blib/lib/Alien/Build/Util.pm

filter: Statementstmt 87.5% 70 / 80 Branchbran 64.0% 32 / 50 Conditioncond 63.6% 7 / 11 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 13 / 13 Podpod n/a totaltotal 78.1% 125 / 160 CC 30 SCAR 33.0
CC
30
Cov
77%
__ANON__
44.2
_has_ssl
3.0
_dump
2.3
CRAP 27.0
« blib/lib/Alien/Build/Plugin/PkgConfig/CommandLine.pm ↑ Summary blib/lib/Alien/Build/Plugin/Digest/SHAPP.pm »
1 package Alien::Build::Util;
2  
3 71 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 71 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 71 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 71 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 71 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 71 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # ABSTRACT: Private utility functions for Alien::Build
11 71 our $VERSION = '2.88'; # VERSION
12  
13  
14 71 our @EXPORT_OK = qw( _mirror _dump _destdir_prefix _perl_config _ssl_reqs _has_ssl );
15  
16 # usage: _mirror $source_directory, $dest_direction, \%options
17 #
18 # options:
19 # - filter -> regex for files that should match
20 # - empty_directory -> if true, create all directories, including empty ones.
21 # - verbose -> turn on verbosity
22  
23 sub _mirror
24 49 ▶{
Subroutine _mirror: called CC=2 SCAR=7.3
25 49 my($src_root, $dst_root, $opt) = @_;
26 49 ($src_root, $dst_root) = map { path($_) } ($src_root, $dst_root);
27 49 ▶ $opt ||= {};
Condition100%2/2
$opt ||= {}
l!l
1732
MC/DC100%1/1
$opt ||= {}
$opt
Truth table100%2/2
A
A= $opt
Aresult
11
00
28  
29 49 require Alien::Build;
30 49 require File::Find;
31 49 require File::Copy;
32  
33 File::Find::find({
34 299 ▶ wanted => sub {
Subroutine __ANON__: called CC=25 SCAR=37.9
35 299 ▶ next unless -e $File::Find::name;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $File::Find::name 0 299 299
36 299 my $src = path($File::Find::name)->relative($src_root);
37 299 ▶ return if $opt->{filter} && "$src" !~ $opt->{filter};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"filter"} and not "$src" =~ /$opt->{"filter"}/ 26 273 299
Condition100%3/3
$opt->{"filter"} and not "$src" =~ /$opt->{"filter"}/
!ll&&!rl&&r
265826
MC/DC100%2/2
$opt->{"filter"} and not "$src" =~ /$opt->{"filter"}/
$opt->{"filter"} not "$src" =~ /$opt->{"filter"}/
Truth table100%3/3
A and not(B)
A= $opt->{"filter"}B= not "$src" =~ /$opt->{"filter"}/
ABresult
0X0
100
111
38 273 ▶ return if "$src" eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if "$src" eq "." 45 228 273
39 228 my $dst = $dst_root->child("$src");
40 228 $src = $src->absolute($src_root);
41 228 ▶ if(-l "$src")
Branch: 3 branches
BranchTrueFalseTotal
if (-l "$src") { } 3 225 228
elsif (-d "$src") { } 85 140 225
elsif (-f "$src") { } 140 0 140
42 {
43 3 ▶ unless(-d $dst->parent)
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dst->parent) 0 3 3
44 {
45 0 ▶ Alien::Build->log("mkdir -p @{[ $dst->parent ]}") if $opt->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"verbose"} 0 0 0
46 0 $dst->parent->mkpath;
47 }
48 # TODO: rmtree if a directory?
49 3 ▶ if(-e "$dst")
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$dst") 0 3 3
50 0 { unlink "$dst" }
51 3 my $target = readlink "$src";
52 3 ▶ Alien::Build->log("ln -s $target $dst") if $opt->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"verbose"} 0 3 3
53 3 ▶ symlink($target, $dst) || die "unable to symlink $target => $dst";
Branch: 1 branch
BranchTrueFalseTotal
symlink $target, $dst or die "unable to symlink $target => $dst" 3 0 3
54 }
55 elsif(-d "$src")
56 {
57 85 ▶ if($opt->{empty_directory})
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"empty_directory"}) 9 76 85
58 {
59 9 ▶ unless(-d $dst)
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dst) 9 0 9
60 {
61 9 ▶ Alien::Build->log("mkdir $dst") if $opt->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"verbose"} 0 9 9
62 9 ▶ mkdir($dst) || die "unable to create directory $dst: $!";
Branch: 1 branch
BranchTrueFalseTotal
mkdir $dst or die "unable to create directory ${dst}: $!" 9 0 9
63 }
64 }
65 }
66 elsif(-f "$src")
67 {
68 140 ▶ unless(-d $dst->parent)
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dst->parent) 79 61 140
69 {
70 79 ▶ Alien::Build->log("mkdir -p @{[ $dst->parent ]}") if $opt->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"verbose"} 25 54 79
71 79 $dst->parent->mkpath;
72 }
73 # TODO: rmtree if a directory?
74 140 ▶ if(-e "$dst")
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$dst") 0 140 140
75 0 { unlink "$dst" }
76 140 ▶ Alien::Build->log("cp $src $dst") if $opt->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"verbose"} 46 94 140
77 140 ▶ File::Copy::cp("$src", "$dst") || die "copy error $src => $dst: $!";
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::cp("$src", "$dst") or die "copy error $src => ${dst}: $!" 140 0 140
78 140 ▶ if($] < 5.012 && -x "$src" && $^O ne 'MSWin32')
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.012" and -x "$src" and $^O ne "MSWin32") 0 140 140
Condition33%2/6
$] < "5.012" and -x "$src" and $^O ne "MSWin32"
!ll&&!rl&&r
14000
$] < "5.012" and -x "$src"
!ll&&!rl&&r
14000
MC/DC0%0/3
$] < "5.012" and -x "$src" and $^O ne "MSWin32"
$] < "5.012" -x "$src" $^O ne "MSWin32"
Truth table25%1/4
A and B and C
A= $] < "5.012"B= -x "$src"C= $^O ne "MSWin32"
ABCresult
0XX0
10X0
1100
1111
79 {
80 # apparently Perl 5.8 and 5.10 do not preserver perms
81 0 my $mode = [stat "$src"]->[2] & oct(777);
82 0 eval { chmod $mode, "$dst" };
83 }
84 }
85 },
86 49 no_chdir => 1,
87 }, "$src_root");
88  
89 49 ();
90 }
91  
92 sub _dump
93 50 ▶{
Subroutine _dump: called CC=2 SCAR=8.4
94 50 ▶ if(eval { require YAML })
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require YAML } }) { } 50 0 50
95 {
96 50 return YAML::Dump(@_);
97 }
98 else
99 {
100 0 require Data::Dumper;
101 0 return Data::Dumper::Dumper(@_);
102 }
103 }
104  
105 sub _destdir_prefix
106 20 ▶{
Subroutine _destdir_prefix: called CC=2 SCAR=7.1
107 20 my($destdir, $prefix) = @_;
108 20 ▶ $prefix =~ s{^/?([a-z]):}{$1}i if $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 20 20
109 20 path($destdir)->child($prefix)->stringify;
110 }
111  
112 sub _perl_config
113 6 ▶{
Subroutine _perl_config: called CC=1 SCAR=0.0
114 6 my($key) = @_;
115 6 $Config{$key};
116 }
117  
118 sub _ssl_reqs
119 12 ▶{
Subroutine _ssl_reqs: called CC=1 SCAR=0.0
120 return {
121 12 'Net::SSLeay' => '1.49',
122 'IO::Socket::SSL' => '1.56',
123 };
124 }
125  
126 sub _has_ssl
127 6 ▶{
Subroutine _has_ssl: called CC=3 SCAR=11.1
128 6 my %reqs = %{ _ssl_reqs() };
129 6 eval {
130 6 require Net::SSLeay;
131 6 ▶ die "need Net::SSLeay $reqs{'Net::SSLeay'}" unless Net::SSLeay->VERSION($reqs{'Net::SSLeay'});
Branch: 1 branch
BranchTrueFalseTotal
unless "Net::SSLeay"->VERSION($reqs{"Net::SSLeay"}) 0 6 6
132 6 require IO::Socket::SSL;
133 6 ▶ die "need IO::Socket::SSL $reqs{'IO::Socket::SSL'}" unless IO::Socket::SSL->VERSION($reqs{'IO::Socket::SSL'});
Branch: 1 branch
BranchTrueFalseTotal
unless "IO::Socket::SSL"->VERSION($reqs{"IO::Socket::SSL"}) 0 6 6
134 };
135 6 $@ eq '';
136 }
137  
138 71 1;
139  
140 __END__
« blib/lib/Alien/Build/Plugin/PkgConfig/CommandLine.pm ↑ Summary blib/lib/Alien/Build/Plugin/Digest/SHAPP.pm »