Dir.pm

filter: Statementstmt 17.0% 14 / 82 Branchbran 0.0% 0 / 44 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 50.0% 4 / 8 Podpod 50.0% 2 / 4 totaltotal 11.2% 20 / 178 CC 34 SCAR 62.2
CC
34
Cov
9%
find_files
756.0
new
30.0
save
12.0
CRAP 502.8
↑ Summary versionup.pl »
1 package Trav::Dir;
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 our $VERSION = '0.02';
7  
8 sub op
9 0 ▶{
Subroutine op: not called CC=2 SCAR=17.9
Pod undocumented
10 0 my ($o, $options, $name) = @_;
11 0 ▶ if ($options->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{$name}) 0 0 0
12 0 $o->{$name} = $options->{$name};
13 0 delete $options->{$name};
14 }
15 }
16  
17 sub new
18 0 ▶{
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
19 0 my ($class, %op) = @_;
20 0 my $o = {};
21 0 $o->{minsize} = 0;
22 0 $o->{maxsize} = 'inf';
23 0 for my $name (qw!
24 verbose
25  
26 callback
27 data
28 maxsize
29 minsize
30 no_dir
31 no_trav
32 only
33 preprocess
34 rejfile
35 !) {
36 0 op ($o, \%op, $name);
37 }
38 # $o->{size} is a flag which tells find_files whether to check the
39 # size.
40 0 ▶ if ($o->{minsize} || $o->{maxsize}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"minsize"} or $o->{"maxsize"}) 0 0 0
Condition0%0/3
$o->{"minsize"} or $o->{"maxsize"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->{"minsize"} or $o->{"maxsize"}
$o->{"minsize"} $o->{"maxsize"}
Truth table0%0/3
A or B
A= $o->{"minsize"}B= $o->{"maxsize"}
ABresult
1X1
011
000
41 0 $o->{size} = 1;
42 }
43 0 for my $k (keys %op) {
44 0 carp "Unknown option $k";
45 0 delete $op{$k};
46 }
47 0 bless $o, $class;
48 }
49  
50 sub find_files
51 0 ▶{
Subroutine find_files: not called CC=27 SCAR=66.3
Pod documented
52 0 my ($o, $dir, $f) = @_;
53 0 ▶ if (! $f && ! $o->{callback}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($f or $o->{"callback"}) 0 0 0
Condition0%0/3
$f or $o->{"callback"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$f or $o->{"callback"}
$f $o->{"callback"}
Truth table0%0/3
A or B
A= $fB= $o->{"callback"}
ABresult
1X1
011
000
54 # There is no work for us to do
55 0 carp "No file list and no callback";
56 0 return;
57 }
58 0 my $dh;
59 0 ▶ if (! opendir ($dh, $dir)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (opendir $dh, $dir) 0 0 0
60 0 warn "opendir $dir failed: $!";
61 0 return;
62 }
63 0 my @files = readdir ($dh);
64 0 closedir ($dh);
65 0 ▶ if ($o->{preprocess}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"preprocess"}) 0 0 0
66 0 &{$o->{preprocess}} ($o->{data}, $dir, \@files);
67 }
68 0 for my $file (@files) {
69 0 ▶ if ($file eq '.' || $file eq '..') {
Branch: 1 branch
BranchTrueFalseTotal
if ($file eq "." or $file eq "..") 0 0 0
Condition0%0/3
$file eq "." or $file eq ".."
l!l&&r!l&&!r
000
MC/DC0%0/2
$file eq "." or $file eq ".."
$file eq "." $file eq ".."
Truth table0%0/3
A or B
A= $file eq "."B= $file eq ".."
ABresult
1X1
011
000
70 0 next;
71 }
72 0 ▶ if ($o->{rejfile} && $file =~ $o->{rejfile}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"rejfile"} and $file =~ /$o->{"rejfile"}/) 0 0 0
Condition0%0/3
$o->{"rejfile"} and $file =~ /$o->{"rejfile"}/
!ll&&!rl&&r
000
MC/DC0%0/2
$o->{"rejfile"} and $file =~ /$o->{"rejfile"}/
$o->{"rejfile"} $file =~ /$o->{"rejfile"}/
Truth table0%0/3
A and B
A= $o->{"rejfile"}B= $file =~ /$o->{"rejfile"}/
ABresult
0X0
100
111
73 0 ▶ if ($o->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"verbose"}) 0 0 0
74 0 print "Skipping $file\n";
75 }
76 0 next;
77 }
78 0 my $dfile = "$dir/$file";
79 0 ▶ if ($o->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"verbose"}) 0 0 0
80 0 print "$dir $file\n";
81 }
82 0 my $is_dir = 0;
83 0 ▶ if (-d $dfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $dfile) 0 0 0
84 0 ▶ if (! $o->{no_trav} || $dfile !~ $o->{no_trav}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($o->{"no_trav"} and $dfile =~ /$o->{"no_trav"}/) 0 0 0
Condition0%0/3
$o->{"no_trav"} and $dfile =~ /$o->{"no_trav"}/
!ll&&!rl&&r
000
MC/DC0%0/2
$o->{"no_trav"} and $dfile =~ /$o->{"no_trav"}/
$o->{"no_trav"} $dfile =~ /$o->{"no_trav"}/
Truth table0%0/3
A and B
A= $o->{"no_trav"}B= $dfile =~ /$o->{"no_trav"}/
ABresult
0X0
100
111
85 0 ▶ if (-l $dfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-l $dfile) 0 0 0
86 # Skip symbolic links
87 0 ▶ if ($o->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"verbose"}) 0 0 0
88 0 print "Skipping symbolic link '$dfile'.\n";
89 }
90 0 next;
91 }
92 0 find_files ($o, $dfile, $f);
93 }
94 0 ▶ if ($o->{no_dir}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"no_dir"}) 0 0 0
95 0 next;
96 }
97 0 $is_dir = 1;
98 }
99 0 ▶ if (-l $dfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-l $dfile) 0 0 0
100 # Skip symbolic links
101 0 ▶ if ($o->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"verbose"}) 0 0 0
102 0 print "Skipping symbolic link '$dfile'.\n";
103 }
104 0 next;
105 }
106 0 ▶ if (! $is_dir && $o->{size}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_dir and $o->{"size"}) 0 0 0
Condition0%0/3
not $is_dir and $o->{"size"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $is_dir and $o->{"size"}
not $is_dir $o->{"size"}
Truth table0%0/3
not(A) and B
A= not $is_dirB= $o->{"size"}
ABresult
0X0
100
111
107 0 my $size = -s $dfile;
108 0 ▶ if ($size > $o->{maxsize} || $size < $o->{minsize}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size > $o->{"maxsize"} or $size < $o->{"minsize"}) 0 0 0
Condition0%0/3
$size > $o->{"maxsize"} or $size < $o->{"minsize"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$size > $o->{"maxsize"} or $size < $o->{"minsize"}
$size > $o->{"maxsize"} $size < $o->{"minsize"}
Truth table0%0/3
A or B
A= $size > $o->{"maxsize"}B= $size < $o->{"minsize"}
ABresult
1X1
011
000
109 0 ▶ if ($o->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"verbose"}) 0 0 0
110 0 print "Skipping $file due to size $size > $o->{maxsize} or < $o->{minsize}\n";
111 }
112 0 next;
113 }
114 }
115 0 ▶ if (! $o->{only} || $file =~ $o->{only}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $o->{"only"} or $file =~ /$o->{"only"}/) 0 0 0
Condition0%0/3
not $o->{"only"} or $file =~ /$o->{"only"}/
l!l&&r!l&&!r
000
MC/DC0%0/2
not $o->{"only"} or $file =~ /$o->{"only"}/
not $o->{"only"} $file =~ /$o->{"only"}/
Truth table0%0/3
not(A) or B
A= not $o->{"only"}B= $file =~ /$o->{"only"}/
ABresult
1X1
011
000
116 0 $o->save ($dfile, $f);
117 }
118 }
119 }
120  
121 sub save
122 0 ▶{
Subroutine save: not called CC=3 SCAR=24.8
Pod undocumented
123 0 my ($o, $dfile, $f) = @_;
124 0 ▶ if ($f) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f) 0 0 0
125 0 push @$f, $dfile;
126 }
127 0 ▶ if ($o->{callback}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"callback"}) 0 0 0
128 0 &{$o->{callback}} ($o->{data}, $dfile);
129 }
130 }
131  
132 1 1;
↑ Summary versionup.pl »