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