| Algorithm-Annotate documentation | Contained in the Algorithm-Annotate distribution. |
Algorithm::Annotate - represent a series of changes in annotate form
use Algorithm::Annotate;
my $ann = Algorithm::Annotate->new ();
$ann->add ($info1, \@seq1);
$ann->add ($info2, \@seq2); $ann->add ($info3, \@seq3);
$result = $ann->result;
Algorithm::Annotate generates a list that is useful for generating
output simliar to cvs annotate.
Might parse diff output and accumulate them for generating the annotate list.
Chia-liang Kao <clkao@clkao.org>
Copyright 2003 by Chia-liang Kao <clkao@clkao.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Algorithm-Annotate documentation | Contained in the Algorithm-Annotate distribution. |
package Algorithm::Annotate; $VERSION = '0.10'; use strict; use Algorithm::Diff qw(traverse_balanced);
sub new { my $class = shift; my $self = bless {}, $class; return $self; } sub init { my ($self, $info, $seq) = @_; $self->{lastseq} = $seq; $self->{annotate} = [map {$info} @$seq]; } sub add { my ($self, $info, $seq) = @_; return $self->init ($info, $seq) unless $self->{lastseq}; traverse_balanced( $self->{lastseq}, $seq, { MATCH => sub {}, DISCARD_A => sub { splice (@{$self->{annotate}}, $_[1], 1); }, DISCARD_B => sub { splice(@{$self->{annotate}}, $_[1], 0, $info); }, CHANGE => sub { $self->{annotate}[$_[1]] = $info; }, } ); $self->{lastseq} = $seq; } sub result { my $self = shift; return $self->{annotate}; } 1;