| 1 | package File::DistDir; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Cwd qw(abs_path getcwd); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use File::Basename qw(basename dirname); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use File::Copy (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use File::Path qw(make_path); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use File::ShareDir qw(dist_dir); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use ExtUtils::Installed; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use Module::Metadata; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 4 | our $VERSION = '1.0.1'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | ######################################################################## | ||||||||||||||||||||||||||||
| 19 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | ######################################################################## | ||||||||||||||||||||||||||||
| 21 | 6 | my ( $class, %args ) = @_; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 6 | my $distribution = $args{distribution}; | |||||||||||||||||||||||||||
| 24 | 6 | my $module = $args{module}; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 6 | ▶ | die "ERROR: specify either distribution or module, not both\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $distribution and defined $module
MC/DC0%0/2
defined $distribution and defined $module
defined $distribution
defined $module
Truth table66%2/3
A and B
A= defined $distributionB= defined $module
| |||||||||||||||||||||||||||||
| 27 | if defined $distribution && defined $module; | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 6 | ▶ | if ( defined $module ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 3 | ▶ | die "ERROR: module is required\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | if !length $module; | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 3 | $distribution = _distribution_for_module($module); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 6 | ▶ | die "ERROR: distribution or module is required\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $distribution and length $distribution
MC/DC0%0/2
defined $distribution and length $distribution
defined $distribution
length $distribution
Truth table33%1/3
A and B
A= defined $distributionB= length $distribution
| |||||||||||||||||||||||||||||
| 37 | if !defined $distribution || !length $distribution; | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 6 | my $root = abs_path( dist_dir($distribution) ); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 6 | ▶ | die sprintf "ERROR: distribution share directory not found: %s\n", $distribution | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $root and -d $root
MC/DC0%0/2
defined $root and -d $root
defined $root
-d $root
Truth table33%1/3
A and B
A= defined $rootB= -d $root
| |||||||||||||||||||||||||||||
| 42 | if !defined $root || !-d $root; | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 6 | return bless { | |||||||||||||||||||||||||||
| 45 | distribution => $distribution, | ||||||||||||||||||||||||||||
| 46 | dir => $root, | ||||||||||||||||||||||||||||
| 47 | }, $class; | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | ######################################################################## | ||||||||||||||||||||||||||||
| 51 | 3 | ▶ | sub _distribution_for_module { | ||||||||||||||||||||||||||
|
Subroutine
_distribution_for_module: called CC=13 SCAR=26.7
| |||||||||||||||||||||||||||||
| 52 | ######################################################################## | ||||||||||||||||||||||||||||
| 53 | 3 | my ($module) = @_; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 3 | ▶ | die sprintf "ERROR: invalid module name: %s\n", $module | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | if $module !~ /\A[A-Za-z_]\w*(?:::[A-Za-z_]\w*)*\z/; | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | # Most packages share their name with the distribution that contains them. | ||||||||||||||||||||||||||||
| 59 | # Try that cheap lookup before inspecting installed .packlist files. | ||||||||||||||||||||||||||||
| 60 | 3 | my $candidate = $module; | |||||||||||||||||||||||||||
| 61 | 3 | $candidate =~ s/::/-/g; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 3 | my $share_dir = eval { dist_dir($candidate) }; | |||||||||||||||||||||||||||
| 64 | 3 | ▶ | return $candidate | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $share_dir and -d $share_dir
MC/DC50%1/2
defined $share_dir and -d $share_dir
defined $share_dir
-d $share_dir
Truth table66%2/3
A and B
A= defined $share_dirB= -d $share_dir
| |||||||||||||||||||||||||||||
| 65 | if defined $share_dir && -d $share_dir; | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 2 | my $metadata = Module::Metadata->new_from_module($module); | |||||||||||||||||||||||||||
| 68 | 2 | ▶ | die sprintf "ERROR: module not installed: %s\n", $module | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | if !$metadata; | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 2 | my $filename = abs_path( $metadata->filename ); | |||||||||||||||||||||||||||
| 72 | 2 | ▶ | die sprintf "ERROR: cannot locate installed module file: %s\n", $module | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | if !defined $filename; | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2 | my $installed = ExtUtils::Installed->new(); | |||||||||||||||||||||||||||
| 76 | 2 | my @owners; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 2 | foreach my $owner ( $installed->modules ) { | |||||||||||||||||||||||||||
| 79 | 2 | my $packlist = $installed->packlist($owner); | |||||||||||||||||||||||||||
| 80 | 2 | ▶ | next if !$packlist; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 2 | foreach my $file ( keys %{$packlist} ) { | |||||||||||||||||||||||||||
| 83 | 2 | my $installed_file = abs_path($file); | |||||||||||||||||||||||||||
| 84 | 2 | ▶ | next if !defined $installed_file || $installed_file ne $filename; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $installed_file or $installed_file ne $filename
MC/DC0%0/2
not defined $installed_file or $installed_file ne $filename
not defined $installed_file
$installed_file ne $filename
Truth table33%1/3
not(A) or B
A= not defined $installed_fileB= $installed_file ne $filename
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 2 | push @owners, $owner; | |||||||||||||||||||||||||||
| 87 | 2 | last; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 2 | ▶ | die sprintf "ERROR: cannot determine installed distribution for module %s; use distribution => NAME\n", $module | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | if !@owners; | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 2 | ▶ | die sprintf "ERROR: ambiguous distribution ownership for module %s: %s\n", $module, join( ', ', sort @owners ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | if @owners > 1; | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 2 | my $distribution = $owners[0]; | |||||||||||||||||||||||||||
| 98 | 2 | $distribution =~ s/::/-/g; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 2 | return $distribution; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | ######################################################################## | ||||||||||||||||||||||||||||
| 104 | 111 | ▶ | sub dir { | ||||||||||||||||||||||||||
|
Subroutine
dir: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | ######################################################################## | ||||||||||||||||||||||||||||
| 106 | 111 | my ($self) = @_; | |||||||||||||||||||||||||||
| 107 | 111 | return $self->{dir}; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | ######################################################################## | ||||||||||||||||||||||||||||
| 111 | 10 | ▶ | sub path { | ||||||||||||||||||||||||||
|
Subroutine
path: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | ######################################################################## | ||||||||||||||||||||||||||||
| 113 | 10 | my ( $self, $relative ) = @_; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 10 | ▶ | $relative //= q{.}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$relative //= "."
MC/DC0%0/1
$relative //= "."
$relative
Truth table50%1/2
A
A= $relative
| |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 10 | ▶ | die "ERROR: source must be relative to the distribution directory\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | if File::Spec->file_name_is_absolute($relative); | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 10 | my $root = $self->dir; | |||||||||||||||||||||||||||
| 121 | 10 | my $candidate = File::Spec->catfile( $root, $relative ); | |||||||||||||||||||||||||||
| 122 | 10 | my $resolved = abs_path($candidate); | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 10 | ▶ | die sprintf "ERROR: source not found: %s\n", $relative | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | if !defined $resolved; | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 10 | ▶ | die sprintf "ERROR: source is outside distribution directory: %s\n", $relative | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$resolved ne $root and index($resolved, $root . '/') != 0
MC/DC100%2/2
$resolved ne $root and index($resolved, $root . '/') != 0
$resolved ne $root
index($resolved, $root . '/') != 0
Truth table100%3/3
A and B
A= $resolved ne $rootB= index($resolved, $root . '/') != 0
| |||||||||||||||||||||||||||||
| 128 | if $resolved ne $root && index( $resolved, $root . q{/} ) != 0; | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 9 | return $resolved; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | ######################################################################## | ||||||||||||||||||||||||||||
| 134 | 9 | ▶ | sub copy { | ||||||||||||||||||||||||||
|
Subroutine
copy: called CC=17 SCAR=29.6
Pod
documented
| |||||||||||||||||||||||||||||
| 135 | ######################################################################## | ||||||||||||||||||||||||||||
| 136 | 9 | my ( $self, $source, $destination, %options ) = @_; | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 9 | ▶ | die "ERROR: copy requires a source\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | if !defined $source; | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 9 | ▶ | die "ERROR: destination is required for file copying\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $destination and $source ne "."
MC/DC0%0/2
not defined $destination and $source ne "."
not defined $destination
$source ne "."
Truth table66%2/3
not(A) and B
A= not defined $destinationB= $source ne "."
| |||||||||||||||||||||||||||||
| 142 | if !defined $destination && $source ne q{.}; | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 9 | ▶ | $destination //= q{.}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$destination //= "."
MC/DC100%1/1
$destination //= "."
$destination
Truth table100%2/2
A
A= $destination
| |||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 9 | my $source_path = File::Spec->catfile( $self->dir, $source ); | |||||||||||||||||||||||||||
| 147 | 9 | _reject_symlink_components($source_path); | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 8 | my $resolved = $self->path($source); | |||||||||||||||||||||||||||
| 150 | 8 | _reject_symlink_components($destination); | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 7 | ▶ | if ( -d $resolved ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | die "ERROR: copying directories requires recursive => 1\n" | ||||||||||||||||||||||||||||
| 154 | 6 | ▶ | if !$options{recursive}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 5 | ▶ | die sprintf "ERROR: destination is not a directory: %s\n", $destination | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-e $destination and not -d $destination
MC/DC0%0/2
-e $destination and not -d $destination
-e $destination
not -d $destination
Truth table66%2/3
A and not(B)
A= -e $destinationB= not -d $destination
| |||||||||||||||||||||||||||||
| 157 | if -e $destination && !-d $destination; | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 5 | my $dest_abs = File::Spec->rel2abs($destination); | |||||||||||||||||||||||||||
| 160 | 5 | my $dest_existing = abs_path($destination); | |||||||||||||||||||||||||||
| 161 | 5 | ▶ | if ( defined $dest_existing ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 5 | $dest_abs = $dest_existing; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 5 | ▶ | die sprintf "ERROR: destination is inside source directory: %s\n", $destination | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$dest_abs eq $resolved or index($dest_abs, $resolved . '/') == 0
MC/DC50%1/2
$dest_abs eq $resolved or index($dest_abs, $resolved . '/') == 0
$dest_abs eq $resolved
index($dest_abs, $resolved . '/') == 0
Truth table66%2/3
A or B
A= $dest_abs eq $resolvedB= index($dest_abs, $resolved . '/') == 0
| |||||||||||||||||||||||||||||
| 166 | if $dest_abs eq $resolved || index( $dest_abs, $resolved . q{/} ) == 0; | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 4 | ▶ | make_path($destination) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | if !-d $destination; | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 4 | _copy_directory_contents( $resolved, $destination ); | |||||||||||||||||||||||||||
| 172 | 3 | return 1; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 1 | ▶ | die sprintf "ERROR: source is not a regular file: %s\n", $source | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | if !-f $resolved; | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 1 | ▶ | if ( -d $destination ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 0 | $destination = File::Spec->catfile( $destination, basename($source) ); | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 1 | ▶ | die sprintf "ERROR: destination directory does not exist: %s\n", dirname($destination) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | if !-d dirname($destination); | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 1 | ▶ | die sprintf "ERROR: unable to copy %s => %s: %s\n", $resolved, $destination, $OS_ERROR | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | if !File::Copy::copy( $resolved, $destination ); | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 1 | return 1; | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | ######################################################################## | ||||||||||||||||||||||||||||
| 192 | 11 | ▶ | sub list { | ||||||||||||||||||||||||||
|
Subroutine
list: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 193 | ######################################################################## | ||||||||||||||||||||||||||||
| 194 | 11 | my ($self) = @_; | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 11 | my @files; | |||||||||||||||||||||||||||
| 197 | 11 | _collect_entries( $self->dir, q{}, \@files ); | |||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 11 | return @files; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | ######################################################################## | ||||||||||||||||||||||||||||
| 203 | 12 | ▶ | sub find { | ||||||||||||||||||||||||||
|
Subroutine
find: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 204 | ######################################################################## | ||||||||||||||||||||||||||||
| 205 | 12 | my ( $self, $pattern ) = @_; | |||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 12 | ▶ | die "ERROR: find requires a filename pattern\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $pattern and length $pattern
MC/DC50%1/2
defined $pattern and length $pattern
defined $pattern
length $pattern
Truth table66%2/3
A and B
A= defined $patternB= length $pattern
| |||||||||||||||||||||||||||||
| 208 | if !defined $pattern || !length $pattern; | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | # A pattern containing a slash matches a path relative to the share | ||||||||||||||||||||||||||||
| 211 | # directory; otherwise it matches the basename at any depth. | ||||||||||||||||||||||||||||
| 212 | 10 | my $expression = quotemeta($pattern); | |||||||||||||||||||||||||||
| 213 | 10 | $expression =~ s/\\\*/.*/g; | |||||||||||||||||||||||||||
| 214 | 10 | $expression =~ s/\\\?/./g; | |||||||||||||||||||||||||||
| 215 | 10 | my $regex = qr/\A$expression\z/; | |||||||||||||||||||||||||||
| 216 | 10 | my $match_path = index( $pattern, q{/} ) >= 0; | |||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 10 | my @matches; | |||||||||||||||||||||||||||
| 219 | 10 | foreach my $relative ( $self->list ) { | |||||||||||||||||||||||||||
| 220 | 80 | my $full = File::Spec->catfile( $self->dir, $relative ); | |||||||||||||||||||||||||||
| 221 | 80 | ▶ | next if !-f $full || -l $full; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not -f $full or -l $full
MC/DC50%1/2
not -f $full or -l $full
not -f $full
-l $full
Truth table66%2/3
not(A) or B
A= not -f $fullB= -l $full
| |||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 40 | ▶ | my $target = $match_path ? $relative : basename($relative); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 224 | 40 | ▶ | push @matches, $relative | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | if $target =~ $regex; | ||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 10 | return @matches; | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | ######################################################################## | ||||||||||||||||||||||||||||
| 232 | 42 | ▶ | sub _collect_entries { | ||||||||||||||||||||||||||
|
Subroutine
_collect_entries: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 233 | ######################################################################## | ||||||||||||||||||||||||||||
| 234 | 42 | my ( $root, $prefix, $result ) = @_; | |||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 42 | ▶ | opendir my $dh, $root | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | or die sprintf "ERROR: cannot open directory %s: %s\n", $root, $OS_ERROR; | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 42 | ▶ | my @entries = sort grep { $_ ne q{.} && $_ ne q{..} } readdir $dh; | ||||||||||||||||||||||||||
|
Condition100%3/3
$_ ne '.' && $_ ne '..'
MC/DC100%2/2
$_ ne '.' && $_ ne '..'
$_ ne '.'
$_ ne '..'
Truth table100%3/3
A && B
A= $_ ne '.'B= $_ ne '..'
| |||||||||||||||||||||||||||||
| 240 | 42 | closedir $dh; | |||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 42 | foreach my $entry (@entries) { | |||||||||||||||||||||||||||
| 243 | 83 | ▶ | my $relative = length $prefix ? File::Spec->catfile( $prefix, $entry ) : $entry; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | 83 | my $full = File::Spec->catfile( $root, $entry ); | |||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 83 | push @{$result}, $relative; | |||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 83 | ▶ | if ( -d $full && !-l $full ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
-d $full and not -l $full
MC/DC100%2/2
-d $full and not -l $full
-d $full
not -l $full
Truth table100%3/3
A and not(B)
A= -d $fullB= not -l $full
| |||||||||||||||||||||||||||||
| 249 | 31 | _collect_entries( $full, $relative, $result ); | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 42 | return; | |||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | ######################################################################## | ||||||||||||||||||||||||||||
| 257 | 28 | ▶ | sub _reject_symlink_components { | ||||||||||||||||||||||||||
|
Subroutine
_reject_symlink_components: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 258 | ######################################################################## | ||||||||||||||||||||||||||||
| 259 | 28 | my ($path) = @_; | |||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | # Preserve explicit .. components while inspecting the actual path walked | ||||||||||||||||||||||||||||
| 262 | # by the filesystem. rel2abs() would normalize them prematurely. | ||||||||||||||||||||||||||||
| 263 | 28 | ▶ | my $absolute | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | = File::Spec->file_name_is_absolute($path) | ||||||||||||||||||||||||||||
| 265 | ? $path | ||||||||||||||||||||||||||||
| 266 | : File::Spec->catfile( getcwd(), $path ); | ||||||||||||||||||||||||||||
| 267 | 28 | my $current = File::Spec->rootdir; | |||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 28 | foreach my $part ( File::Spec->splitdir($absolute) ) { | |||||||||||||||||||||||||||
| 270 | 139 | ▶ | next if !length $part || $part eq q{.}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not length $part or $part eq "."
MC/DC100%2/2
not length $part or $part eq "."
not length $part
$part eq "."
Truth table100%3/3
not(A) or B
A= not length $partB= $part eq "."
| |||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 106 | $current = File::Spec->catdir( $current, $part ); | |||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 106 | ▶ | die sprintf "ERROR: symbolic links are not supported: %s\n", $current | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | if -l $current; | ||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 26 | return; | |||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | ######################################################################## | ||||||||||||||||||||||||||||
| 282 | 7 | ▶ | sub _copy_directory_contents { | ||||||||||||||||||||||||||
|
Subroutine
_copy_directory_contents: called CC=11 SCAR=24.6
| |||||||||||||||||||||||||||||
| 283 | ######################################################################## | ||||||||||||||||||||||||||||
| 284 | 7 | my ( $source, $destination ) = @_; | |||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 7 | ▶ | opendir my $dh, $source | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | or die sprintf "ERROR: cannot open directory %s: %s\n", $source, $OS_ERROR; | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 7 | ▶ | my @entries = grep { $_ ne q{.} && $_ ne q{..} } readdir $dh; | ||||||||||||||||||||||||||
|
Condition100%3/3
$_ ne '.' && $_ ne '..'
MC/DC100%2/2
$_ ne '.' && $_ ne '..'
$_ ne '.'
$_ ne '..'
Truth table100%3/3
A && B
A= $_ ne '.'B= $_ ne '..'
| |||||||||||||||||||||||||||||
| 290 | 7 | closedir $dh; | |||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 7 | foreach my $entry (@entries) { | |||||||||||||||||||||||||||
| 293 | 11 | my $from = File::Spec->catfile( $source, $entry ); | |||||||||||||||||||||||||||
| 294 | 11 | my $to = File::Spec->catfile( $destination, $entry ); | |||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | 11 | _reject_symlink_components($to); | |||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | 11 | ▶ | die sprintf "ERROR: symbolic links are not supported: %s\n", $from | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 299 | if -l $from; | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | 10 | ▶ | if ( -d $from ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 302 | 3 | ▶ | die sprintf "ERROR: destination is not a directory: %s\n", $to | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-e $to and not -d $to
MC/DC0%0/2
-e $to and not -d $to
-e $to
not -d $to
Truth table33%1/3
A and not(B)
A= -e $toB= not -d $to
| |||||||||||||||||||||||||||||
| 303 | if -e $to && !-d $to; | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | 3 | ▶ | make_path($to) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 306 | if !-d $to; | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | 3 | _copy_directory_contents( $from, $to ); | |||||||||||||||||||||||||||
| 309 | 3 | next; | |||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | 7 | ▶ | die sprintf "ERROR: unsupported resource type: %s\n", $from | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | if !-f $from; | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | 7 | ▶ | die sprintf "ERROR: unable to copy %s => %s: %s\n", $from, $to, $OS_ERROR | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 316 | if !File::Copy::copy( $from, $to ); | ||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 6 | return; | |||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 4 | 1; | |||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | __END__ | ||||||||||||||||||||||||||||