| 1 | package Serge::FindFiles; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | no warnings qw(uninitialized); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Config::Neat::Util qw(is_array is_neat_array); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use File::Spec::Functions qw(rel2abs catfile); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | my ($class, $self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | ▶ | $self = {} unless defined $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | # Exclude `.svn', `.git', `.hg' (Mercurial), '.bzr' (Bazaar) and `CVS' dirs (case-sensitive) from processing by default | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | ▶ | $self->{dir_exclude} = ['^(\.svn|\.git|\.hg|\.bzr|CVS)$'] unless exists $self->{dir_exclude}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 6 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 6 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | sub find { | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | ▶ | my ($self, $dir) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find: called CC=9 SCAR=27.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # Perform sanity checks | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 6 | ▶ | die "'prefix' property must be a scalar value" if exists $self->{prefix} && !(defined $self->{prefix} && (ref(\$self->{prefix}) eq 'SCALAR')); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
exists $self->{"prefix"} and not defined $self->{"prefix"} && ref \$self->{"prefix"} eq "SCALAR"
defined $self->{'prefix'} && ref \$self->{'prefix'} eq 'SCALAR'
MC/DC0%0/3
exists $self->{"prefix"} and not defined $self->{"prefix"} && ref \$self->{"prefix"} eq "SCALAR"
exists $self->{"prefix"}
defined $self->{'prefix'}
ref \$self->{'prefix'} eq 'SCALAR'
Truth table25%1/4
A and not(B && C)
A= exists $self->{"prefix"}B= defined $self->{'prefix'}C= ref \$self->{'prefix'} eq 'SCALAR'
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | ▶ | die "'postcheck_callback' property must be a code reference" if exists $self->{postcheck_callback} && (ref($self->{postcheck_callback}) ne 'CODE'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $self->{"postcheck_callback"} and ref $self->{"postcheck_callback"} ne "CODE"
MC/DC0%0/2
exists $self->{"postcheck_callback"} and ref $self->{"postcheck_callback"} ne "CODE"
exists $self->{"postcheck_callback"}
ref $self->{"postcheck_callback"} ne "CODE"
Truth table33%1/3
A and B
A= exists $self->{"postcheck_callback"}B= ref $self->{"postcheck_callback"} ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 6 | ▶ | die "'$_' property must be an array reference" if exists $self->{$_} && !(is_array($self->{$_}) || is_neat_array($self->{$_})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
exists $self->{$_} and not is_array($self->{$_}) || is_neat_array($self->{$_})
is_array($self->{$_}) || is_neat_array($self->{$_})
MC/DC0%0/3
exists $self->{$_} and not is_array($self->{$_}) || is_neat_array($self->{$_})
exists $self->{$_}
is_array($self->{$_})
is_neat_array($self->{$_})
Truth table0%0/4
A and not(B || C)
A= exists $self->{$_}B= is_array($self->{$_})C= is_neat_array($self->{$_})
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | } qw(match dir_match dir_exclude exclude); | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | # Initialize the output hash and process the dir recursively | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 6 | $self->{found_files} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 6 | $self->process_subdir(rel2abs($dir), ''); | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | sub process_subdir { | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 6 | ▶ | my ($self, $dir, $relpath) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_subdir: called CC=11 SCAR=27.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | opendir(my $dh, $dir); | |||||||||||||||||||||||||||||||||||||||||
| 43 | 6 | ▶ | while (my $name = readdir $dh) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 20 | ▶ | next if $name eq '.' || $name eq '..'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$name eq "." or $name eq ".."
MC/DC100%2/2
$name eq "." or $name eq ".."
$name eq "."
$name eq ".."
Truth table100%3/3
A or B
A= $name eq "."B= $name eq ".."
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 8 | ▶ | my $subpath = $relpath ne '' ? $relpath.'/'.$name : $name; # relative path is always delimited by a forward slash (relative paths are platform-independent) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 8 | my $fullpath = catfile($dir, $name); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 8 | my $file_rel = $self->{prefix}.$subpath; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 8 | ▶ | if (-d $fullpath) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ($self->{process_subdirs} && $self->check_path($file_rel, $name)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"process_subdirs"} and $self->check_path($file_rel, $name)
MC/DC0%0/2
$self->{"process_subdirs"} and $self->check_path($file_rel, $name)
$self->{"process_subdirs"}
$self->check_path($file_rel, $name)
Truth table0%0/3
A and B
A= $self->{"process_subdirs"}B= $self->check_path($file_rel, $name)
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $self->process_subdir($fullpath, $subpath); | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | } elsif (-f $fullpath) { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 8 | ▶ | if ($self->check_path($file_rel, $name, 1)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 8 | ▶ | if (exists $self->{postcheck_callback}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 8 | $file_rel = &{$self->{postcheck_callback}}($file_rel, $fullpath); | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 8 | $self->{found_files}->{$file_rel} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 6 | closedir $dh; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | sub check_path { | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 8 | ▶ | my ($self, $path, $name, $file_mode) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_path: called CC=21 SCAR=52.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 8 | my $ok = undef; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 8 | ▶ | if ($file_mode) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | # Test if relative file path (or file name) matches the mask | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 8 | ▶ | if (exists $self->{match}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 8 | foreach my $rule (@{$self->{match}}) { | |||||||||||||||||||||||||||||||||||||||||
| 74 | 8 | ▶ | if (($name =~ m/$rule/) || ($path =~ m/$rule/)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$name =~ /$rule/ or $path =~ /$rule/
MC/DC0%0/2
$name =~ /$rule/ or $path =~ /$rule/
$name =~ /$rule/
$path =~ /$rule/
Truth table33%1/3
A or B
A= $name =~ /$rule/B= $path =~ /$rule/
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 8 | $ok = 1; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 8 | last; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | # If 'match' not provided, gather all files | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | $ok = 1; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | # Test if relative directory path (or directory name) matches the mask | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if (exists $self->{dir_match}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | foreach my $rule (@{$self->{dir_match}}) { | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if (($name =~ m/$rule/) || ($path =~ m/$rule/)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$name =~ /$rule/ or $path =~ /$rule/
MC/DC0%0/2
$name =~ /$rule/ or $path =~ /$rule/
$name =~ /$rule/
$path =~ /$rule/
Truth table0%0/3
A or B
A= $name =~ /$rule/B= $path =~ /$rule/
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $ok = 1; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 93 | # If 'dir_match' not provided, go through all directories | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $ok = 1; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | ▶ | if (!$file_mode) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | # Test if relative directory path (or directory name) does not match the directory-specific exclusion mask | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ($ok && exists $self->{dir_exclude}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ok and exists $self->{"dir_exclude"}
MC/DC0%0/2
$ok and exists $self->{"dir_exclude"}
$ok
exists $self->{"dir_exclude"}
Truth table0%0/3
A and B
A= $okB= exists $self->{"dir_exclude"}
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | foreach my $rule (@{$self->{dir_exclude}}) { | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if (($name =~ m/$rule/) || ($path =~ m/$rule/)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$name =~ /$rule/ or $path =~ /$rule/
MC/DC0%0/2
$name =~ /$rule/ or $path =~ /$rule/
$name =~ /$rule/
$path =~ /$rule/
Truth table0%0/3
A or B
A= $name =~ /$rule/B= $path =~ /$rule/
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $ok = undef; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | # Test if relative file/directory path (or file/directory name) does not match the exclusion mask | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 8 | ▶ | if ($ok && exists $self->{exclude}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ok and exists $self->{"exclude"}
MC/DC0%0/2
$ok and exists $self->{"exclude"}
$ok
exists $self->{"exclude"}
Truth table33%1/3
A and B
A= $okB= exists $self->{"exclude"}
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | foreach my $rule (@{$self->{exclude}}) { | |||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if (($name =~ m/$rule/) || ($path =~ m/$rule/)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$name =~ /$rule/ or $path =~ /$rule/
MC/DC0%0/2
$name =~ /$rule/ or $path =~ /$rule/
$name =~ /$rule/
$path =~ /$rule/
Truth table0%0/3
A or B
A= $name =~ /$rule/B= $path =~ /$rule/
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $ok = undef; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 8 | return $ok; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||