|
Algorithm::Diff3::DiffHeckel - P. Heckel's diff plugin |
Algorithm::Diff3::DiffHeckel - P. Heckel's diff plugin
use Algorithm::Diff3;
my $f = Algorithm::Diff3::Factory->new;
my $p = $f->create_diff;
my $mytext = $f->create_text([ map{chomp;$_} <F0> ]);
my $original = $f->create_text([ map{chomp;$_} <F1> ]);
my $diff2 = $p->diff( $origial, $mytext );
$diff2->each(sub{
my( $r ) = @_;
print $r->as_string, "\n";
if ( $r->type ne 'd' ) {
print '-', $original->as_string_at( $_ ) for $r->rangeB;
}
if ( $r->type ne 'a' ) {
print '+', $mytext->as_string_at( $_ ) for $r->rangeA;
}
});
This is a package for Algorithm::Diff3 to compute difference sets between two text buffers based on the P. Heckel's algorithm. Anyone may change this to an another diff or a its wrapper module by injecting of a your custom Factory instanse.
Algorithm::Diff3 needs a support of computing difference sets
between two text buffers (diff). As the diff(1) command,
the required diff module creates a list of tapples recorded
an information set of a change type (such as a,c,d) and a range
of line numbers between two text buffers.
Since there are several algorithms and their implementations for the diff computation, Algorithm::Diff3 makes a plan independ on any specific diff routine. It calls a pluggable diff processor instanse specifed in a factory commonly used in Algorithm::Diff3. Anyone may change diff plugin according to their text properties.
For users convenience, Algorithm::Diff3 includes small diff based on the P. Heckel's algorithm. On the other hands, many other systems use the popular Least Common Seaquense (LCS) algorithm. The merits for each algorithms are case by case. In author's experience, two algorithms generates almost same results for small local changes in the text. In some cases, such as moving blocks of lines, it happened quite differences in results.
Author recommends you to create an instanse of diff prosessor by using with a factory as follows.
use SomeFactory; my $f = SomeFactory->new; my $p = $f->create_diff;
Algorithm::Diff3::Factory is a class to packaging several classes for the buildin diff processor.
Performing the diff process, we send a `diff' message with two text instanses to the receiver
my $diff2 = $p->diff( $origial, $mytext );
Where the parameters of text might be a kind of as follows.
After the process, the receiver returns the list as difference sets.
P. Heckel. ``A technique for isolating differences between files.'' Communications of the ACM, Vol. 21, No. 4, page 264, April 1978.
Algorithm::Diff3::Diff3
MIZUTANI Tociyuki <tociyuki@gmail.com>
Copyright (C) 2005 MIZUTANI Tociyuki
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version.
|
Algorithm::Diff3::DiffHeckel - P. Heckel's diff plugin |