package Text::Diff; $VERSION = 0.35; =head1 NAME Text::Diff - Perform diffs on files and record sets =head1 SYNOPSIS use Text::Diff; ## Mix and match filenames, strings, file handles, producer subs, ## or arrays of records; returns diff in a string. ## WARNING: can return B diffs for large files. my $diff = diff "file1.txt", "file2.txt", { STYLE => "Context" }; my $diff = diff \$string1, \$string2, \%options; my $diff = diff \*FH1, \*FH2; my $diff = diff \&reader1, \&reader2; my $diff = diff \@records1, \@records2; ## May also mix input types: my $diff = diff \@records1, "file_B.txt"; =head1 DESCRIPTION C provides a basic set of services akin to the GNU C utility. It is not anywhere near as feature complete as GNU C, but it is better integrated with Perl and available on all platforms. It is often faster than shelling out to a system's C executable for small files, and generally slower on larger files. Relies on L for, well, the algorithm. This may not produce the same exact diff as a system's local C executable, but it will be a valid diff and comprehensible by C. We haven't seen any differences between Algorithm::Diff's logic and GNU diff's, but we have not examined them to make sure they are indeed identical. B: If you don't want to import the C function, do one of the following: use Text::Diff (); require Text::Diff; That's a pretty rare occurence, so C is exported by default. =cut use Exporter; @ISA = qw( Exporter ); @EXPORT = qw( diff ); use strict; use Carp; use Algorithm::Diff qw( traverse_sequences ); ## Hunks are made of ops. An op is the starting index for each ## sequence and the opcode: use constant A => 0; # Array index before match/discard use constant B => 1; use constant OPCODE => 2; # "-", " ", "+" use constant FLAG => 3; # What to display if not OPCODE "!" =head1 OPTIONS diff() takes two parameters from which to draw input and a set of options to control it's output. The options are: =over =item FILENAME_A, MTIME_A, FILENAME_B, MTIME_B The name of the file and the modification time "files" These are filled in automatically for each file when diff() is passed a filename, unless a defined value is passed in. If a filename is not passed in and FILENAME_A and FILENAME_B are not provided or C, the header will not be printed. Unused on C diffs. =item OFFSET_A, OFFSET_B The index of the first line / element. These default to 1 for all parameter types except ARRAY references, for which the default is 0. This is because ARRAY references are presumed to be data structures, while the others are line oriented text. =item STYLE "Unified", "Context", "OldStyle", or an object or class reference for a class providing C, C, C, C and C methods. The two footer() methods are provided for overloading only; none of the formats provide them. Defaults to "Unified" (unlike standard C, but Unified is what's most often used in submitting patches and is the most human readable of the three. If the package indicated by the STYLE has no hunk() method, c will load it automatically (lazy loading). Since all such packages should inherit from Text::Diff::Base, this should be marvy. Styles may be specified as class names (C