File Coverage

lib/PatchReader.pm
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 4 4 100.0


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