| 1 | package TestLib; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 2 | our $VERSION = '0.06'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Test::Smoke::Util qw( whereis ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 10 | &whereis | ||||||||||||||||||||||||||||
| 11 | &find_a_patch | ||||||||||||||||||||||||||||
| 12 | &find_unzip &do_unzip | ||||||||||||||||||||||||||||
| 13 | &find_untargz &do_untargz | ||||||||||||||||||||||||||||
| 14 | &manify_path | ||||||||||||||||||||||||||||
| 15 | &get_dir &get_file &put_file | ||||||||||||||||||||||||||||
| 16 | &rmtree &mkpath | ||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head1 NAME | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | TestLib - Stuff to help the test-suite | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | use TestLib; | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | What is in here? | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =over 4 | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =cut | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 2 | ▶ | use Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 2 | ▶ | use File::Find; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 2 | ▶ | use File::Spec::Functions qw( :DEFAULT abs2rel rel2abs | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 2 | splitdir splitpath catpath); | |||||||||||||||||||||||||||
| 39 | 2 | require File::Path; | |||||||||||||||||||||||||||
| 40 | 2 | ▶ | use Cwd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =item manify_path( $path ) | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | Do a OS-specific split on the path, and join with '/' for MANIFEST | ||||||||||||||||||||||||||||
| 46 | format. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =cut | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub manify_path($) { | ||||||||||||||||||||||||||
|
Subroutine
manify_path: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $path = shift or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | # There should be no volume on these file_paths | ||||||||||||||||||||||||||||
| 53 | 0 | $path = File::Spec->canonpath( $path ); | |||||||||||||||||||||||||||
| 54 | 0 | my( undef, $dirs, $file ) = File::Spec->splitpath( $path ); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | my @subdirs = grep $_ && length $_ => File::Spec->splitdir( $dirs ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$_ && length $_
MC/DC0%0/2
$_ && length $_
$_
length $_
Truth table0%0/3
A && B
A= $_B= length $_
| |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | $^O eq 'VMS' and $file =~ s/\.$//; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | push @subdirs, $file; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | return join '/', @subdirs; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =item get_dir( $path ) | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | Returns a list of filenames (no directory-names) in C<$path>. | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =cut | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub get_dir($) { | ||||||||||||||||||||||||||
|
Subroutine
get_dir: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | 0 | my( $path ) = @_; | |||||||||||||||||||||||||||
| 72 | 0 | my $cwd = cwd(); | |||||||||||||||||||||||||||
| 73 | 0 | ▶ | chdir $path or die "Cannot chdir($path): $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | my @files; | |||||||||||||||||||||||||||
| 75 | 0 | ▶ | find sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | -f or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 0 | my $cname = File::Spec->canonpath( $File::Find::name ); | |||||||||||||||||||||||||||
| 78 | 0 | push @files, $cname; | |||||||||||||||||||||||||||
| 79 | 0 | }, '.'; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | chdir $cwd or die "Cannot chdir($cwd) back: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | return @files; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =item get_file( @path ) | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | The contents of C<@path> are passed to B<< File::Spec->catfile() >> | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | Returns the contents of a file, takes note of context (scalar/list). | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =cut | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub get_file { | ||||||||||||||||||||||||||
|
Subroutine
get_file: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 0 | my $filename = File::Spec->catfile( @_ ); | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | local *MYFILE; | |||||||||||||||||||||||||||
| 97 | 0 | my @content; | |||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ( open MYFILE, "< $filename" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | @content = <MYFILE>; | |||||||||||||||||||||||||||
| 100 | 0 | close MYFILE; | |||||||||||||||||||||||||||
| 101 | } else { | ||||||||||||||||||||||||||||
| 102 | 0 | Carp::carp("(@{[cwd]})$filename: $!"); | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | return wantarray ? @content : join "", @content; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =item put_file( $content, @path ) | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | The contents of C<@path> are passed to B<< File::Spec->catfile() >> | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | Writes C<$content> to that file and returns the success/failure. | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =cut | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 4 | ▶ | sub put_file { | ||||||||||||||||||||||||||
|
Subroutine
put_file: called CC=3 SCAR=13.7
Pod
documented
| |||||||||||||||||||||||||||||
| 117 | 4 | my $contents = shift; | |||||||||||||||||||||||||||
| 118 | 4 | my $filename = File::Spec->catfile( @_ ); | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 4 | local *MYFILE; | |||||||||||||||||||||||||||
| 121 | 4 | ▶ | if ( open MYFILE, "> $filename" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 4 | print MYFILE $contents; | |||||||||||||||||||||||||||
| 123 | 4 | ▶ | close MYFILE or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | warn "Cannot close (@{[cwd]})$filename: $!"; | |||||||||||||||||||||||||||
| 125 | 0 | return; | |||||||||||||||||||||||||||
| 126 | }; | ||||||||||||||||||||||||||||
| 127 | } else { | ||||||||||||||||||||||||||||
| 128 | 0 | warn "Cannot create (@{[cwd]})$filename: $!"; | |||||||||||||||||||||||||||
| 129 | 0 | return; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 4 | return 1; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =item rmtree( @_ ) | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | This is B<< File::Path::rmtree() >>. | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =cut | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub rmtree { File::Path::rmtree( @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
rmtree: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =item mkpath( @_ ) | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | This is B<< File::Path::mkpath() >>. | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =cut | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | ▶ | sub mkpath { File::Path::mkpath( @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
mkpath: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =item find_a_patch() | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | Loop over some known names for gnu-patch and see if they know about --version. | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =cut | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | ▶ | sub find_a_patch { | ||||||||||||||||||||||||||
|
Subroutine
find_a_patch: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | my $patch_bin; | |||||||||||||||||||||||||||
| 160 | 0 | foreach my $patch (qw( gpatch npatch patch )) { | |||||||||||||||||||||||||||
| 161 | 0 | ▶ | $patch_bin = whereis( $patch ) or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 0 | ▶ | my $quoted = $patch_bin =~ /\s/ ? qq{"$patch_bin"} : $patch_bin; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 0 | my $version = `$quoted --version 2>&1`; | |||||||||||||||||||||||||||
| 164 | 0 | ▶ | $? or return $quoted; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =item find_unzip() | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | Check C<< wheris( 'gzip' ) >> or C<< eval{ require Compress::Zlib } >>. | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | =cut | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | ▶ | sub find_unzip { | ||||||||||||||||||||||||||
|
Subroutine
find_unzip: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 175 | 0 | my $unzip = whereis( 'gzip' ); | |||||||||||||||||||||||||||
| 176 | 0 | ▶ | my $qunzip = defined $unzip && $unzip =~ /\s/ ? qq{"$unzip"} : $unzip; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $unzip and $unzip =~ /\s/
MC/DC0%0/2
defined $unzip and $unzip =~ /\s/
defined $unzip
$unzip =~ /\s/
Truth table0%0/3
A and B
A= defined $unzipB= $unzip =~ /\s/
| |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 0 | ▶ | my $dounzip = $unzip ? "$qunzip -cd " : ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | ▶ | unless ( $dounzip ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | 0 | eval { require Compress::Zlib }; | |||||||||||||||||||||||||||
| 182 | 0 | ▶ | $dounzip = 'Compress::Zlib' unless $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | return $dounzip; | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | =item do_unzip( $unzip, $uzfile ) | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | Returns the gunzipped contents of C<$uzfile>. | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | =cut | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 0 | ▶ | sub do_unzip { | ||||||||||||||||||||||||||
|
Subroutine
do_unzip: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 195 | 0 | my( $unzip, $uzfile ) = @_; | |||||||||||||||||||||||||||
| 196 | 0 | ▶ | return undef unless -f $uzfile; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 0 | my $content; | |||||||||||||||||||||||||||
| 199 | 0 | ▶ | if ( $unzip eq 'Compress::Zlib' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 0 | require Compress::Zlib; | |||||||||||||||||||||||||||
| 201 | 0 | ▶ | my $unzipper = Compress::Zlib::gzopen( $uzfile, 'rb' ) or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | 0 | require Carp; | |||||||||||||||||||||||||||
| 203 | 0 | Carp::carp( "Can't open '$uzfile': $Compress::Zlib::gzerrno" ); | |||||||||||||||||||||||||||
| 204 | 0 | return undef; | |||||||||||||||||||||||||||
| 205 | }; | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 0 | my $buffer; | |||||||||||||||||||||||||||
| 208 | 0 | ▶ | $content .= $buffer while $unzipper->gzread( $buffer ) > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 0 | ▶ | unless ( $Compress::Zlib::gzerrno == Compress::Zlib::Z_STREAM_END() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | 0 | require Carp; | |||||||||||||||||||||||||||
| 212 | 0 | Carp::carp( "Error reading '$uzfile': $Compress::Zlib::gzerrno" ); | |||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 0 | $unzipper->gzclose; | |||||||||||||||||||||||||||
| 216 | } else { | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | # this calls out for `$unzip $uzfile` | ||||||||||||||||||||||||||||
| 219 | # {unzip} could be like 'zcat', 'gunzip -c', 'gzip -dc' | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 0 | $content = `$unzip $uzfile`; | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | return $content; | |||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | =item find_untargz() | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | Find either B<gzip>/B<tar> or B<Compress::Zlib>/B<Archive::Tar> | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | =cut | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 0 | ▶ | sub find_untargz { | ||||||||||||||||||||||||||
|
Subroutine
find_untargz: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||
| 235 | 0 | my $tar = whereis( 'tar' ); | |||||||||||||||||||||||||||
| 236 | 0 | ▶ | my $qtar = defined $tar && $tar =~ /\s/ ? qq{"$tar"} : $tar; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $tar and $tar =~ /\s/
MC/DC0%0/2
defined $tar and $tar =~ /\s/
defined $tar
$tar =~ /\s/
Truth table0%0/3
A and B
A= defined $tarB= $tar =~ /\s/
| |||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 0 | my $uncompress = ''; | |||||||||||||||||||||||||||
| 239 | 0 | ▶ | if ( $tar ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | 0 | my $zip = whereis( 'gzip' ); | |||||||||||||||||||||||||||
| 241 | 0 | ▶ | my $qzip = defined $zip && $zip =~ /\s/ ? qq{"$zip"} : $zip; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $zip and $zip =~ /\s/
MC/DC0%0/2
defined $zip and $zip =~ /\s/
defined $zip
$zip =~ /\s/
Truth table0%0/3
A and B
A= defined $zipB= $zip =~ /\s/
| |||||||||||||||||||||||||||||
| 242 | 0 | ▶ | $uncompress = "$qzip -cd %s | $qtar -xf -" if $zip; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 0 | ▶ | unless ( $uncompress ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | 0 | eval { require Archive::Tar; }; | |||||||||||||||||||||||||||
| 247 | 0 | ▶ | unless ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 248 | 0 | ▶ | if ( $Archive::Tar::VERSION >= 0.99 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | 0 | eval { require IO::Zlib }; | |||||||||||||||||||||||||||
| 250 | } else { | ||||||||||||||||||||||||||||
| 251 | 0 | eval { require Compress::Zlib }; | |||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | 0 | ▶ | $uncompress = 'Archive::Tar' unless $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 0 | ▶ | if ( $tar && !$uncompress ) { # try tar by it self | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$tar and not $uncompress
MC/DC0%0/2
$tar and not $uncompress
$tar
not $uncompress
Truth table0%0/3
A and not(B)
A= $tarB= not $uncompress
| |||||||||||||||||||||||||||||
| 258 | 0 | $uncompress = "$qtar -xzf %s"; | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 0 | return $uncompress; | |||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | =item do_untargz( $untargz, $tgzfile ) | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | Gunzip and extract the archive in C<$tgzfile>. | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | =cut | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 0 | ▶ | sub do_untargz { | ||||||||||||||||||||||||||
|
Subroutine
do_untargz: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 271 | 0 | my( $untgz, $tgzfile ) = @_; | |||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 0 | ▶ | if ( $untgz eq 'Archive::Tar' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 274 | 0 | require Archive::Tar; | |||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 0 | ▶ | my $archive = Archive::Tar->new() or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | 0 | warn "Can't Archive::Tar->new: " . $Archive::Tar::error; | |||||||||||||||||||||||||||
| 278 | 0 | return undef; | |||||||||||||||||||||||||||
| 279 | }; | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | 0 | $archive->read( $tgzfile, 1 ); | |||||||||||||||||||||||||||
| 282 | 0 | ▶ | $Archive::Tar::error and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 283 | 0 | warn "Error reading '$tgzfile': ".$Archive::Tar::error; | |||||||||||||||||||||||||||
| 284 | 0 | return undef; | |||||||||||||||||||||||||||
| 285 | }; | ||||||||||||||||||||||||||||
| 286 | 0 | my @files = $archive->list_files; | |||||||||||||||||||||||||||
| 287 | 0 | $archive->extract( @files ); | |||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | } else { # assume command | ||||||||||||||||||||||||||||
| 290 | 0 | ▶ | $^O eq 'VMS' and return vms_untargz( $untgz, $tgzfile ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 0 | my $command = sprintf $untgz, $tgzfile; | |||||||||||||||||||||||||||
| 293 | 0 | ▶ | $command .= " $tgzfile" if $command eq $untgz; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 0 | ▶ | if ( system $command ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | 0 | my $error = $? >> 8; | |||||||||||||||||||||||||||
| 297 | 0 | warn "Error in command: $error"; | |||||||||||||||||||||||||||
| 298 | 0 | return undef; | |||||||||||||||||||||||||||
| 299 | }; | ||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | 0 | return 1; | |||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | =item vms_untargz( $untargz, $tgzfile ) | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | Gunzip and extract the archive in C<$tgzfile>. | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | =cut | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | 0 | ▶ | sub vms_untargz { | ||||||||||||||||||||||||||
|
Subroutine
vms_untargz: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 311 | 0 | my( $cmd, $file ) = @_; | |||||||||||||||||||||||||||
| 312 | 0 | my( $vol, $path, $fname ) = splitpath( $file ); | |||||||||||||||||||||||||||
| 313 | 0 | my @parts = split /[.@#]/, $fname; | |||||||||||||||||||||||||||
| 314 | 0 | ▶ | if ( @parts > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 315 | 0 | ▶ | my $ext = ( pop @parts ) || ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
pop @parts || ''
MC/DC0%0/1
pop @parts || ''
pop @parts
Truth table0%0/2
A
A= pop @parts
| |||||||||||||||||||||||||||||
| 316 | 0 | $fname = join( "_", @parts ) . ".$ext"; | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | 0 | $file = catpath( $vol, $path, $fname ); | |||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 0 | my( $gzip_cmd, $tar_cmd ) = split /\s*\|\s*/, $cmd; | |||||||||||||||||||||||||||
| 321 | 0 | ▶ | my $gzip = $gzip_cmd =~ /^(\S+)/ ? $1 : 'GZIP'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | 0 | ▶ | my $tar = $tar_cmd =~ /^(\S+)/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
whereis("vmstar") or whereis("tar")
MC/DC0%0/2
whereis("vmstar") or whereis("tar")
whereis("vmstar")
whereis("tar")
Truth table0%0/3
A or B
A= whereis("vmstar")B= whereis("tar")
| |||||||||||||||||||||||||||||
| 323 | ? $1 : (whereis( 'vmstar' ) || whereis( 'tar' ) ); | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 0 | local *TMPCOM; | |||||||||||||||||||||||||||
| 326 | 0 | ▶ | open TMPCOM, "> TS-UNTGZ.COM" or return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 327 | 0 | ▶ | print TMPCOM <<EO_UNTGZ; close TMPCOM or return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 328 | \$ define/user sys\$output TS-UNTGZ.TAR | ||||||||||||||||||||||||||||
| 329 | \$ $gzip "-cd" $file | ||||||||||||||||||||||||||||
| 330 | \$ $tar "-xf" TS-UNTGZ.TAR | ||||||||||||||||||||||||||||
| 331 | \$ delete TS-UNTGZ.TAR;* | ||||||||||||||||||||||||||||
| 332 | EO_UNTGZ | ||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | 0 | my $ret = system "\@TS-UNTGZ.COM"; | |||||||||||||||||||||||||||
| 335 | 0 | ▶ | 1 while unlink "TS-UNTGZ.COM"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | 0 | return ! $ret; | |||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 2 | 1; | |||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | =back | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | (c) 2001-2003, All rights reserved. | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | * Abe Timmerman <abeltje@cpan.org> | ||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 351 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | See: | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | =over 4 | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | =item * L<http://www.perl.com/perl/misc/Artistic.html> | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | =item * L<http://www.gnu.org/copyleft/gpl.html> | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | =back | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||
| 364 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||
| 365 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | =cut | ||||||||||||||||||||||||||||