Base.pm

filter: Statementstmt 12.8% 26 / 202 Branchbran 0.0% 0 / 98 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 26.6% 8 / 30 Podpod 100% 18 / 18 totaltotal 14.7% 52 / 353 CC 66 SCAR 38.2
CC
66
Cov
9%
xor
110.0
_branch
72.0
and
72.0
CRAP 45.8
↑ Summary Report.pm »
1 #================================= Base.pm ===================================
2 # Filename: Base.pm
3 # Description: Generalized hash by full path of file information.
4 # Original Author: Dale M. Amon
5 # Revised by: $Author: amon $
6 # Date: $Date: 2008-08-28 23:35:28 $
7 # Version: $Revision: 1.10 $
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 Fault::DebugPrinter;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use FileHash::Entry;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use FileHash::FormatString;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Cwd qw(abs_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 package FileHash::Base;
20 1 ▶use vars qw{@ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 @ISA = qw( UNIVERSAL );
22  
23 #=============================================================================
24 # INTERNAL OPS
25 #=============================================================================
26  
27 0 ▶sub _leaf {
Subroutine _leaf: not called CC=1 SCAR=6.9
28 0 my ($self,$dev,$directory,$file) = @_;
29 0 my $entry = FileHash::Entry->alloc;
30 0 my $path = File::Spec->catfile($dev,$directory,$file);
31  
32 0 return $entry->initFromStat ($path);
33 }
34  
35 #-----------------------------------------------------------------------------
36  
37 0 ▶sub _branch {
Subroutine _branch: not called CC=8 SCAR=42.8
38 0 my ($self,$dev,$directory,$file,$depth) = @_;
39 0 my $path = File::Spec->catfile($dev,$directory,$file);
40
41 0 ▶ if (-d "$path" and ! -l "$path") {
Branch: 1 branch
BranchTrueFalseTotal
if (-d "$path" and not -l "$path") { } 0 0 0
Condition0%0/3
-d "$path" and not -l "$path"
!ll&&!rl&&r
000
MC/DC0%0/2
-d "$path" and not -l "$path"
-d "$path" not -l "$path"
Truth table0%0/3
A and not(B)
A= -d "$path"B= not -l "$path"
ABresult
0X0
100
111
42 0 my ($fh,$new);
43  
44 0 ▶ Fault::Logger->assertion_check
Branch: 1 branch
BranchTrueFalseTotal
"Fault::Logger"->assertion_check(!opendir($fh, "$path"), undef, "Can not open '${path}': $!") or return $self 0 0 0
45 (!(opendir $fh, "$path"),undef,"Can not open '$path': $!")
46 or return $self;
47  
48 # Readdir returns a null list if there are no files.
49 0 $depth++;
50 0 my @dirlist = readdir ($fh);
51 0 closedir $fh;
52
53 0 foreach $new (@dirlist) {
54 0 ▶ next if ($new eq ".");
Branch: 1 branch
BranchTrueFalseTotal
if $new eq "." 0 0 0
55 0 ▶ next if ($new eq "..");
Branch: 1 branch
BranchTrueFalseTotal
if $new eq ".." 0 0 0
56 0 $self->_branch ($dev,File::Spec->catfile($directory,$file),$new,$depth);
57 }
58 0 $depth--;
59 }
60 else {
61 0 my $entry = $self->_leaf ($dev,$directory,$file);
62 0 ▶ defined $entry or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $entry or return undef 0 0 0
63  
64 0 $self->_store ($self->_genKey ($entry),$entry);
65 }
66 0 return $self;
67 }
68  
69 #=============================================================================
70  
71 0 ▶sub _store {
Subroutine _store: not called CC=2 SCAR=17.9
72 0 my ($self,$key,$val) = @_;
73  
74 0 ▶ if (! exists $self->{'filehash'}->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $self->{'filehash'}{$key}) { } 0 0 0
75 0 $self->{'filehash'}->{$key} = [$val];
76 0 Fault::DebugPrinter->dbg (2,"NEW KEY <$key>");
77 }
78 else {
79 0 Fault::DebugPrinter->dbg (2,"DUPLICATE KEY <$key>");
80 0 push @{$self->{'filehash'}->{$key}}, $val;
81 }
82 0 my $path = $val->path;
83 0 Fault::DebugPrinter->dbg (3," FILE <$path>");
84 0 return $self;
85 }
86  
87 #-----------------------------------------------------------------------------
88  
89 sub _genKey
90 0 ▶ {Fault::Logger->crash ("Subclass must impliment: _genKey");}
Subroutine _genKey: not called CC=1 SCAR=6.9
91  
92 #=============================================================================
93 # CLASS METHODS
94 #=============================================================================
95  
96 0 ▶sub alloc ($) {
Subroutine alloc: not called CC=1 SCAR=6.9
Pod documented
97 0 my ($class) = @_;
98 0 my $self = bless {}, $class;
99 0 $self->{'filehash'} = {};
100 0 return $self;
101 }
102  
103 #=============================================================================
104 # INSTANCE METHODS
105 #=============================================================================
106 # Init methods
107 #-----------------------------------------------------------------------------
108 0 ▶sub init ($) {shift;}
Subroutine init: not called CC=1 SCAR=6.9
Pod documented
109 0 ▶sub initFromLines ($$@) {shift->addFromLines (@_);}
Subroutine initFromLines: not called CC=1 SCAR=6.9
Pod documented
110 0 ▶sub initFromFile ($$$) {shift->addFromFile (@_);}
Subroutine initFromFile: not called CC=1 SCAR=6.9
Pod documented
111 0 ▶sub initFromTree ($$) {shift->addFromTree (@_);}
Subroutine initFromTree: not called CC=1 SCAR=6.9
Pod documented
112 0 ▶sub initFromObject ($$) {shift->addFromObject (@_);}
Subroutine initFromObject: not called CC=1 SCAR=6.9
Pod documented
113 0 ▶sub initFromDump ($$) {shift->addFromDump (@_);}
Subroutine initFromDump: not called CC=1 SCAR=6.9
Pod documented
114  
115 #=============================================================================
116 # add methods
117 #-----------------------------------------------------------------------------
118 # The FileHash::Entry object will check for invalid values in @lines.
119  
120 0 ▶sub addFromLines ($$@) {
Subroutine addFromLines: not called CC=7 SCAR=40.3
Pod documented
121 0 my ($self,$formatline,@lines) = @_;
122  
123 0 ▶ if ($::DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::DEBUG) 0 0 0
124 0 ▶ Fault::Logger->arg_check_noref ($formatline,"formatline") or return undef;
Branch: 1 branch
BranchTrueFalseTotal
"Fault::Logger"->arg_check_noref($formatline, "formatline") or return undef 0 0 0
125 }
126  
127 0 my $fmt = FileHash::FormatString->alloc;
128 0 ▶ $fmt->init ($formatline) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$fmt->init($formatline) or return undef 0 0 0
129  
130 0 $self->{'format'} = $fmt;
131 0 foreach (@lines) {
132 0 ▶ next if (/^\w*$/);
Branch: 1 branch
BranchTrueFalseTotal
if /^\w*$/ 0 0 0
133  
134 0 my $entry = FileHash::Entry->alloc;
135 0 ▶ $entry->initFromLine ($self->{'format'},$_) or next;
Branch: 1 branch
BranchTrueFalseTotal
$entry->initFromLine($self->{"format"}, $_) or next 0 0 0
136  
137 0 $self->_store ($self->_genKey ($entry),$entry);
138 }
139 0 return $self;
140 }
141  
142 #-----------------------------------------------------------------------------
143  
144 0 ▶sub addFromFile ($$$) {
Subroutine addFromFile: not called CC=5 SCAR=34.0
Pod documented
145 0 my ($self,$formatline,$listfname) = @_;
146 0 my $fh;
147  
148 0 ▶ if ($::DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::DEBUG) 0 0 0
149 0 ▶ Fault::Logger->arg_check_noref ($formatline,"formatline") or return undef;
Branch: 1 branch
BranchTrueFalseTotal
"Fault::Logger"->arg_check_noref($formatline, "formatline") or return undef 0 0 0
150 0 ▶ Fault::Logger->arg_check_noref ($listfname, "listfname" ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
"Fault::Logger"->arg_check_noref($listfname, "listfname") or return undef 0 0 0
151 }
152  
153 Fault::Logger->assertion_check
154 0 ▶ (!(open $fh, "<$listfname"),undef,"Can not open '$listfname': $!")
Branch: 1 branch
BranchTrueFalseTotal
"Fault::Logger"->assertion_check(!open($fh, "<$listfname"), undef, "Can not open '${listfname}': $!") or return undef 0 0 0
155 or return undef;
156  
157 # Readline returns a null list if there are no lines.
158 0 my @lines = readline $fh;
159  
160 0 return $self->addFromLines ($formatline,@lines);
161 }
162  
163 #-----------------------------------------------------------------------------
164  
165 0 ▶sub addFromTree ($$) {
Subroutine addFromTree: not called CC=3 SCAR=24.8
Pod documented
166 0 my ($self,$path) = @_;
167  
168 0 ▶ if ($::DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::DEBUG) 0 0 0
169 0 ▶ Fault::Logger->arg_check_noref ($path,"path") or return undef;
Branch: 1 branch
BranchTrueFalseTotal
"Fault::Logger"->arg_check_noref($path, "path") or return undef 0 0 0
170 }
171  
172 0 my ($dev,$directories,$file) =
173 File::Spec->splitpath(Cwd::abs_path($path));
174
175 0 $self->_branch ($dev,$directories,$file, 0);
176 0 return $self;
177 }
178  
179 #-----------------------------------------------------------------------------
180  
181 0 ▶sub addFromObject ($$) {
Subroutine addFromObject: not called CC=5 SCAR=34.0
Pod documented
182 0 my ($self,$old) = @_;
183  
184 0 ▶ if ($::DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::DEBUG) 0 0 0
185 0 ▶ Fault::Logger->arg_check_isa ($old,"FileHash::Base","oldfilehash")
Branch: 1 branch
BranchTrueFalseTotal
"Fault::Logger"->arg_check_isa($old, "FileHash::Base", "oldfilehash") or return undef 0 0 0
186 or return undef;
187 }
188  
189 0 foreach my $i (values %{$old->{'filehash'}}) {
190 0 foreach my $j (@$i) {
191 0 $self->_store ($self->_genKey ($j),$j);
192 }
193 }
194 0 return $self;
195 }
196  
197 #-----------------------------------------------------------------------------
198  
199 0 ▶sub addFromDump ($$) {
Subroutine addFromDump: not called CC=6 SCAR=37.4
Pod documented
200 0 my ($self,$path) = @_;
201 0 my ($fh,$entry,$s,$vers) = undef;
202  
203 0 ▶ if ($::DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::DEBUG) 0 0 0
204 0 ▶ Fault::Logger->arg_check_noref ($path,"path") or return undef;
Branch: 1 branch
BranchTrueFalseTotal
"Fault::Logger"->arg_check_noref($path, "path") or return undef 0 0 0
205 }
206  
207 Fault::Logger->assertion_check
208 0 ▶ (!(open $fh, "<$path"),undef,"Can not open '$path': $!")
Branch: 1 branch
BranchTrueFalseTotal
"Fault::Logger"->assertion_check(!open($fh, "<$path"), undef, "Can not open '${path}': $!") or return undef 0 0 0
209 or return undef;
210  
211 0 $_ = (<$fh>);
212 0 ▶ if (/^Version:/) {($s,$vers) = split;}
Branch: 1 branch
BranchTrueFalseTotal
if (/^Version:/) { } 0 0 0
213 else {
214 0 Fault::Logger->log
215 ("No Format version number found in report file header: '$path'");
216 0 close $fh;
217 0 return undef;
218 }
219  
220 0 while (1) {
221 0 my $entry = FileHash::Entry->alloc;
222 0 ▶ $entry->addFromDump($fh) or last;
Branch: 1 branch
BranchTrueFalseTotal
$entry->addFromDump($fh) or last 0 0 0
223  
224 0 $self->_store ($self->_genKey ($entry),$entry);
225 }
226 0 close $fh;
227 0 return $self;
228 }
229  
230 #=============================================================================
231 # Unary operators
232 #=============================================================================
233  
234 0 ▶sub identical ($) {
Subroutine identical: not called CC=5 SCAR=34.0
Pod documented
235 0 my ($fha) = @_;
236 0 my $class = ref $fha;
237 0 my ($j,$k,$v1);
238
239 0 my $fhb = $class->alloc;
240 0 ▶ $fhb->init or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$fhb->init or return undef 0 0 0
241
242 0 my $a = $fha->{'filehash'};
243 0 foreach $v1 (values %$a) {
244 0 ▶ if ($#$v1 > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v1->$#* > 0) 0 0 0
245 0 foreach $j (@$v1) {$fhb->_store ($fhb->_genKey ($j),$j);}
246 }
247 }
248 0 return $fhb;
249 }
250  
251 #-----------------------------------------------------------------------------
252  
253 0 ▶sub unique ($) {
Subroutine unique: not called CC=5 SCAR=34.0
Pod documented
254 0 my ($fha) = @_;
255 0 my $class = ref $fha;
256 0 my ($j,$k,$v1);
257
258 0 my $fhb = $class->alloc;
259 0 ▶ $fhb->init or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$fhb->init or return undef 0 0 0
260
261 0 my $a = $fha->{'filehash'};
262 0 foreach $v1 (values %$a) {
263 0 ▶ if ($#$v1 == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v1->$#* == 0) 0 0 0
264 0 foreach $j (@$v1) {$fhb->_store ($fhb->_genKey ($j),$j);}
265 }
266 }
267 0 return $fhb;
268 }
269  
270 #=============================================================================
271 # Binary operators
272 #=============================================================================
273  
274 0 ▶sub xor ($$) {
Subroutine xor: not called CC=10 SCAR=47.0
Pod documented
275 0 my ($fha,$fhb) = @_;
276 0 my $class = ref $fha;
277 0 my ($j, $k,$v1,$v2);
278  
279 0 ▶ if ($::DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::DEBUG) 0 0 0
280 0 ▶ Fault::Logger->arg_check_isa ($fhb,$class,"fhb") or return undef;
Branch: 1 branch
BranchTrueFalseTotal
"Fault::Logger"->arg_check_isa($fhb, $class, "fhb") or return undef 0 0 0
281 }
282  
283 0 my $fhc = $class->alloc;
284 0 ▶ $fhc->init or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$fhc->init or return undef 0 0 0
285  
286 0 my ($a,$b) = ($fha->{'filehash'},$fhb->{'filehash'});
287 0 ▶ while (($k,$v1) = each %$a) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$a) 0 0 0
288 0 ▶ if (!exists $b->{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $b->{$k}) 0 0 0
289 0 foreach $j (@$v1) {$fhc->_store ($fhc->_genKey ($j),$j);}
290 }
291 }
292 0 ▶ while (($k,$v2) = each %$b) {
Branch: 1 branch
BranchTrueFalseTotal
if (($k, $v2) = each %$b) 0 0 0
293 0 ▶ if (!exists $a->{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $a->{$k}) 0 0 0
294 0 foreach $j (@$v2) {$fhc->_store ($fhc->_genKey ($j),$j);}
295 }
296 }
297 0 return $fhc;
298 }
299  
300 #-----------------------------------------------------------------------------
301  
302 0 ▶sub and ($$) {
Subroutine and: not called CC=8 SCAR=42.8
Pod documented
303 0 my ($fha,$fhb) = @_;
304 0 my $class = ref $fha;
305 0 my ($j,$k,$v1,$v2);
306  
307 0 ▶ if ($::DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::DEBUG) 0 0 0
308 0 ▶ Fault::Logger->arg_check_isa ($fhb,$class,"fhb") or return undef;
Branch: 1 branch
BranchTrueFalseTotal
"Fault::Logger"->arg_check_isa($fhb, $class, "fhb") or return undef 0 0 0
309 }
310  
311 0 my $fhc = $class->alloc;
312 0 ▶ $fhc->init or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$fhc->init or return undef 0 0 0
313  
314 0 my ($a,$b) = ($fha->{'filehash'},$fhb->{'filehash'});
315 0 ▶ while (($k,$v1) = each %$a) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$a) 0 0 0
316 0 ▶ if (exists $b->{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $b->{$k}) 0 0 0
317 0 my $v2 = $b->{$k};
318 0 foreach $j (@$v1) {$fhc->_store ($fhc->_genKey ($j),$j);}
319 0 foreach $j (@$v2) {$fhc->_store ($fhc->_genKey ($j),$j);}
320 }
321 }
322 0 return $fhc;
323 }
324  
325 #-----------------------------------------------------------------------------
326  
327 0 ▶sub andnot ($$) {
Subroutine andnot: not called CC=7 SCAR=40.3
Pod documented
328 0 my ($fha,$fhb) = @_;
329 0 my $class = ref $fha;
330 0 my ($j,$k,$v1,$v2);
331  
332 0 ▶ if ($::DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::DEBUG) 0 0 0
333 0 ▶ Fault::Logger->arg_check_isa ($fhb,$class,"fhb") or return undef;
Branch: 1 branch
BranchTrueFalseTotal
"Fault::Logger"->arg_check_isa($fhb, $class, "fhb") or return undef 0 0 0
334 }
335  
336 0 my $fhc = $class->alloc;
337 0 ▶ $fhc->init or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$fhc->init or return undef 0 0 0
338  
339 0 my ($a,$b) = ($fha->{'filehash'},$fhb->{'filehash'});
340 0 ▶ while (($k,$v1) = each %$a) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$a) 0 0 0
341 0 ▶ if (!exists $b->{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $b->{$k}) 0 0 0
342 0 foreach $j (@$v1) {$fhc->_store ($fhc->_genKey ($j),$j);}
343 }
344 }
345 0 return $fhc;
346 }
347  
348 #=============================================================================
349  
350 0 ▶sub dump ($$) {
Subroutine dump: not called CC=7 SCAR=40.3
Pod documented
351 0 my ($self,$dumpfile) = @_;
352 0 my $fh;
353  
354 0 ▶ if ($::DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::DEBUG) 0 0 0
355 0 ▶ Fault::Logger->arg_check_noref ($dumpfile,"dumpfile") or return undef;
Branch: 1 branch
BranchTrueFalseTotal
"Fault::Logger"->arg_check_noref($dumpfile, "dumpfile") or return undef 0 0 0
356 }
357  
358 Fault::Logger->assertion_check
359 0 ▶ (!(open $fh, ">$dumpfile"),undef,"Can not open '$dumpfile': $!")
Branch: 1 branch
BranchTrueFalseTotal
"Fault::Logger"->assertion_check(!open($fh, ">$dumpfile"), undef, "Can not open '${dumpfile}': $!") or return undef 0 0 0
360 or return undef;
361  
362 0 ▶ if (!printf $fh "Version: " . FileHash::Entry->dumpversion . "\n") {
Branch: 1 branch
BranchTrueFalseTotal
unless (printf $fh 'Version: ' . "FileHash::Entry"->dumpversion . "\n") 0 0 0
363 0 Fault::Logger->log ("Failed to print dumpfile header: $!");
364 0 close $fh;
365 0 return undef;
366 }
367  
368 0 foreach my $i (values %{$self->{'filehash'}}) {
369 0 foreach my $j (@$i) {$j->fprint ($fh);}
370 }
371  
372 0 close $fh;
373 0 return $self;
374 }
375
376 #=============================================================================
377 # POD DOCUMENTATION
378 #=============================================================================
379 # You may extract and format the documention section with the 'perldoc' cmd.
380  
381 =head1 NAME
382  
383 FileHash::Base - Abstract superclass for FileHashes.
384  
385 =head1 SYNOPSIS
386  
387 use FileHash;
388 $obj = FileHash::Base->alloc;
389  
390 $obj = $obj->init;
391 $obj = $obj->initFromLines ($formatline,@lines);
392 $obj = $obj->initFromFile ($formatline,$datafilepath);
393 $obj = $obj->initFromTree ($rootdir);
394 $obj = $obj->initFromObject ($obj2);
395 $obj = $obj->initFromDump ($path);
396  
397 $obj = $obj->addFromLines ($formatline,@lines);
398 $obj = $obj->addFromFile ($formatline,$datafilepath);
399 $obj = $obj->addFromTree ($rootdir);
400 $obj = $obj->addFromObject ($obj2);
401 $obj = $obj->addFromDump ($path);
402  
403 $fhb = $fha->identical;
404 $fhb = $fha->unique;
405  
406 $fhc = $fha->and ($fhb);
407 $fhc = $fha->andnot ($fhb);
408 $fhc = $fha->xor ($fhb);
409  
410 $obj = $obj->dump ($dumpfile);
411  
412 =head1 Inheritance
413  
414 UNIVERSAL
415  
416 =head1 Description
417  
418 This is an abstract superclass for containers of lists of file metadata.
419 It is not directly useable and will execute a Fault if you attempt it.
420  
421 FileHash::Name and FileHash::Content inherit most of their behavior from
422 here with the exception of hash key selection.
423  
424 =head1 Examples
425  
426 See subclasses.
427  
428 =head1 Class Variables
429  
430 None.
431  
432 =head1 Instance Variables
433  
434 filehash Pointer to a hash of arrays of FileHash::Entry objects
435 which contain all the file metadata discovered found
436 when the FileHash object was initialized. Entries for files
437 with identical keys hash into the same array, making for
438 a very efficient sort.
439  
440 =head1 Class Methods
441  
442 =over 4
443  
444 =item B<$obj = FileHash::Base-E<gt>alloc>
445  
446 Allocate an empty instance of FileHash::Base. This is for inheritance
447 only and should not be used. Subclasses could override but there is
448 probably no reason to do so unless they add ivars. None do at present.
449  
450 =head1 Instance Methods
451  
452 Unless otherwise specified, instance methods return self on success and
453 undef on failure.
454  
455 =over 4
456  
457 =item B<$fhc = $fha-E<gt>and ($fhb)>
458  
459 Create a file hash containing the groups of files found in both
460 filehash a and b.
461  
462 a and b must be of the same FileHash subclass and the newly created
463 c will be off that type also.
464  
465 =item B<$fhc = $fha-E<gt>andnot ($fhb)>
466  
467 Create a file hash containing the groups of files found in filehash
468 a but not in filehash b.
469  
470 a and b must be of the same FileHash subclass and the newly created
471 c will be off that type also.
472  
473 If you want not a and b, just reverse the args; not a and not b is
474 obviously nonsensical as we are testing keys of a against keys of
475 b.
476  
477 =item B<$obj = $obj-E<gt>addFromDump ($dumpfile)>
478  
479 Use a dump file to recreate hash entries and add them to a FileHash
480 object.
481  
482 The first line of the file must contain the text:
483  
484 Version: x.yy
485  
486 =item B<$obj = $obj-E<gt>addFromFile ($format,$datafilepath)>
487  
488 Use the format line to create a FileHash::FormatString object. The
489 format object is used to parse each of the lines in a file which
490 contains lines of text data. Each line in the file is assumed to
491 contain data about one file which is to be added to the FileHash.
492  
493 =item B<$obj = $obj-E<gt>addFromLines ($format,@lines)>
494  
495 Use the format line to create a FileHash:FormatString object. The
496 format object is used to parse each of the lines in a list. Each
497 line contains data about one file which is to be added to the FileHash.
498  
499 =item B<$obj = $obj-E<gt>addFromObject ($obj2)>
500  
501 Add data to a filehash from another FileHash, $obj2. This is useful for
502 merging two objects. The subclasses need not be the same because the
503 Entries are inserted by re-hashing into the target object.
504  
505 my $a = FileHash::Name->alloc;
506 $a->initFromTree ("/root");
507 $a->addFromTree ("/home/me");
508  
509 =item B<$obj = $obj-E<gt>addFromTree ($rootdir)>
510  
511 Entries are added to the hash via a recursive descent through a directory
512 tree. Each file is a 'leaf node' and is represented by an array record in
513 the hash. If two files have the same hash key, the are likely identical
514 so the records for them are placed together in an array under that hask key.
515  
516 =item B<$obj = $obj-E<gt>dump ($dumpfile)>
517  
518 Dump FileHash::Entry objects sequentially, one to a line, to the specified
519 filename.
520  
521 The first line of the file contains the FileHash::Entry dump file format
522 version number in this format:
523  
524 Version: x.yy
525  
526 =item B<$fhb = $fha-E<gt>identical>
527  
528 Return a FileHash containing the contents of hash keys which have more
529 than one member. If the keys are md5,length this represents all files
530 with the same content; if they keys are name it represents all files
531 with the same name.
532  
533 =item B<$obj = $obj-E<gt>init>
534  
535 A noop at present. If you need an empty object, use this after alloc
536 to make sure that if init is needed in the future, it will be carried
537 out.
538  
539 =item B<$obj = $obj-E<gt>initFromDump ($dumpfile)>
540  
541 Use a dump file to recreate hash entries in a freshly alloc'd FileHash
542 object.
543  
544 The first line of the file must contain the text:
545  
546 Version: x.yy
547  
548 =item B<$obj = $obj-E<gt>initFromFile ($format,$datafilepath)>
549  
550 Initialize a freshly alloc'd FileHash. It uses the format line
551 to init a FileHash::FormatString object. The format object is used to parse
552 each of the lines in a file which contains lines of text data. Each line
553 in the file is assumed to contain data about one file.
554  
555 =item B<$obj = $obj-E<gt>initFromLines ($format,@lines)>
556  
557 Initialize a freshly formatted FileHash. It uses the format line
558 to create a FileHash:FormatString object. The format object is used to parse
559 each of the lines in a list. Each line contains data about one file.
560  
561 =item B<$obj = $obj-E<gt>initFromObject ($obj2)>
562  
563 Initialize the newly alloc'd object using data from another FileHash, $obj2.
564 This is useful for changing from hashing by name to hashing by content or
565 vice versa:
566  
567 my $a = FileHash::Name->alloc;
568 my $b = FileHash::Content->alloc;
569 $a->initFromTree ("/root");
570 $b->initFromObject ($a);
571  
572 =item B<$obj = $obj-E<gt>initFromTree ($rootdir)>
573  
574 Initialize a freshly alloc'd FileHash. The hash is filled via a
575 recursive descent through a directory tree. Each file is a
576 'leaf node' and is represented by an array record in the hash. If
577 two files have the same hash key, the are likely identical so the records
578 for them are placed together in an array under that hask key.
579  
580 =item B<$fhb = $fha-E<gt>unique>
581  
582 Return a FileHash containing the contents of hash keys which have only
583 one member. These are files for which no other file has the same content
584 if the key is md5,length; or the same name if the key is the name.
585  
586 =item B<$fhc = $fha-E<gt>xor ($fhb)>
587  
588 Create a filehash c which contains all of the groups of files which
589 are only in fha or fhb but not both.
590  
591 a and b must be of the same FileHash subclass and the newly created
592 c will be off that type also.
593  
594 =back 4
595  
596 =head1 Private Class Method
597  
598 None.
599  
600 =head1 Private Instance Methods
601  
602 =item B<$key = $obj-E<gt>_genKey($entry)>
603  
604 Create an appropriate hash key. Each subclass must override this
605 stub method as it does nothing except print a warning message
606 and crash the program.
607  
608 =head1 Errors and Warnings
609  
610 Lots.
611  
612 =head1 KNOWN BUGS
613  
614 See TODO.
615  
616 =head1 SEE ALSO
617  
618 File::Spec, Cwd, FileHash::Entry, FileHash::FormatString, Fault::Logger.
619  
620 =head1 AUTHOR
621  
622 Dale Amon <amon@vnl.com>
623  
624 =cut
625
626 #=============================================================================
627 # CVS HISTORY
628 #=============================================================================
629 # $Log: Base.pm,v $
630 # Revision 1.10 2008-08-28 23:35:28 amon
631 # perldoc section regularization.
632 #
633 # Revision 1.9 2008-08-09 20:25:13 amon
634 # Documentation error fixed.
635 #
636 # Revision 1.8 2008-08-09 12:56:01 amon
637 # Used wrong method name. Fixed
638 #
639 # Revision 1.7 2008-08-04 12:12:20 amon
640 # Added unary and binary ops; made init methods synonums for add methods.
641 #
642 # Revision 1.6 2008-07-27 15:16:17 amon
643 # Wrote lexical parse for Entry; error checking on eval and other minor issues.
644 #
645 # Revision 1.5 2008-07-25 14:30:42 amon
646 # Documentation improvements and corrections.
647 #
648 # Revision 1.4 2008-07-24 20:19:43 amon
649 # Just in case I missed anything.
650 #
651 # Revision 1.3 2008-07-24 13:35:26 amon
652 # switch to NeXT style alloc/init format for FileHash and Entry classes.
653 #
654 # Revision 1.2 2008-07-23 21:12:24 amon
655 # Moved notes out of file headers; a few doc updates; added assertion checks;
656 # minor bug fixes.
657 #
658 # 20080722 Dale Amon <amon@vnl.com>
659 # Renamed FileHash.pm to Base.pm so it is FileHash::Base.
660 # 20080717 Dale Amon <amon@vnl.com>
661 # Split FilenameHash, formerly Directory class, into FileHash
662 # FileHash::Name and FileHash::Content.
663 # 20080625 Dale Amon <amon@vnl.com>
664 # Created.
665 1 1;
↑ Summary Report.pm »