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