Report.pm

filter: Statementstmt 37.8% 14 / 37 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 100% 2 / 2 totaltotal 32.2% 20 / 62 CC 11 SCAR 34.7
CC
11
Cov
26%
all
56.0
_print_bucket
30.0
new
2.0
CRAP 32.2
« Base.pm ↑ Summary FormatString.pm »
1 #================================ Report.pm ===================================
2 # Filename: Report.pm
3 # Description: Generate reports from a FileHash.
4 # Original Author: Dale M. Amon
5 # Revised by: $Author: amon $
6 # Date: $Date: 2008-08-28 23:35:28 $
7 # Version: $Revision: 1.8 $
8 # License: LGPL 2.1, Perl Artistic or BSD
9 #
10 #=============================================================================
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Fault::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use FileHash::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 package FileHash::Report;
16 1 ▶use vars qw{@ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 @ISA = qw( UNIVERSAL );
18  
19 #=============================================================================
20 # INTERNAL METHODS
21 #=============================================================================
22 # Print the contents of a hash bucket, one file to a line and an extra newline
23 # after the block if the flg is set.
24  
25 0 ▶sub _print_bucket ($$$*$) {
Subroutine _print_bucket: not called CC=5 SCAR=34.0
26 0 my ($self,$v1,$report,$fd,$flg) = @_;
27 0 my ($j,$ok);
28  
29 0 foreach $j (@$v1) {
30 0 $ok = printf $fd "%s %12s %12s %s\n",
31 $j->md5sum, $j->sizeBytes, $j->mtime,$j->path;
32 0 ▶ $ok or Fault::Logger->log_once ("Failed to print to '$report': $!");
Branch: 1 branch
BranchTrueFalseTotal
$ok or "Fault::Logger"->log_once("Failed to print to '${report}': $!") 0 0 0
33 }
34 0 ▶ if ($flg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flg) 0 0 0
35 0 $ok = printf $fd "\n";
36 0 ▶ $ok or Fault::Logger->log_once ("Failed to print to '$report': $!");
Branch: 1 branch
BranchTrueFalseTotal
$ok or "Fault::Logger"->log_once("Failed to print to '${report}': $!") 0 0 0
37 }
38 }
39  
40 #=============================================================================
41 # CLASS METHODS
42 #=============================================================================
43  
44 0 ▶sub new ($) {my ($class) = @_; return bless {}, $class;}
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
45  
46 #=============================================================================
47 # INSTANCE METHODS
48 #=============================================================================
49  
50 0 ▶sub all (\%$$$) {
Subroutine all: not called CC=7 SCAR=40.3
Pod documented
51 0 my ($self,$files,$report,$fmtflg) = @_;
52 0 my ($i,$j,$fd);
53  
54 0 ▶ defined $fmtflg or $fmtflg=0;
Branch: 1 branch
BranchTrueFalseTotal
defined $fmtflg or $fmtflg = 0 0 0 0
55
56 0 ▶ if ($::DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::DEBUG) 0 0 0
57 0 ▶ Fault::Logger->arg_check_isa ($files,"FileHash::Base","files")
Branch: 1 branch
BranchTrueFalseTotal
"Fault::Logger"->arg_check_isa($files, "FileHash::Base", "files") or return undef 0 0 0
58 or return undef;
59 0 ▶ Fault::Logger->arg_check_noref ($report,"reportname")
Branch: 1 branch
BranchTrueFalseTotal
"Fault::Logger"->arg_check_noref($report, "reportname") or return undef 0 0 0
60 or return undef;
61 }
62
63 Fault::Logger->assertion_check
64 0 ▶ (!(open $fd, ">$report"),undef,"Can not open '$report': $!")
Branch: 1 branch
BranchTrueFalseTotal
"Fault::Logger"->assertion_check(!open($fd, ">$report"), undef, "Can not open '${report}': $!") or return undef 0 0 0
65 or return undef;
66
67 0 my $ok;
68 0 foreach $i (values %{$files->{'filehash'}}) {
69 0 $self->_print_bucket ($i,$report,$fd,$fmtflg);
70 }
71 0 close ($fd);
72 0 return $self;
73 }
74
75 #=============================================================================
76 # POD DOCUMENTATION
77 #=============================================================================
78 # You may extract and format the documention section with the 'perldoc' cmd.
79  
80 =head1 NAME
81  
82 FileHash::Report - Generate reports from a FileHash.
83  
84 =head1 SYNOPSIS
85  
86 use FileHash::Report;
87 $obj = FileHash::Report->new;
88 $obj = $obj->all ($filehash,$report,$fmtflg)
89  
90 =head1 Inheritance
91  
92 UNIVERSAL
93  
94 =head1 Description
95  
96 Write simple reports. The output data is printed in search key/bucket order.
97  
98 =head1 Examples
99  
100 use FileHash::Content;
101 use FileHash::Report;
102  
103 my $r = FileHash::Report->new;
104 my $a = FileHash::Content->alloc;
105 $a->initFromTree ("/root");
106  
107 # print a list of all sets of files with the same md5sum and size.
108 my $c = $a->identical;
109 $r->all ($c,"myreport");
110  
111 # Hash the data by name instead.
112 my $b = FileHash::Name->alloc;
113 $b->initFromTree ($a);
114  
115 # print a list of all sets of files with the same file name.
116 $c = $b->identical;
117 $r->all ($c,"myreport2");
118  
119 # Print a list of all files found in a that are not in b
120 $a = FileHash::Content->alloc;
121 $b = FileHash::Content->alloc;
122 $a->initFromTree ("/home/me/tree1");
123 $b->initFromTree ("/home/me/tree2");
124 $c = $a->andnot ($b);
125 $r->all ($c,"myreport3");
126  
127 # Print a list of all files found in a that are in one or the
128 # other but not both.
129 my $c = $a->xor ($b);
130 $r->all ($c,"myreport3");
131  
132 =head1 Class Variables
133  
134 None.
135  
136 =head1 Instance Variables
137  
138 None.
139  
140 =head1 Class Methods
141  
142 =over 4
143  
144 =item B<$obj = FileHash::Report-E<gt>new>
145  
146 Create instances of FileHash::Report.
147  
148 =head1 Instance Methods
149  
150 Methods return self on success and undef on error unless stated otherwise.
151  
152 =over 4
153  
154 A 'group of files' are files that have the same hash key.
155  
156 =item B<$obj = $obj-E<gt>all ($filehash,$report,$fmtflg)>
157  
158 Write a report of all files in $filehash to a file named $report. If
159 the format flag exists and is true, linefeeds are printed between each
160 group on output.
161  
162 =back 4
163  
164 =head1 Private Class Method
165  
166 None.
167  
168 =head1 Private Instance Methods
169  
170 None.
171  
172 =head1 Errors and Warnings
173  
174 Lots.
175  
176 =head1 KNOWN BUGS
177  
178 See TODO.
179  
180 =head1 SEE ALSO
181  
182 FileHash::Base, Fault::Logger.
183  
184 =head1 AUTHOR
185  
186 Dale Amon <amon@vnl.com>
187  
188 =cut
189
190 #=============================================================================
191 # CVS HISTORY
192 #=============================================================================
193 # $Log: Report.pm,v $
194 # Revision 1.8 2008-08-28 23:35:28 amon
195 # perldoc section regularization.
196 #
197 # Revision 1.7 2008-08-04 12:13:46 amon
198 # Moved logical unary and binary ops to FileHash; created an internal common hash bucket print method.
199 #
200 # Revision 1.6 2008-07-27 15:16:17 amon
201 # Wrote lexical parse for Entry; error checking on eval and other minor issues.
202 #
203 # Revision 1.5 2008-07-25 14:30:42 amon
204 # Documentation improvements and corrections.
205 #
206 # Revision 1.4 2008-07-24 20:19:43 amon
207 # Just in case I missed anything.
208 #
209 # Revision 1.3 2008-07-24 13:35:26 amon
210 # switch to NeXT style alloc/init format for FileHash and Entry classes.
211 #
212 # Revision 1.2 2008-07-23 21:12:24 amon
213 # Moved notes out of file headers; a few doc updates; added assertion checks;
214 # minor bug fixes.
215 #
216 # $DATE Dale Amon <amon@vnl.com>
217 # Created.
218 1 1;
« Base.pm ↑ Summary FormatString.pm »