Algorithm::Annotate - represent a series of changes in annotate form


Algorithm-Annotate documentation Contained in the Algorithm-Annotate distribution.

Index


Code Index:

NAME

Top

Algorithm::Annotate - represent a series of changes in annotate form

SYNOPSIS

Top

use Algorithm::Annotate;

my $ann = Algorithm::Annotate->new ();

$ann->add ($info1, \@seq1);

$ann->add ($info2, \@seq2); $ann->add ($info3, \@seq3);

$result = $ann->result;

DESCRIPTION

Top

Algorithm::Annotate generates a list that is useful for generating output simliar to cvs annotate.

TODO

Top

Might parse diff output and accumulate them for generating the annotate list.

AUTHORS

Top

Chia-liang Kao <clkao@clkao.org>

COPYRIGHT

Top


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;