| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$o->{"minsize"} or $o->{"maxsize"}
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"}
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$f or $o->{"callback"}
MC/DC0%0/2
$f or $o->{"callback"}
$f
$o->{"callback"}
Truth table0%0/3
A or B
A= $fB= $o->{"callback"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$file eq "." or $file eq ".."
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 ".."
| |||||||||||||||||||||||||||||
| 70 | 0 | next; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ($o->{rejfile} && $file =~ $o->{rejfile}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$o->{"rejfile"} and $file =~ /$o->{"rejfile"}/
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"}/
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if ($o->{verbose}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 80 | 0 | print "$dir $file\n"; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 0 | my $is_dir = 0; | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | if (-d $dfile) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if (! $o->{no_trav} || $dfile !~ $o->{no_trav}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$o->{"no_trav"} and $dfile =~ /$o->{"no_trav"}/
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"}/
| |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if (-l $dfile) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | # Skip symbolic links | ||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ($o->{verbose}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 95 | 0 | next; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 0 | $is_dir = 1; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if (-l $dfile) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | # Skip symbolic links | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ($o->{verbose}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | print "Skipping symbolic link '$dfile'.\n"; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | 0 | next; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if (! $is_dir && $o->{size}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $is_dir and $o->{"size"}
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"}
| |||||||||||||||||||||||||||||
| 107 | 0 | my $size = -s $dfile; | |||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ($size > $o->{maxsize} || $size < $o->{minsize}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$size > $o->{"maxsize"} or $size < $o->{"minsize"}
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"}
| |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if ($o->{verbose}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
not $o->{"only"} or $file =~ /$o->{"only"}/
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"}/
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 125 | 0 | push @$f, $dfile; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ($o->{callback}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | &{$o->{callback}} ($o->{data}, $dfile); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 1 | 1; | |||||||||||||||||||||||||||