1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
package Algorithm::Annotate;
$VERSION = '0.10';
use strict;
use Algorithm::Diff qw(traverse_balanced);
=head1 NAME
Algorithm::Annotate - represent a series of changes in annotate form
=head1 SYNOPSIS
use Algorithm::Annotate;
my $ann = Algorithm::Annotate->new ();
$ann->add ($info1, \@seq1);
$ann->add ($info2, \@seq2);
$ann->add ($info3, \@seq3);
$result = $ann->result;
=head1 DESCRIPTION
Algorithm::Annotate generates a list that is useful for generating
output simliar to C<cvs annotate>.
=head1 TODO
Might parse diff output and accumulate them for generating the annotate list.
=cut
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;
=head1 AUTHORS
Chia-liang Kao E<lt>clkao@clkao.orgE<gt>
=head1 COPYRIGHT
Copyright 2003 by Chia-liang Kao E<lt>clkao@clkao.orgE<gt>.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
See L<http://www.perl.com/perl/misc/Artistic.html>
=cut
|