blib/lib/File/Find/Repository.pm

filter: Statementstmt 100% 149 / 149 Branchbran 100% 76 / 76 Conditioncond 95.4% 21 / 22 MC/DCmcdc 75.0% 9 / 12 Subroutinesub 100% 17 / 17 Podpod 100% 7 / 7 totaltotal 98.5% 279 / 283 CC 51 SCAR 23.8
CC
51
Cov
100%
Find
20.0
Setup
10.0
FindFiles
10.0
CRAP 10.9
↑ Summary
1  
2 package File::Find::Repository ;
3  
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings ;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 BEGIN
8 6 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use vars qw ($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 $VERSION = '0.03';
11 }
12  
13 #-------------------------------------------------------------------------------
14  
15 6 ▶use Carp qw(carp croak confess) ;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use English qw( -no_match_vars ) ;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 6 ▶use Readonly ;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 Readonly my $EMPTY_STRING => q{} ;
20  
21 6 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 ▶use Tie::Hash::Indexed ;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 #-------------------------------------------------------------------------------
25  
26 =head1 NAME
27  
28 File::Find::Repository - Find files in your repositories.
29  
30 =head1 SYNOPSIS
31  
32 use File::Find::Repository ;
33
34 my $locator = new File::Find::Repository
35 (
36 NAME => 'name you want to see when messages are displayed',
37
38 REPOSITORIES =>
39 [
40 'path',
41 \&sub,
42 ...
43 ],
44 ) ;
45
46 # single scalar argument
47 my $located_file = $locator->Find($file_to_locate) ;
48
49 # multiple arguments
50 my $located_files = $locator->Find
51 (
52 FILES => [...],
53 REPOSITORIES => ['path', \&sub, ...],
54 VERBOSE => 1,
55 ) ;
56  
57 =head1 DESCRIPTION
58  
59 This module will find files in a set of repositories.
60  
61 =head1 DOCUMENTATION
62  
63 This module will try to locate a file in the repositories you define. The repositories are either
64 a string representing a local filesystem path or a sub.
65  
66 When locating a file, multiple file match can occur (each in a different repository). The default behavior is
67 to return the first match.
68  
69 You can customize the behavior of the search with two callbacks.
70  
71 B<FULL_INFO> will be called to allow you to add relevant information to the files that have been located.
72  
73 B<WHICH> will be called to let you decide which found files is returned.
74  
75 =head3 Advanced example
76  
77 This module was extracted from B<PBS>, a build system, made generic and will be re-integrated in B<PBS>
78 in next version. Here is how it could be used for a more advanced repository search.
79  
80 Let's imagine we have multiple matches for an object file in our repositories. The goal here is to not rebuild the object
81 file. Selecting the first object file in the list would be too naive so we define a B<WHICH> callback that will select
82 the most appropriate. In this case, it might involve looking in the object file digest and/or check what configuration was
83 used when the object file was build.
84  
85 my $located_file = $locator->Find
86 (
87 FILES => [$file_to_locate],
88 REPOSITORIES => [$build_directory, @repositories],
89 WHICH => FIND_NODE_WITH_DEPENDENCIES($information_needed_to_select_the_found_file)
90
91 # bote that FIND_NODE_WITH_DEPENDENCIES returns a sub reference
92 ) ;
93
94 $located_file ||= "$build_directory/$located_file" ;
95
96  
97 =head1 SUBROUTINES/METHODS
98  
99 =cut
100  
101  
102 #-------------------------------------------------------------------------------
103  
104 sub new
105 18 ▶{
Subroutine new: called CC=3 SCAR=11.0
Pod documented
106  
107 =head2 new
108  
109 Create a File::Find::Repository .
110  
111 my $locator = new File::Find::Repository
112 (
113 # all arguments are optional
114
115 NAME => 'name you want to see when messages are displayed',
116
117 REPOSITORIES =>
118 [
119 'path',
120 \&sub,
121 ...
122 ],
123
124 INTERACTION =>
125 {
126 INFO = \&OnMyTerminal,
127 WARN = \&WithBlinkingRedLetters,
128 DIE = \&QuickAndPainless,
129 }
130
131 VERBOSE => 1,
132 FULL_INFO => \&File::Find::Repository::TIME_AND_SIZE,
133 WHICH => \&File::Find::Repository::FIRST_FOUND,
134 ) ;
135  
136 =head3 Options
137  
138 =over 2
139  
140 =item * NAME
141  
142 Name you want to see when messages are displayed.
143  
144 =item * REPOSITORIES
145  
146 An array reference. The elements are either scalars representing a local filesystem path or a code
147 reference. The code references are passed a single argument, the file to locate, and should either
148 return the located file or undef.
149  
150 This allows you to, for example, to locate the files on servers.
151  
152 =item * INTERACTION
153  
154 Lets you define subs used to interact with the user.
155  
156 INTERACTION =>
157 {
158 INFO => \&sub,
159 WARN => \&sub,
160 DIE => \&sub,
161 }
162  
163 =over 4
164  
165 =item INFO
166  
167 This sub will be used when displaying L<VERBOSE> information.
168  
169 =item WARN
170  
171 This sub will be used when a warning is displayed.
172  
173 =item DIE
174  
175 Used when an error occurs.
176  
177 =back
178  
179 The functions default to:
180  
181 =over 2
182  
183 =item * INFO => print
184  
185 =item * WARN => Carp::carp
186  
187 =item * DIE => Carp::confess
188  
189 =back
190  
191 =item * VERBOSE
192  
193 When set, informative messages will be displayed.
194  
195 =item * FULL_INFO
196  
197 This is set to a sub ref which is called for all the found files, this allows you to add information.
198 See L<File::Find::Repository::TIME_AND_SIZE> for an example.
199  
200 Passed arguments:
201  
202 =over 4
203  
204 =item * the File::Find::Repository object.
205  
206 This is useful when you want to display a message; use the subroutines defined in $object->{INTERACTION}.
207  
208 =item * The file name
209  
210 =item * a hash reference.
211  
212 The found file.
213  
214 =back
215  
216 =item * WHICH
217  
218 By defaults, B<File::Find::Repository> will set I<WHICH> to I<File::Find::Repository::FIRST_FOUND> which
219 return the first file found in the repositories.
220  
221 Define this callback if you wish to return something else, e.g. the newest file or the largest file.
222  
223 I<WHICH> subroutine will be called with these arguments:
224  
225 =over 4
226  
227 =item * the File::Find::Repository object.
228  
229 This is useful when you want to display a message; use the subroutines defined in $object->{INTERACTION}.
230  
231 =item * a hash reference.
232  
233 Containing all the found files, after processing with L<FULL_INFO>. The hash is ordered.
234  
235 =back
236  
237 The subroutine should return one of the array elements or undef. Note that you could also return an element
238 not present in the hash. In this case, a proper documentation of your algorithm will help maintenance.
239  
240 =back
241  
242 =cut
243  
244 18 my ($invocant, @setup_data) = @_ ;
245  
246 18 ▶my $class = ref($invocant) || $invocant ;
Condition100%3/3
ref $invocant || $invocant
l!l&&r!l&&!r
1161
MC/DC100%2/2
ref $invocant || $invocant
ref $invocant $invocant
Truth table100%3/3
A || B
A= ref $invocantB= $invocant
ABresult
1X1
011
000
247 18 ▶confess 'Invalid constructor call!' unless defined $class ;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $class 1 17 18
248  
249 17 my $object = {} ;
250  
251 17 my ($package, $file_name, $line) = caller() ;
252 17 bless $object, $class ;
253  
254 17 $object->Setup($package, $file_name, $line, @setup_data) ;
255  
256 14 return($object) ;
257 }
258  
259 #-------------------------------------------------------------------------------
260  
261 sub Setup
262 17 ▶{
Subroutine Setup: called CC=10 SCAR=23.0
Pod documented
263  
264 =head2 Setup
265  
266 Helper sub called by new. This is a private sub.
267  
268 =cut
269  
270 17 my ($object, $package, $file_name, $line, @setup_data) = @_ ;
271  
272 17 %{$object} =
273 (
274 NAME => "Anonymous created at $file_name:$line",
275 WHICH => \&FIRST_FOUND,
276
277 @setup_data,
278
279 AT_FILE => $file_name,
280 AT_LINE => $line,
281 ) ;
282  
283 17 my $location = "$object->{AT_FILE}:$object->{AT_LINE}" ;
284  
285 $object->{VALID_OPTIONS} =
286 {
287 17 map{$_ => 1}
288 qw(
289 FILES
290 FULL_INFO
291 INTERACTION
292 REPOSITORIES
293 VERBOSE
294 WHICH
295
296 AT_FILE
297 AT_LINE
298 )
299 } ;
300  
301 #~ $object->{INTERACTION}{INFO} ||= \&CORE::print ;
302 17 ▶$object->{INTERACTION}{INFO} ||= sub{print(@_) or croak "Can't print! $!"};
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
print @_ or croak("Can't print! $!") 5 1 6
Condition66%2/3
$object->{"INTERACTION"}{"INFO"} ||= sub { print @_ or croak("Can't print! $!"); }
l!l&&r!l&&!r
1160
MC/DC0%0/2
$object->{"INTERACTION"}{"INFO"} ||= sub { print @_ or croak("Can't print! $!"); }
$object->{"INTERACTION"}{"INFO"} sub { print @_ or croak("Can't print! $!"); }
Truth table66%2/3
A ||= B
A= $object->{"INTERACTION"}{"INFO"}B= sub { print @_ or croak("Can't print! $!"); }
ABresult
1X1
011
000
303 17 ▶$object->{INTERACTION}{WARN} ||= \&Carp::carp ;
Condition100%2/2
$object->{"INTERACTION"}{"WARN"} ||= \&Carp::carp
l!l
116
MC/DC100%1/1
$object->{"INTERACTION"}{"WARN"} ||= \&Carp::carp
$object->{"INTERACTION"}{"WARN"}
Truth table100%2/2
A
A= $object->{"INTERACTION"}{"WARN"}
Aresult
11
00
304 17 ▶$object->{INTERACTION}{DIE} ||= \&Carp::confess ;
Condition100%2/2
$object->{"INTERACTION"}{"DIE"} ||= \&Carp::confess
l!l
215
MC/DC100%1/1
$object->{"INTERACTION"}{"DIE"} ||= \&Carp::confess
$object->{"INTERACTION"}{"DIE"}
Truth table100%2/2
A
A= $object->{"INTERACTION"}{"DIE"}
Aresult
11
00
305  
306 17 ▶if(defined $object->{REPOSITORIES})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $object->{"REPOSITORIES"}) 15 2 17
307 {
308 15 ▶ if('ARRAY' ne ref $object->{REPOSITORIES})
Branch: 1 branch
BranchTrueFalseTotal
if ("ARRAY" ne ref $object->{"REPOSITORIES"}) 1 14 15
309 {
310 1 $object->{INTERACTION}{DIE}->("$object->{NAME}: REPOSITORIES must be an array reference at '$location'!") ;
311 }
312
313 14 for my $repository (@{$object->{REPOSITORIES}})
314 {
315 28 ▶ if(defined $repository)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $repository) { } 27 1 28
316 {
317 27 my $type = ref $repository ;
318
319 27 ▶ if($EMPTY_STRING ne $type && 'CODE' ne $type)
Branch: 1 branch
BranchTrueFalseTotal
if ($EMPTY_STRING ne $type and "CODE" ne $type) 1 26 27
Condition100%3/3
$EMPTY_STRING ne $type and "CODE" ne $type
!ll&&!rl&&r
2421
MC/DC100%2/2
$EMPTY_STRING ne $type and "CODE" ne $type
$EMPTY_STRING ne $type "CODE" ne $type
Truth table100%3/3
A and B
A= $EMPTY_STRING ne $typeB= "CODE" ne $type
ABresult
0X0
100
111
320 {
321 1 $object->{INTERACTION}{DIE}->("$object->{NAME}: invalid repository type '$type' at '$location'!") ;
322 }
323 }
324 else
325 {
326 1 $object->{INTERACTION}{DIE}->("$object->{NAME}: invalid repository [undef] at '$location'!") ;
327 }
328 }
329 }
330
331 14 return(1) ;
332 }
333  
334 #-------------------------------------------------------------------------------
335  
336 sub Find
337 31 ▶{ ## no critic (ProhibitExcessComplexity)
Subroutine Find: called CC=20 SCAR=30.0
Pod documented
338  
339 =head2 Find
340  
341 # single scalar argument
342 my $located_file = $locator->Find($file_to_locate) ;
343
344 # multiple arguments
345 my $located_files = $locator->Find
346 (
347 FILES => [...],
348
349 # optional
350 REPOSITORIES => ['path', \&sub, ...],
351 VERBOSE => 1,
352 INTERACTION => { INFO = \&OnMyTerminal,},
353 FULL_INFO => \&File::Find::Repository::TIME_AND_SIZE,
354 WHICH => \&File::Find::Repository::FIRST_FOUND,
355 ) ;
356  
357 =head3 SCALAR calling context
358  
359 Only SCALAR calling context is allowed.
360  
361 =head3 Arguments
362  
363 If a single string argument is passed to Find, a string or undef is returned.
364  
365 If multiple arguments are passed, they will override the object's values for the call duration.
366  
367 Valid arguments:
368  
369 =over 2
370  
371 =item * FILES
372  
373 An array ref with scalar elements. Each element represents a file to locate. The returned value will be an
374 ordered hash reference.
375  
376 =item * AT_FILE and AT_LINE
377  
378 These will be used in the information message and the history information if set. If not set, the values
379 returned by I<caller> will be used. B<These options allow you to write wrapper functions> that report the
380 callers location properly.
381  
382 All arguments passed to L<New>, except B<NAME> are also valid arguments to L<Find>.
383  
384 =back
385  
386 =cut
387  
388 31 my ($self, @arguments) = @_ ;
389  
390 31 my $single_file_to_find = $EMPTY_STRING ;
391 31 my ($number_of_arguments) = scalar(@arguments) ;
392  
393 31 my $location = "$self->{AT_FILE}:$self->{AT_LINE}" ;
394  
395 31 ▶if($number_of_arguments <= 0)
Branch: 2 branches
BranchTrueFalseTotal
if ($number_of_arguments <= 0) { } 1 30 31
elsif ($number_of_arguments == 1) { } 8 22 30
396 {
397 1 $self->{INTERACTION}{DIE}->("$self->{NAME}: No argument at '$location'!") ;
398 }
399 elsif($number_of_arguments == 1)
400 {
401 8 ▶ if($EMPTY_STRING eq ref $arguments[0])
Branch: 1 branch
BranchTrueFalseTotal
if ($EMPTY_STRING eq ref $arguments[0]) { } 7 1 8
402 {
403 7 $single_file_to_find = $arguments[0] ;
404 7 @arguments = (FILES => [@arguments]) ;
405 }
406 else
407 {
408 1 $self->{INTERACTION}{DIE}->("$self->{NAME}: single argument must be scalar at '$location'!") ;
409 }
410 }
411  
412 29 my %arguments = @arguments ;
413 29 $self->CheckOptions(\%arguments) ;
414  
415 ## no critic (ProhibitLocalVars ProhibitConditionalDeclarations)
416  
417 23 local $self->{FILES} = $arguments{FILES} ;
418  
419 23 ▶local $self->{FULL_INFO} = $arguments{FULL_INFO} if exists $arguments{FULL_INFO} ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $arguments{"FULL_INFO"} 1 22 23
420  
421 23 ▶local $self->{INTERACTION}{INFO} = $arguments{INTERACTION}{INFO} if exists $arguments{INTERACTION}{INFO} ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $arguments{"INTERACTION"}{"INFO"} 4 19 23
422 23 ▶local $self->{INTERACTION}{WARN} = $arguments{INTERACTION}{WARN} if exists $arguments{INTERACTION}{WARN} ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $arguments{"INTERACTION"}{"WARN"} 4 19 23
423 23 ▶local $self->{INTERACTION}{DIE} = $arguments{INTERACTION}{DIE} if exists $arguments{INTERACTION}{DIE} ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $arguments{"INTERACTION"}{"DIE"} 4 19 23
424  
425 23 ▶local $self->{REPOSITORIES} = $arguments{REPOSITORIES} if exists $arguments{REPOSITORIES} ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $arguments{"REPOSITORIES"} 7 16 23
426 23 ▶local $self->{VERBOSE} = $arguments{VERBOSE} if exists $arguments{VERBOSE} ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $arguments{"VERBOSE"} 4 19 23
427 23 ▶local $self->{WHICH} = $arguments{WHICH} if exists $arguments{WHICH} ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $arguments{"WHICH"} 5 18 23
428 23 ▶local $self->{AT_FILE } = $arguments{AT_FILE } if exists $arguments{AT_FILE } ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $arguments{"AT_FILE"} 1 22 23
429 23 ▶local $self->{AT_LINE } = $arguments{AT_LINE } if exists $arguments{AT_LINE };
Branch: 1 branch
BranchTrueFalseTotal
if exists $arguments{"AT_LINE"} 1 22 23
430  
431 ## use critic
432  
433 23 $location = "$self->{AT_FILE}:$self->{AT_LINE}" ;
434  
435 23 ▶if(! defined wantarray)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 3 20 23
436 {
437 3 $self->{INTERACTION}{DIE}->("$self->{NAME}: not called in scalar context at '$location'!") ;
438 }
439
440 20 ▶if(wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 1 19 20
441 {
442 1 $self->{INTERACTION}{DIE}->("$self->{NAME}: not called in scalar context at '$location'!") ;
443 }
444  
445 19 my %located_files ;
446  
447 19 for my $file_to_locate (@{$arguments{FILES}})
448 {
449 19 my $located_files = $self->FindFiles($file_to_locate) ;
450
451 16 ▶ if(keys %{$located_files})
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$located_files;}) { } 12 4 16
452 {
453 12 ▶ if($self->{FULL_INFO})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"FULL_INFO"}) 2 10 12
454 {
455 2 ▶ while (my ($file_name, $file) = each %{$located_files})
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$located_files;}) 8 2 10
456 {
457 8 $self->{FULL_INFO}->($self, $file_to_locate, $file) ;
458 }
459 }
460
461 12 $located_files{$file_to_locate} = $self->{WHICH}->($self, $located_files) ;
462 }
463 else
464 {
465 4 $located_files{$file_to_locate} = undef ;
466 }
467 }
468
469 16 ▶if($number_of_arguments == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($number_of_arguments == 1) { } 6 10 16
470 {
471 6 return($located_files{$single_file_to_find}{FOUND_AT}) ;
472 }
473 else
474 {
475 10 return(\%located_files) ;
476 }
477 }
478  
479 #-------------------------------------------------------------------------------
480  
481 sub FindFiles
482 19 ▶{
Subroutine FindFiles: called CC=10 SCAR=23.0
Pod documented
483  
484 =head2 FindFiles
485  
486 This is a private sub. Do not use directly.
487  
488 Finds all the files in the repositories.
489  
490 =cut
491  
492 19 my ($self, $file_to_locate) = @_ ;
493  
494 19 my $location = "$self->{AT_FILE}:$self->{AT_LINE}" ;
495  
496 19 tie my %files_found, 'Tie::Hash::Indexed' ; ## no critic
497  
498 19 ▶if(File::Spec->file_name_is_absolute($file_to_locate))
Branch: 1 branch
BranchTrueFalseTotal
if ('File::Spec'->file_name_is_absolute($file_to_locate)) { } 2 17 19
499 {
500 2 $self->{INTERACTION}{WARN}->("$self->{NAME}: passed absolute file path '$file_to_locate' at $location.\n") ;
501 }
502 else
503 {
504 17 ▶ $self->{INTERACTION}{INFO}->("Searching for '$file_to_locate':\n") if $self->{VERBOSE} ;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"VERBOSE"} 4 13 17
505
506 16 for my $source_directory (@{$self->{REPOSITORIES}})
507 {
508 59 my $searched_file = "$source_directory/$file_to_locate" ;
509 59 my $file_found ;
510
511 59 my $type = ref $source_directory ;
512
513 59 ▶ if($EMPTY_STRING eq $type)
Branch: 2 branches
BranchTrueFalseTotal
if ($EMPTY_STRING eq $type) { } 56 3 59
elsif ('CODE' eq $type) { } 2 1 3
514 {
515 56 ▶ $file_found = $searched_file if( -e $searched_file) ;
Branch: 1 branch
BranchTrueFalseTotal
if -e $searched_file 30 26 56
516 }
517 elsif('CODE' eq $type)
518 {
519 2 $file_found = $source_directory->($file_to_locate);
520 }
521 else
522 {
523 1 $self->{INTERACTION}{DIE}->("$self->{NAME}: Invalid repository type '$type' at $location.\n") ;
524 }
525
526 58 ▶ if(defined $file_found)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file_found) { } 32 26 58
527 {
528 32 $files_found{$file_found} = {FOUND_AT => $file_found, EXISTS => (-e $file_found)} ;
529 32 ▶ $self->{INTERACTION}{INFO}->(" Found in '$source_directory'\n.") if $self->{VERBOSE} ;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"VERBOSE"} 6 26 32
530 }
531 else
532 {
533 26 ▶ $self->{INTERACTION}{INFO}->(" Not found in '$source_directory'.\n") if $self->{VERBOSE} ;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"VERBOSE"} 6 20 26
534 }
535 }
536 }
537
538 16 return(\%files_found) ;
539 }
540  
541 #-------------------------------------------------------------------------------
542  
543 sub CheckOptions
544 29 ▶{
Subroutine CheckOptions: called CC=10 SCAR=23.0
Pod documented
545  
546 =head2 CheckOptions
547  
548 Verifies the options passed to the members of this class. Calls B<{INTERACTION}{DIE}> in case
549 of error. This shall not be used directly.
550  
551 =cut
552  
553 29 my ($self, $options) = @_ ;
554 29 my $location = "$self->{AT_FILE}:$self->{AT_LINE}" ;
555  
556 29 for my $option_name (keys %{$options})
557 {
558 56 ▶ $self->{INTERACTION}{DIE}->("$self->{NAME}: Invalid Option '$option_name' at '$self->{AT_FILE}:$self->{AT_LINE}'!") unless exists $self->{VALID_OPTIONS}{$option_name} ;
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"VALID_OPTIONS"}{$option_name} 1 55 56
559 }
560  
561 28 ▶if
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options->{"AT_FILE"} and not defined $options->{"AT_LINE"} or not defined $options->{"AT_FILE"} and defined $options->{"AT_LINE"}) 2 26 28
Condition100%9/9
defined $options->{"AT_FILE"} and not defined $options->{"AT_LINE"} or not defined $options->{"AT_FILE"} and defined $options->{"AT_LINE"}
l!l&&r!l&&!r
1126
defined $options->{"AT_FILE"} and not defined $options->{"AT_LINE"}
!ll&&!rl&&r
2611
not defined $options->{"AT_FILE"} and defined $options->{"AT_LINE"}
!ll&&!rl&&r
1251
MC/DC75%3/4
defined $options->{"AT_FILE"} and not defined $options->{"AT_LINE"} or not defined $options->{"AT_FILE"} and defined $options->{"AT_LINE"}
defined $options->{"AT_FILE"} not defined $options->{"AT_LINE"} not defined $options->{"AT_FILE"} defined $options->{"AT_LINE"}
Truth table57%4/7
A and not(B) or not(C) and D
A= defined $options->{"AT_FILE"}B= not defined $options->{"AT_LINE"}C= not defined $options->{"AT_FILE"}D= defined $options->{"AT_LINE"}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
562 (
563 (defined $options->{AT_FILE} && ! defined $options->{AT_LINE})
564 || (!defined $options->{AT_FILE} && defined $options->{AT_LINE})
565 )
566 {
567 2 $self->{INTERACTION}{DIE}->("$self->{NAME}: Incomplete option AT_FILE::AT_LINE!") ;
568 }
569  
570 # check we have enough to work with
571 26 ▶unless(exists $options->{FILES})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $options->{"FILES"}) 1 25 26
572 {
573 1 $self->{INTERACTION}{DIE}->("$self->{NAME}: No FILES to find at '$location'!") ;
574 }
575
576 25 ▶if('ARRAY' ne ref $options->{FILES})
Branch: 1 branch
BranchTrueFalseTotal
if ("ARRAY" ne ref $options->{"FILES"}) 1 24 25
577 {
578 1 $self->{INTERACTION}{DIE}->("$self->{NAME}: Invalid FILES at '$location'!") ;
579 }
580  
581 24 ▶if(0 == scalar(@{$options->{FILES}}))
Branch: 1 branch
BranchTrueFalseTotal
if (0 == scalar @{$options->{"FILES"};}) 1 23 24
582 {
583 1 $self->{INTERACTION}{DIE}->("$self->{NAME}: no entries in FILES at '$location'!") ;
584 }
585  
586 23 return(1) ;
587 }
588  
589 #-------------------------------------------------------------------------------
590  
591 sub FIRST_FOUND
592 11 ▶{
Subroutine FIRST_FOUND: called CC=1 SCAR=0.0
Pod documented
593  
594 =head2 FIRST_FOUND
595  
596 Returns the first matching file.
597  
598 =cut
599  
600 11 my ($object, $located_files) = @_ ;
601  
602 11 my (@keys) = keys %{$located_files} ;
603  
604 11 return($located_files->{$keys[0]}) ;
605 }
606  
607 #-------------------------------------------------------------------------------
608  
609 sub TIME_AND_SIZE
610 8 ▶{
Subroutine TIME_AND_SIZE: called CC=2 SCAR=6.9
Pod documented
611  
612 =head2 TIME_AND_SIZE
613  
614 Adds time and size information to the matched file.
615  
616 =cut
617  
618 8 my ($object, $file_name, $file) = @_ ;
619  
620 8 Readonly my $YEAR_1900 => 1900 ;
621 8 Readonly my $STAT_SIZE => 7 ;
622 8 Readonly my $STAT_CTIME => 10 ;
623  
624 8 ▶if($file->{EXISTS})
Branch: 1 branch
BranchTrueFalseTotal
if ($file->{"EXISTS"}) 6 2 8
625 {
626 6 my ($file_size, undef, undef, $modification_time) = (stat($file->{FOUND_AT}))[$STAT_SIZE..$STAT_CTIME];
627 6 my ($sec, $min, $hour, $month_day, $month, $year, $week_day, $year_day) = gmtime($modification_time) ;
628 6 $year += $YEAR_1900 ;
629 6 $month++ ;
630  
631 6 $file->{SIZE} = $file_size ;
632 $file->{DATE} =
633 {
634 6 DAY => $month_day,
635 MONTH => $month,
636 YEAR => $year,
637 HOUR => $hour,
638 MINUTE => $min,
639 SECOND => $sec,
640 };
641 }
642
643 8 return(1) ;
644 }
645  
646 #-------------------------------------------------------------------------------
647  
648 6 1 ;
649  
650 =head1 BUGS AND LIMITATIONS
651  
652 None so far.
653  
654 =head1 AUTHOR
655  
656 Khemir Nadim ibn Hamouda
657 CPAN ID: NKH
658 mailto:nadim@khemir.net
659  
660 =head1 LICENSE AND COPYRIGHT
661  
662 This program is free software; you can redistribute
663 it and/or modify it under the same terms as Perl itself.
664  
665 =head1 SUPPORT
666  
667 You can find documentation for this module with the perldoc command.
668  
669 perldoc File::Find::Repository
670  
671 You can also look for information at:
672  
673 =over 4
674  
675 =item * AnnoCPAN: Annotated CPAN documentation
676  
677 L<http://annocpan.org/dist/File-Find-Repository>
678  
679 =item * RT: CPAN's request tracker
680  
681 Please report any bugs or feature requests to L <bug-file-find-repository@rt.cpan.org>.
682  
683 We will be notified, and then you'll automatically be notified of progress on
684 your bug as we make changes.
685  
686 =item * Search CPAN
687  
688 L<http://search.cpan.org/dist/File-Find-Repository>
689  
690 =back
691  
692 =head1 SEE ALSO
693  
694 L<File::Find::Rules>
695  
696 =cut
↑ Summary