App/SmokeBrew/Tools.pm

filter: Statementstmt 95.1% 138 / 145 Branchbran 73.2% 63 / 86 Conditioncond 79.3% 50 / 63 MC/DCmcdc 69.4% 25 / 36 Subroutinesub 100% 24 / 24 Podpod 100% 7 / 7 totaltotal 85.0% 307 / 361 CC 69 SCAR 27.5
CC
69
Cov
85%
smokebrew_dir
48.3
perls
28.1
fetch
12.3
CRAP 15.6
« App/SmokeBrew/BuildPerl.pm ↑ Summary App/SmokeBrew/IniFile.pm »
1 package App::SmokeBrew::Tools;
2 8 $App::SmokeBrew::Tools::VERSION = '1.06';
3 #ABSTRACT: Various utility functions for smokebrew
4  
5 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use Archive::Extract;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use File::Fetch;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use List::Util qw[uniq];
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Module::CoreList;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use Perl::Version;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 8 my @mirrors = (
16 'http://www.cpan.org/',
17 'http://cpan.cpantesters.org/',
18 );
19  
20 1 ▶sub fetch {
Subroutine fetch: called CC=10 SCAR=25.1
Pod documented
21 1 my $fetch = shift;
22 1 ▶ $fetch = shift if $fetch->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
if $fetch->isa(__PACKAGE__) 1 0 1
23 1 ▶ return unless $fetch;
Branch: 1 branch
BranchTrueFalseTotal
unless $fetch 0 1 1
24 1 ▶ my $loc = shift || return;
Condition50%1/2
shift() || (return)
l!l
10
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
25 1 my $mirrors = shift;
26 $mirrors = \@mirrors unless
27 0 ▶ $mirrors and ref $mirrors eq 'ARRAY' and scalar @{ $mirrors };
Branch: 1 branch
BranchTrueFalseTotal
unless $mirrors and ref $mirrors eq "ARRAY" and scalar @{$mirrors;} 1 0 1
Condition40%2/5
$mirrors and ref $mirrors eq "ARRAY" and scalar @{$mirrors;}
!ll
10
$mirrors and ref $mirrors eq "ARRAY"
!ll&&!rl&&r
100
MC/DC0%0/2
$mirrors and ref $mirrors eq "ARRAY" and scalar @{$mirrors;}
$mirrors ref $mirrors eq "ARRAY"
Truth table33%1/3
A and B
A= $mirrorsB= ref $mirrors eq "ARRAY"
ABresult
0X0
100
111
28 1 $loc = File::Spec->rel2abs($loc);
29 1 my $stat;
30 1 foreach my $mirror ( @{ $mirrors } ) {
31 1 ▶ my $uri = URI->new( ( $mirror->isa('URI') ? $mirror->as_string : $mirror ) );
Branch: 1 branch
BranchTrueFalseTotal
$mirror->isa('URI') ? : 0 1 1
32 1 $uri->path_segments( ( grep { $_ } $uri->path_segments ), split(m!/!, $fetch) );
33 1 my $ff = File::Fetch->new( uri => $uri->as_string );
34 1 $stat = $ff->fetch( to => $loc );
35 1 ▶ last if $stat;
Branch: 1 branch
BranchTrueFalseTotal
if $stat 1 0 1
36 }
37 1 return $stat;
38 }
39  
40 1 ▶sub extract {
Subroutine extract: called CC=6 SCAR=18.8
Pod documented
41 1 my $file = shift;
42 1 ▶ $file = shift if $file->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
if $file->isa(__PACKAGE__) 1 0 1
43 1 ▶ return unless $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 1 1
44 1 ▶ my $loc = shift || return;
Condition50%1/2
shift() || (return)
l!l
10
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
45 1 $loc = File::Spec->rel2abs($loc);
46 1 local $Archive::Extract::PREFER_BIN=1;
47 1 my $ae = Archive::Extract->new( archive => $file );
48 1 ▶ return unless $ae;
Branch: 1 branch
BranchTrueFalseTotal
unless $ae 0 1 1
49 1 ▶ return unless $ae->extract( to => $loc );
Branch: 1 branch
BranchTrueFalseTotal
unless $ae->extract("to", $loc) 0 1 1
50 1 return $ae->extract_path();
51 }
52  
53 1 ▶sub smokebrew_dir {
Subroutine smokebrew_dir: called CC=8 SCAR=38.8
Pod documented
54 return $ENV{PERL5_SMOKEBREW_DIR}
55 if exists $ENV{PERL5_SMOKEBREW_DIR}
56 1 ▶ && defined $ENV{PERL5_SMOKEBREW_DIR};
Branch: 1 branch
BranchTrueFalseTotal
if exists $ENV{"PERL5_SMOKEBREW_DIR"} and defined $ENV{"PERL5_SMOKEBREW_DIR"} 1 0 1
Condition33%1/3
exists $ENV{"PERL5_SMOKEBREW_DIR"} and defined $ENV{"PERL5_SMOKEBREW_DIR"}
!ll&&!rl&&r
001
MC/DC0%0/2
exists $ENV{"PERL5_SMOKEBREW_DIR"} and defined $ENV{"PERL5_SMOKEBREW_DIR"}
exists $ENV{"PERL5_SMOKEBREW_DIR"} defined $ENV{"PERL5_SMOKEBREW_DIR"}
Truth table33%1/3
A and B
A= exists $ENV{"PERL5_SMOKEBREW_DIR"}B= defined $ENV{"PERL5_SMOKEBREW_DIR"}
ABresult
0X0
100
111
57  
58 0 my @os_home_envs = qw( APPDATA HOME USERPROFILE WINDIR SYS$LOGIN );
59  
60 0 for my $env ( @os_home_envs ) {
61 0 ▶ next unless exists $ENV{ $env };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ENV{$env} 0 0 0
62 0 ▶ next unless defined $ENV{ $env } && length $ENV{ $env };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ENV{$env} and length $ENV{$env} 0 0 0
Condition0%0/3
defined $ENV{$env} and length $ENV{$env}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ENV{$env} and length $ENV{$env}
defined $ENV{$env} length $ENV{$env}
Truth table0%0/3
A and B
A= defined $ENV{$env}B= length $ENV{$env}
ABresult
0X0
100
111
63 0 ▶ return $ENV{ $env } if -d $ENV{ $env };
Branch: 1 branch
BranchTrueFalseTotal
if -d $ENV{$env} 0 0 0
64 }
65  
66 0 return cwd();
67 }
68  
69 8 ▶sub perls {
Subroutine perls: called CC=28 SCAR=33.3
Pod documented
70 8 my $type = shift;
71 8 ▶ $type = shift if $type->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
if $type->isa(__PACKAGE__) 7 1 8
72 8 ▶ if ( $type and $type eq 'latest' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type and $type eq "latest") 1 7 8
Condition100%3/3
$type and $type eq "latest"
!ll&&!rl&&r
161
MC/DC100%2/2
$type and $type eq "latest"
$type $type eq "latest"
Truth table100%3/3
A and B
A= $typeB= $type eq "latest"
ABresult
0X0
100
111
73 1 my %perls;
74 1 foreach my $pv ( map { Perl::Version->new($_) } perls('recent') ) {
75 71 my $vers = $pv->version;
76 71 ▶ unless ( exists $perls{$vers} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $perls{$vers}) 19 52 71
77 19 $perls{$vers} = $pv;
78 19 next;
79 }
80 52 ▶ $perls{$vers} = $pv if $pv > $perls{$vers};
Branch: 1 branch
BranchTrueFalseTotal
if $pv > $perls{$vers} 52 0 52
81 }
82 19 return map { _format_version($_) } map { $perls{$_} }
83 1 sort { $perls{$a} <=> $perls{$b} } keys %perls;
84 ;
85 }
86 7 ▶ unless ( $type and $type =~ /^(rel|dev|recent|modern)$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type and $type =~ /^(rel|dev|recent|modern)$/i) 2 5 7
Condition100%3/3
$type and $type =~ /^(rel|dev|recent|modern)$/i
!ll&&!rl&&r
115
MC/DC100%2/2
$type and $type =~ /^(rel|dev|recent|modern)$/i
$type $type =~ /^(rel|dev|recent|modern)$/i
Truth table100%3/3
A and B
A= $typeB= $type =~ /^(rel|dev|recent|modern)$/i
ABresult
0X0
100
111
87 2 ▶ $type =~ s/[^\d\.]+//g if $type;
Branch: 1 branch
BranchTrueFalseTotal
if $type 1 1 2
88 }
89 return
90 uniq
91 931 map { _format_version($_) }
92 grep {
93 2415 ▶ if ( $type and $type eq 'rel' ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($type and $type eq 'rel') { } 345 2070 2415
elsif ($type and $type eq 'dev') { } 345 1725 2070
elsif ($type and $type eq 'recent') { } 690 1035 1725
elsif ($type and $type eq 'modern') { } 345 690 1035
elsif ($type) { } 345 345 690
Condition100%3/3
$type and $type eq "rel"
!ll&&!rl&&r
3451725345
MC/DC100%2/2
$type and $type eq "rel"
$type $type eq "rel"
Truth table100%3/3
A and B
A= $typeB= $type eq "rel"
ABresult
0X0
100
111
94 345 ▶ _is_rel($_) and !_is_ancient($_) and !_skip($_);
Condition83%5/6
_is_rel($_) && !_is_ancient($_) && !_skip($_)
!ll&&!rl&&r
2393103
_is_rel($_) and not _is_ancient($_)
!ll&&!rl&&r
2390106
MC/DC66%2/3
_is_rel($_) && !_is_ancient($_) && !_skip($_)
_is_rel($_) not _is_ancient($_) !_skip($_)
Truth table75%3/4
A and not(B) && not(C)
A= _is_rel($_)B= not _is_ancient($_)C= !_skip($_)
ABCresult
0XX0
10X0
1100
1111
95 }
96 ▶ elsif ( $type and $type eq 'dev' ) {
Condition100%3/3
$type and $type eq "dev"
!ll&&!rl&&r
3451380345
MC/DC100%2/2
$type and $type eq "dev"
$type $type eq "dev"
Truth table100%3/3
A and B
A= $typeB= $type eq "dev"
ABresult
0X0
100
111
97 345 ▶ _is_dev($_) and !_is_ancient($_);
Condition66%2/3
_is_dev($_) && !_is_ancient($_)
!ll&&!rl&&r
1160229
MC/DC50%1/2
_is_dev($_) && !_is_ancient($_)
_is_dev($_) !_is_ancient($_)
Truth table66%2/3
A && not(B)
A= _is_dev($_)B= !_is_ancient($_)
ABresult
0X0
100
111
98 }
99 ▶ elsif ( $type and $type eq 'recent' ) {
Condition100%3/3
$type and $type eq "recent"
!ll&&!rl&&r
345690690
MC/DC100%2/2
$type and $type eq "recent"
$type $type eq "recent"
Truth table100%3/3
A and B
A= $typeB= $type eq "recent"
ABresult
0X0
100
111
100 690 ▶ _is_recent($_) and !_skip($_);
Condition100%3/3
_is_recent($_) && !_skip($_)
!ll&&!rl&&r
5066178
MC/DC100%2/2
_is_recent($_) && !_skip($_)
_is_recent($_) !_skip($_)
Truth table100%3/3
A && not(B)
A= _is_recent($_)B= !_skip($_)
ABresult
0X0
100
111
101 }
102 ▶ elsif ( $type and $type eq 'modern' ) {
Condition100%3/3
$type and $type eq "modern"
!ll&&!rl&&r
345345345
MC/DC100%2/2
$type and $type eq "modern"
$type $type eq "modern"
Truth table100%3/3
A and B
A= $typeB= $type eq "modern"
ABresult
0X0
100
111
103 345 ▶ _is_modern($_) and !_skip($_);
Condition100%3/3
_is_modern($_) && !_skip($_)
!ll&&!rl&&r
254388
MC/DC100%2/2
_is_modern($_) && !_skip($_)
_is_modern($_) !_skip($_)
Truth table100%3/3
A && not(B)
A= _is_modern($_)B= !_skip($_)
ABresult
0X0
100
111
104 }
105 elsif ( $type ) {
106 345 $_->normal =~ /\Q$type\E$/;
107 }
108 else {
109 345 ▶ _is_dev($_) or _is_rel($_) and !_is_ancient($_) and !_skip($_);
Condition88%8/9
_is_dev($_) || _is_rel($_) && !_is_ancient($_) && !_skip($_)
l!l&&r!l&&!r
22910313
_is_rel($_) and not _is_ancient($_) and not _skip($_)
!ll&&!rl&&r
103103
_is_rel($_) and not _is_ancient($_)
!ll&&!rl&&r
100106
MC/DC75%3/4
_is_dev($_) || _is_rel($_) && !_is_ancient($_) && !_skip($_)
_is_dev($_) _is_rel($_) not _is_ancient($_) not _skip($_)
Truth table80%4/5
A || B and not(C) and not(D)
A= _is_dev($_)B= _is_rel($_)C= not _is_ancient($_)D= not _skip($_)
ABCDresult
1XXX1
01111
00XX0
010X0
01100
110 }
111 }
112 2415 map { Perl::Version->new($_) }
113 7 ▶ map { $_ >= 5.006 ? sprintf('%.6f', $_) : $_ }
Branch: 1 branch
BranchTrueFalseTotal
$_ >= 5.006 ? : 2345 70 2415
114 sort keys %Module::CoreList::released;
115 }
116  
117 2 ▶sub _has_quadmath {
Subroutine _has_quadmath: called CC=2 SCAR=6.9
118 2 my $pv = shift;
119 2 ▶ return 1 if $pv->numify >= 5.021004;
Branch: 1 branch
BranchTrueFalseTotal
if $pv->numify >= "5.021004" 1 1 2
120 1 return 0;
121 }
122  
123 1697 ▶sub _is_dev {
Subroutine _is_dev: called CC=2 SCAR=6.9
124 1697 my $pv = shift;
125 1697 ▶ return 0 if _is_ancient($pv);
Branch: 1 branch
BranchTrueFalseTotal
if _is_ancient($pv) 20 1677 1697
126 1677 return $pv->version % 2;
127 }
128  
129 461 ▶sub _is_rel {
Subroutine _is_rel: called CC=2 SCAR=6.9
130 461 my $pv = shift;
131 461 ▶ return 0 if _is_ancient($pv);
Branch: 1 branch
BranchTrueFalseTotal
if _is_ancient($pv) 20 441 461
132 441 return !( $pv->version % 2 );
133 }
134  
135 690 ▶sub _is_recent {
Subroutine _is_recent: called CC=4 SCAR=13.9
136 690 my $pv = shift;
137 690 ▶ return 0 if _is_ancient($pv);
Branch: 1 branch
BranchTrueFalseTotal
if _is_ancient($pv) 20 670 690
138 670 ▶ return 0 if _is_dev($pv);
Branch: 1 branch
BranchTrueFalseTotal
if _is_dev($pv) 458 212 670
139 212 ▶ return 1 if $pv->numify >= 5.008009;
Branch: 1 branch
BranchTrueFalseTotal
if $pv->numify >= "5.008009" 184 28 212
140 28 return 0;
141 }
142  
143 345 ▶sub _is_modern {
Subroutine _is_modern: called CC=4 SCAR=13.9
144 345 my $pv = shift;
145 345 ▶ return 0 if _is_ancient($pv);
Branch: 1 branch
BranchTrueFalseTotal
if _is_ancient($pv) 10 335 345
146 335 ▶ return 0 if _is_dev($pv);
Branch: 1 branch
BranchTrueFalseTotal
if _is_dev($pv) 229 106 335
147 106 ▶ return 1 if $pv->numify >= 5.010000;
Branch: 1 branch
BranchTrueFalseTotal
if $pv->numify >= "5.01" 91 15 106
148 15 return 0;
149 }
150  
151 3634 ▶sub _is_ancient {
Subroutine _is_ancient: called CC=2 SCAR=6.9
152 3634 my $pv = shift;
153 3634 ( my $numify = $pv->numify ) =~ s/_//g;
154 3634 ▶ return 1 if $numify < 5.006;
Branch: 1 branch
BranchTrueFalseTotal
if $numify < "5.006" 70 3564 3634
155 3564 return 0;
156 }
157  
158 487 ▶sub _skip {
Subroutine _skip: called CC=4 SCAR=13.9
159 487 my $pv = shift;
160 487 my $nv = $pv->numify;
161 487 ▶ return 1 if $nv == 5.034002 || $nv == 5.036002 || $nv == 5.038001;
Branch: 1 branch
BranchTrueFalseTotal
if $nv == "5.034002" or $nv == "5.036002" or $nv == "5.038001" 15 472 487
Condition100%6/6
$nv == "5.034002" or $nv == "5.036002" or $nv == "5.038001"
l!l&&r!l&&!r
105472
$nv == "5.034002" or $nv == "5.036002"
l!l&&r!l&&!r
55477
MC/DC100%3/3
$nv == "5.034002" or $nv == "5.036002" or $nv == "5.038001"
$nv == "5.034002" $nv == "5.036002" $nv == "5.038001"
Truth table100%4/4
A or B or C
A= $nv == "5.034002"B= $nv == "5.036002"C= $nv == "5.038001"
ABCresult
1XX1
01X1
0011
0000
162 472 return 0;
163 }
164  
165 950 ▶sub _format_version {
Subroutine _format_version: called CC=2 SCAR=7.0
166 950 my $pv = shift;
167 950 my $numify = $pv->numify;
168 950 $numify =~ s/_//g;
169 950 ▶ return $pv if $numify < 5.006;
Branch: 1 branch
BranchTrueFalseTotal
if $numify < "5.006" 0 950 950
170 950 my $normal = $pv->normal();
171 950 $normal =~ s/^v//g;
172 950 return $normal;
173 }
174  
175 2 ▶sub perl_version {
Subroutine perl_version: called CC=3 SCAR=11.0
Pod documented
176 2 my $vers = shift;
177 2 ▶ $vers = shift if eval { $vers->isa(__PACKAGE__) };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { $vers->isa(__PACKAGE__) } } 2 0 2
178 2 my $version = Perl::Version->new( $vers );
179 2 ( my $numify = $version->numify ) =~ s/_//g;
180 2 ▶ my $pv = 'perl'.( $numify < 5.006 ? $version->numify : $version->normal );
Branch: 1 branch
BranchTrueFalseTotal
$numify < 5.006 ? : 1 1 2
181 2 $pv =~ s/perlv/perl-/g;
182 2 return $pv;
183 }
184  
185 2 ▶sub devel_perl {
Subroutine devel_perl: called CC=3 SCAR=11.3
Pod documented
186 2 my $perl = shift;
187 2 ▶ $perl = shift if eval { $perl->isa(__PACKAGE__) };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { $perl->isa(__PACKAGE__) } } 2 0 2
188 2 ▶ return unless $perl;
Branch: 1 branch
BranchTrueFalseTotal
unless $perl 0 2 2
189 2 return _is_dev( Perl::Version->new( $perl ) );
190 }
191  
192 2 ▶sub can_quadmath {
Subroutine can_quadmath: called CC=3 SCAR=11.3
Pod documented
193 2 my $perl = shift;
194 2 ▶ $perl = shift if eval { $perl->isa(__PACKAGE__) };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { $perl->isa(__PACKAGE__) } } 2 0 2
195 2 ▶ return unless $perl;
Branch: 1 branch
BranchTrueFalseTotal
unless $perl 0 2 2
196 2 return _has_quadmath( Perl::Version->new( $perl ) );
197 }
198  
199 8 qq[Smoke tools look what's inside of you];
200  
201 __END__
« App/SmokeBrew/BuildPerl.pm ↑ Summary App/SmokeBrew/IniFile.pm »