1PatchReader(3) User Contributed Perl Documentation PatchReader(3)
2
3
4
6 PatchReader - Utilities to read and manipulate patches and CVS
7
9 # script that reads in a patch (in any known format), and prints out some
10 # information about it. Other common operations are outputting the patch
11 # in a raw unified diff format, outputting the patch information to
12 # Template::Toolkit templates, adding context to a patch from CVS, and
13 # narrowing the patch down to apply only to a single file or set of files.
14
15 use PatchReader::Raw;
16 use PatchReader::PatchInfoGrabber;
17 my $filename = 'filename.patch';
18
19 # Create the reader that parses the patch and the object that extracts info
20 # from the reader's datastream
21 my $reader = new PatchReader::Raw();
22 my $patch_info_grabber = new PatchReader::PatchInfoGrabber();
23 $reader->sends_data_to($patch_info_grabber);
24
25 # Iterate over the file
26 $reader->iterate_file($filename);
27
28 # Print the output
29 my $patch_info = $patch_info_grabber->patch_info();
30 print "Summary of Changed Files:\n";
31 while (my ($file, $info) = each %{$patch_info->{files}}) {
32 print "$file: +$info->{plus_lines} -$info->{minus_lines}\n";
33 }
34
36 This perl library allows you to manipulate patches programmatically by
37 chaining together a variety of objects that read, manipulate, and
38 output patch information:
39
40 PatchReader::Raw - parse a patch in any format known to this author
41 (unified, normal, cvs diff,
42 among others) PatchReader::PatchInfoGrabber - grab summary info for
43 sections of a patch in a nice hash
44 of a patch, for example) PatchReader::AddCVSContext - add context to
45 the patch by grabbing the original files from CVS
46 PatchReader::NarrowPatch - narrow a patch down to only apply to a
47 specific set of files
48
49 PatchReader::DiffPrinter::raw - output the parsed patch in raw unified
50 diff format PatchReader::DiffPrinter::template - output the parsed
51 patch to Template::Toolkit templates (can be used to make
52 HTML output or anything else you please)
53
54 Additionally, it is designed so that you can plug in your own objects
55 that read the parsed data while it is being parsed (no need for the
56 performance or memory problems that can come from reading in the entire
57 patch all at once). You can do this by mimicking one of the existing
58 readers (such as PatchInfoGrabber) and overriding the methods
59 start_patch, start_file, section, end_file and end_patch.
60
61
62
63perl v5.12.0 2004-07-17 PatchReader(3)