Add built local::lib
[catagits/Gitalist.git] / local-lib5 / man / man3 / Text::Diff.3pm
1 .\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.10)
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
6 .if t .sp .5v
7 .if n .sp
8 ..
9 .de Vb \" Begin verbatim text
10 .ft CW
11 .nf
12 .ne \\$1
13 ..
14 .de Ve \" End verbatim text
15 .ft R
16 .fi
17 ..
18 .\" Set up some character translations and predefined strings.  \*(-- will
19 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20 .\" double quote, and \*(R" will give a right double quote.  \*(C+ will
21 .\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
22 .\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
23 .\" nothing in troff, for use with C<>.
24 .tr \(*W-
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26 .ie n \{\
27 .    ds -- \(*W-
28 .    ds PI pi
29 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
31 .    ds L" ""
32 .    ds R" ""
33 .    ds C` ""
34 .    ds C' ""
35 'br\}
36 .el\{\
37 .    ds -- \|\(em\|
38 .    ds PI \(*p
39 .    ds L" ``
40 .    ds R" ''
41 'br\}
42 .\"
43 .\" Escape single quotes in literal strings from groff's Unicode transform.
44 .ie \n(.g .ds Aq \(aq
45 .el       .ds Aq '
46 .\"
47 .\" If the F register is turned on, we'll generate index entries on stderr for
48 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
49 .\" entries marked with X<> in POD.  Of course, you'll have to process the
50 .\" output yourself in some meaningful fashion.
51 .ie \nF \{\
52 .    de IX
53 .    tm Index:\\$1\t\\n%\t"\\$2"
54 ..
55 .    nr % 0
56 .    rr F
57 .\}
58 .el \{\
59 .    de IX
60 ..
61 .\}
62 .\"
63 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
64 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
65 .    \" fudge factors for nroff and troff
66 .if n \{\
67 .    ds #H 0
68 .    ds #V .8m
69 .    ds #F .3m
70 .    ds #[ \f1
71 .    ds #] \fP
72 .\}
73 .if t \{\
74 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
75 .    ds #V .6m
76 .    ds #F 0
77 .    ds #[ \&
78 .    ds #] \&
79 .\}
80 .    \" simple accents for nroff and troff
81 .if n \{\
82 .    ds ' \&
83 .    ds ` \&
84 .    ds ^ \&
85 .    ds , \&
86 .    ds ~ ~
87 .    ds /
88 .\}
89 .if t \{\
90 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
91 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
92 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
93 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
94 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
95 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
96 .\}
97 .    \" troff and (daisy-wheel) nroff accents
98 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
99 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
100 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
101 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
102 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
103 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
104 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
105 .ds ae a\h'-(\w'a'u*4/10)'e
106 .ds Ae A\h'-(\w'A'u*4/10)'E
107 .    \" corrections for vroff
108 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
109 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
110 .    \" for low resolution devices (crt and lpr)
111 .if \n(.H>23 .if \n(.V>19 \
112 \{\
113 .    ds : e
114 .    ds 8 ss
115 .    ds o a
116 .    ds d- d\h'-1'\(ga
117 .    ds D- D\h'-1'\(hy
118 .    ds th \o'bp'
119 .    ds Th \o'LP'
120 .    ds ae ae
121 .    ds Ae AE
122 .\}
123 .rm #[ #] #H #V #F C
124 .\" ========================================================================
125 .\"
126 .IX Title "Text::Diff 3"
127 .TH Text::Diff 3 "2009-07-16" "perl v5.8.7" "User Contributed Perl Documentation"
128 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
129 .\" way too many mistakes in technical documents.
130 .if n .ad l
131 .nh
132 .SH "NAME"
133 Text::Diff \- Perform diffs on files and record sets
134 .SH "SYNOPSIS"
135 .IX Header "SYNOPSIS"
136 .Vb 1
137 \&    use Text::Diff;
138 \&
139 \&    ## Mix and match filenames, strings, file handles, producer subs,
140 \&    ## or arrays of records; returns diff in a string.
141 \&    ## WARNING: can return B<large> diffs for large files.
142 \&    my $diff = diff "file1.txt", "file2.txt", { STYLE => "Context" };
143 \&    my $diff = diff \e$string1,   \e$string2,   \e%options;
144 \&    my $diff = diff \e*FH1,       \e*FH2;
145 \&    my $diff = diff \e&reader1,   \e&reader2;
146 \&    my $diff = diff \e@records1,  \e@records2;
147 \&
148 \&    ## May also mix input types:
149 \&    my $diff = diff \e@records1,  "file_B.txt";
150 .Ve
151 .SH "DESCRIPTION"
152 .IX Header "DESCRIPTION"
153 \&\f(CW\*(C`diff()\*(C'\fR provides a basic set of services akin to the \s-1GNU\s0 \f(CW\*(C`diff\*(C'\fR utility.  It
154 is not anywhere near as feature complete as \s-1GNU\s0 \f(CW\*(C`diff\*(C'\fR, but it is better
155 integrated with Perl and available on all platforms.  It is often faster than
156 shelling out to a system's \f(CW\*(C`diff\*(C'\fR executable for small files, and generally
157 slower on larger files.
158 .PP
159 Relies on Algorithm::Diff for, well, the algorithm.  This may not produce
160 the same exact diff as a system's local \f(CW\*(C`diff\*(C'\fR executable, but it will be a
161 valid diff and comprehensible by \f(CW\*(C`patch\*(C'\fR.  We haven't seen any differences
162 between Algorithm::Diff's logic and \s-1GNU\s0 diff's, but we have not examined them
163 to make sure they are indeed identical.
164 .PP
165 \&\fBNote\fR: If you don't want to import the \f(CW\*(C`diff\*(C'\fR function, do one of the
166 following:
167 .PP
168 .Vb 1
169 \&   use Text::Diff ();
170 \&
171 \&   require Text::Diff;
172 .Ve
173 .PP
174 That's a pretty rare occurence, so \f(CW\*(C`diff()\*(C'\fR is exported by default.
175 =head1 \s-1OPTIONS\s0
176 .PP
177 \&\fIdiff()\fR takes two parameters from which to draw input and a set of
178 options to control it's output.  The options are:
179 .IP "\s-1FILENAME_A\s0, \s-1MTIME_A\s0, \s-1FILENAME_B\s0, \s-1MTIME_B\s0" 4
180 .IX Item "FILENAME_A, MTIME_A, FILENAME_B, MTIME_B"
181 The name of the file and the modification time \*(L"files\*(R"
182 .Sp
183 These are filled in automatically for each file when \fIdiff()\fR is passed a
184 filename, unless a defined value is passed in.
185 .Sp
186 If a filename is not passed in and \s-1FILENAME_A\s0 and \s-1FILENAME_B\s0 are not provided
187 or \f(CW\*(C`undef\*(C'\fR, the header will not be printed.
188 .Sp
189 Unused on \f(CW\*(C`OldStyle\*(C'\fR diffs.
190 .IP "\s-1OFFSET_A\s0, \s-1OFFSET_B\s0" 4
191 .IX Item "OFFSET_A, OFFSET_B"
192 The index of the first line / element.  These default to 1 for all
193 parameter types except \s-1ARRAY\s0 references, for which the default is 0.  This
194 is because \s-1ARRAY\s0 references are presumed to be data structures, while the
195 others are line oriented text.
196 .IP "\s-1STYLE\s0" 4
197 .IX Item "STYLE"
198 \&\*(L"Unified\*(R", \*(L"Context\*(R", \*(L"OldStyle\*(R", or an object or class reference for a class
199 providing \f(CW\*(C`file_header()\*(C'\fR, \f(CW\*(C`hunk_header()\*(C'\fR, \f(CW\*(C`hunk()\*(C'\fR, \f(CW\*(C`hunk_footer()\*(C'\fR and
200 \&\f(CW\*(C`file_footer()\*(C'\fR methods.  The two \fIfooter()\fR methods are provided for
201 overloading only; none of the formats provide them.
202 .Sp
203 Defaults to \*(L"Unified\*(R" (unlike standard \f(CW\*(C`diff\*(C'\fR, but Unified is what's most
204 often used in submitting patches and is the most human readable of the three.
205 .Sp
206 If the package indicated by the \s-1STYLE\s0 has no \fIhunk()\fR method, c<\fIdiff()\fR> will
207 load it automatically (lazy loading).  Since all such packages should inherit
208 from Text::Diff::Base, this should be marvy.
209 .Sp
210 Styles may be specified as class names (\f(CW\*(C`STYLE =\*(C'\fR \*(L"Foo\*(R"), in which case they
211 will be \f(CW\*(C`new()\*(C'\fRed with no parameters, or as objects (\f(CW\*(C`STYLE =\*(C'\fR Foo\->new>).
212 .IP "\s-1CONTEXT\s0" 4
213 .IX Item "CONTEXT"
214 How many lines before and after each diff to display.  Ignored on old-style
215 diffs.  Defaults to 3.
216 .IP "\s-1OUTPUT\s0" 4
217 .IX Item "OUTPUT"
218 Examples and their equivalent subroutines:
219 .Sp
220 .Vb 4
221 \&    OUTPUT   => \e*FOOHANDLE,   # like: sub { print FOOHANDLE shift() }
222 \&    OUTPUT   => \e$output,      # like: sub { $output .= shift }
223 \&    OUTPUT   => \e@output,      # like: sub { push @output, shift }
224 \&    OUTPUT   => sub { $output .= shift },
225 .Ve
226 .Sp
227 If no \f(CW\*(C`OUTPUT\*(C'\fR is supplied, returns the diffs in a string.  If
228 \&\f(CW\*(C`OUTPUT\*(C'\fR is a \f(CW\*(C`CODE\*(C'\fR ref, it will be called once with the (optional)
229 file header, and once for each hunk body with the text to emit.  If
230 \&\f(CW\*(C`OUTPUT\*(C'\fR is an IO::Handle, output will be emitted to that handle.
231 .IP "\s-1FILENAME_PREFIX_A\s0, \s-1FILENAME_PREFIX_B\s0" 4
232 .IX Item "FILENAME_PREFIX_A, FILENAME_PREFIX_B"
233 The string to print before the filename in the header. Unused on \f(CW\*(C`OldStyle\*(C'\fR
234 diffs.  Defaults are \f(CW"\-\-\-"\fR, \f(CW"+++"\fR for Unified and \f(CW"***"\fR, \f(CW"+++"\fR for
235 Context.
236 .IP "\s-1KEYGEN\s0, \s-1KEYGEN_ARGS\s0" 4
237 .IX Item "KEYGEN, KEYGEN_ARGS"
238 These are passed to \*(L"traverse_sequences\*(R" in Algorithm::Diff.
239 .PP
240 \&\fBNote\fR: if neither \f(CW\*(C`FILENAME_\*(C'\fR option is defined, the header will not be
241 printed.  If at one is present, the other and both \s-1MTIME_\s0 options must be
242 present or \*(L"Use of undefined variable\*(R" warnings will be generated (except
243 on \f(CW\*(C`OldStyle\*(C'\fR diffs, which ignores these options).
244 .SH "Formatting Classes"
245 .IX Header "Formatting Classes"
246 These functions implement the output formats.  They are grouped in to classes
247 so \fIdiff()\fR can use class names to call the correct set of output routines and so
248 that you may inherit from them easily.  There are no constructors or instance
249 methods for these classes, though subclasses may provide them if need be.
250 .PP
251 Each class has \fIfile_header()\fR, \fIhunk_header()\fR, \fIhunk()\fR, and \fIfooter()\fR methods
252 identical to those documented in the Text::Diff::Unified section.  \fIheader()\fR is
253 called before the \fIhunk()\fR is first called, \fIfooter()\fR afterwards.  The default
254 footer function is an empty method provided for overloading:
255 .PP
256 .Vb 1
257 \&    sub footer { return "End of patch\en" }
258 .Ve
259 .PP
260 Some output formats are provided by external modules (which are loaded
261 automatically), such as Text::Diff::Table.  These are
262 are documented here to keep the documentation simple.
263 .SS "Text::Diff::Base"
264 .IX Subsection "Text::Diff::Base"
265 Returns "" for all methods (other than \f(CW\*(C`new()\*(C'\fR).
266 .SS "Text::Diff::Unified"
267 .IX Subsection "Text::Diff::Unified"
268 .Vb 10
269 \&  \-\-\- A   Mon Nov 12 23:49:30 2001
270 \&  +++ B   Mon Nov 12 23:49:30 2001
271 \&  @@ \-2,13 +2,13 @@
272 \&   2
273 \&   3
274 \&   4
275 \&  \-5d
276 \&  +5a
277 \&   6
278 \&   7
279 \&   8
280 \&   9
281 \&  +9a
282 \&   10
283 \&   11
284 \&  \-11d
285 \&   12
286 \&   13
287 .Ve
288 .IP "file_header" 4
289 .IX Item "file_header"
290 .Vb 1
291 \&  $s = Text::Diff::Unified\->file_header( $options );
292 .Ve
293 .Sp
294 Returns a string containing a unified header.  The sole parameter is the
295 options hash passed in to \fIdiff()\fR, containing at least:
296 .Sp
297 .Vb 4
298 \&  FILENAME_A  => $fn1,
299 \&  MTIME_A     => $mtime1,
300 \&  FILENAME_B  => $fn2,
301 \&  MTIME_B     => $mtime2
302 .Ve
303 .Sp
304 May also contain
305 .Sp
306 .Vb 2
307 \&  FILENAME_PREFIX_A    => "\-\-\-",
308 \&  FILENAME_PREFIX_B    => "+++",
309 .Ve
310 .Sp
311 to override the default prefixes (default values shown).
312 .IP "hunk_header" 4
313 .IX Item "hunk_header"
314 .Vb 1
315 \&  Text::Diff::Unified\->hunk_header( \e@ops, $options );
316 .Ve
317 .Sp
318 Returns a string containing the output of one hunk of unified diff.
319 .IP "Text::Diff::Unified::hunk" 4
320 .IX Item "Text::Diff::Unified::hunk"
321 .Vb 1
322 \&  Text::Diff::Unified\->hunk( \e@seq_a, \e@seq_b, \e@ops, $options );
323 .Ve
324 .Sp
325 Returns a string containing the output of one hunk of unified diff.
326 .SS "Text::Diff::Table"
327 .IX Subsection "Text::Diff::Table"
328 .Vb 10
329 \&  +\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
330 \&  |  |../Test\-Differences\-0.2/MANIFEST  |  |../Test\-Differences/MANIFEST  |
331 \&  |  |Thu Dec 13 15:38:49 2001          |  |Sat Dec 15 02:09:44 2001      |
332 \&  +\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
333 \&  |  |                                  * 1|Changes                       *
334 \&  | 1|Differences.pm                    | 2|Differences.pm                |
335 \&  | 2|MANIFEST                          | 3|MANIFEST                      |
336 \&  |  |                                  * 4|MANIFEST.SKIP                 *
337 \&  | 3|Makefile.PL                       | 5|Makefile.PL                   |
338 \&  |  |                                  * 6|t/00escape.t                  *
339 \&  | 4|t/00flatten.t                     | 7|t/00flatten.t                 |
340 \&  | 5|t/01text_vs_data.t                | 8|t/01text_vs_data.t            |
341 \&  | 6|t/10test.t                        | 9|t/10test.t                    |
342 \&  +\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
343 .Ve
344 .PP
345 This format also goes to some pains to highlight \*(L"invisible\*(R" characters on
346 differing elements by selectively escaping whitespace:
347 .PP
348 .Vb 10
349 \&  +\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
350 \&  |  |demo_ws_A.txt             |demo_ws_B.txt             |
351 \&  |  |Fri Dec 21 08:36:32 2001  |Fri Dec 21 08:36:50 2001  |
352 \&  +\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
353 \&  | 1|identical                 |identical                 |
354 \&  * 2|        spaced in         |        also spaced in    *
355 \&  * 3|embedded space            |embedded        tab       *
356 \&  | 4|identical                 |identical                 |
357 \&  * 5|        spaced in         |\ettabbed in               *
358 \&  * 6|trailing spaces\es\es\en     |trailing tabs\et\et\en       *
359 \&  | 7|identical                 |identical                 |
360 \&  * 8|lf line\en                 |crlf line\er\en             *
361 \&  * 9|embedded ws               |embedded\etws              *
362 \&  +\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
363 .Ve
364 .PP
365 See \*(L"Text::Diff::Table\*(R" for more details, including how the whitespace
366 escaping works.
367 .SS "Text::Diff::Context"
368 .IX Subsection "Text::Diff::Context"
369 .Vb 10
370 \&    *** A   Mon Nov 12 23:49:30 2001
371 \&    \-\-\- B   Mon Nov 12 23:49:30 2001
372 \&    ***************
373 \&    *** 2,14 ****
374 \&      2
375 \&      3
376 \&      4
377 \&    ! 5d
378 \&      6
379 \&      7
380 \&      8
381 \&      9
382 \&      10
383 \&      11
384 \&    \- 11d
385 \&      12
386 \&      13
387 \&    \-\-\- 2,14 \-\-\-\-
388 \&      2
389 \&      3
390 \&      4
391 \&    ! 5a
392 \&      6
393 \&      7
394 \&      8
395 \&      9
396 \&    + 9a
397 \&      10
398 \&      11
399 \&      12
400 \&      13
401 .Ve
402 .PP
403 Note: \fIhunk_header()\fR returns only \*(L"***************\en\*(R".
404 .SS "Text::Diff::OldStyle"
405 .IX Subsection "Text::Diff::OldStyle"
406 .Vb 8
407 \&    5c5
408 \&    < 5d
409 \&    \-\-\-
410 \&    > 5a
411 \&    9a10
412 \&    > 9a
413 \&    12d12
414 \&    < 11d
415 .Ve
416 .PP
417 Note: no \fIfile_header()\fR.
418 .SH "LIMITATIONS"
419 .IX Header "LIMITATIONS"
420 Must suck both input files entirely in to memory and store them with a normal
421 amount of Perlish overhead (one array location) per record.  This is implied by
422 the implementation of Algorithm::Diff, which takes two arrays.  If
423 Algorithm::Diff ever offers an incremental mode, this can be changed (contact
424 the maintainers of Algorithm::Diff and Text::Diff if you need this; it
425 shouldn't be too terribly hard to tie arrays in this fashion).
426 .PP
427 Does not provide most of the more refined \s-1GNU\s0 diff options: recursive directory
428 tree scanning, ignoring blank lines / whitespace, etc., etc.  These can all be
429 added as time permits and need arises, many are rather easy; patches quite
430 welcome.
431 .PP
432 Uses closures internally, this may lead to leaks on \f(CW\*(C`perl\*(C'\fR versions 5.6.1 and
433 prior if used many times over a process' life time.
434 .SH "AUTHOR"
435 .IX Header "AUTHOR"
436 Adam Kennedy <adamk@cpan.org>
437 .PP
438 Barrie Slaymaker <barries@slaysys.com>
439 .SH "COPYRIGHT"
440 .IX Header "COPYRIGHT"
441 Some parts copyright 2009 Adam Kennedy.
442 .PP
443 Copyright 2001 Barrie Slaymaker.  All Rights Reserved.
444 .PP
445 You may use this under the terms of either the Artistic License or \s-1GNU\s0 Public
446 License v 2.0 or greater.