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 out‐
38 put 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 PatchReader::Narrow‐
46 Patch - narrow a patch down to only apply to a specific set of files
47
48 PatchReader::DiffPrinter::raw - output the parsed patch in raw unified
49 diff format PatchReader::DiffPrinter::template - output the parsed
50 patch to Template::Toolkit templates (can be used to make
51 HTML output or anything else you please)
52
53 Additionally, it is designed so that you can plug in your own objects
54 that read the parsed data while it is being parsed (no need for the
55 performance or memory problems that can come from reading in the entire
56 patch all at once). You can do this by mimicking one of the existing
57 readers (such as PatchInfoGrabber) and overriding the methods
58 start_patch, start_file, section, end_file and end_patch.
59
60
61
62perl v5.8.8 2004-07-17 PatchReader(3)