blib/lib/Alien/Build/CommandSequence.pm

filter: Statementstmt 97.0% 97 / 100 Branchbran 83.3% 35 / 42 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 16 / 16 Podpod 100% 3 / 3 totaltotal 94.1% 161 / 171 CC 27 SCAR 16.0
CC
27
Cov
93%
execute
10.0
apply_requirements
6.0
__ANON__
5.5
CRAP 5.0
« blib/lib/Alien/Build/Plugin/Extract/ArchiveTar.pm ↑ Summary blib/lib/Alien/Base/PkgConfig.pm »
1 package Alien::Build::CommandSequence;
2  
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use Text::ParseWords qw( shellwords );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use Capture::Tiny qw( capture );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # ABSTRACT: Alien::Build command sequence
10 10 our $VERSION = '2.88'; # VERSION
11  
12  
13 sub new
14 70 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
15 70 my($class, @commands) = @_;
16 70 my $self = bless {
17 commands => \@commands,
18 }, $class;
19 70 $self;
20 }
21  
22  
23 sub apply_requirements
24 59 ▶{
Subroutine apply_requirements: called CC=6 SCAR=17.9
Pod documented
25 59 my($self, $meta, $phase) = @_;
26 59 my $intr = $meta->interpolator;
27 59 foreach my $command (@{ $self->{commands} })
28 {
29 109 ▶ next if ref $command eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $command eq "CODE" 9 100 109
30 100 ▶ if(ref $command eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $command eq 'ARRAY') { } 53 47 100
31 {
32 53 foreach my $arg (@$command)
33 {
34 197 ▶ next if ref $arg eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $arg eq "CODE" 23 174 197
35 174 $meta->add_requires($phase, $intr->requires($arg))
36 }
37 }
38 else
39 {
40 47 $meta->add_requires($phase, $intr->requires($command));
41 }
42 }
43 59 $self;
44 }
45  
46 my %built_in = (
47  
48 3 ▶ cd => sub {
Subroutine __ANON__: called CC=4 SCAR=17.1
49 3 my(undef, $dir) = @_;
50 3 ▶ if(!defined $dir)
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $dir) { } 0 3 3
elsif (-d $dir) { } 3 0 3
51 {
52 0 die "undef passed to cd";
53 }
54 elsif(-d $dir)
55 {
56 3 ▶ chdir($dir) || die "unable to cd $dir $!";
Branch: 1 branch
BranchTrueFalseTotal
chdir $dir or die "unable to cd $dir $!" 3 0 3
57 }
58 else
59 {
60 0 die "unable to cd $dir, does not exist";
61 }
62 },
63  
64 10 );
65  
66 sub _run_list
67 18 ▶{
Subroutine _run_list: called CC=3 SCAR=11.0
68 18 my($build, @cmd) = @_;
69 18 $build->log("+ @cmd");
70 18 ▶ return $built_in{$cmd[0]}->(@cmd) if $built_in{$cmd[0]};
Branch: 1 branch
BranchTrueFalseTotal
if $built_in{$cmd[0]} 1 17 18
71 17 system @cmd;
72 17 ▶ die "external command failed" if $?;
Branch: 1 branch
BranchTrueFalseTotal
if $? 3 14 17
73 }
74  
75 sub _run_string
76 7 ▶{
Subroutine _run_string: called CC=4 SCAR=13.9
77 7 my($build, $cmd) = @_;
78 7 $build->log("+ $cmd");
79  
80 {
81 7 my $cmd = $cmd;
82 7 ▶ $cmd =~ s{\\}{\\\\}g if $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 7 7
83 7 my @cmd = shellwords($cmd);
84 7 ▶ return $built_in{$cmd[0]}->(@cmd) if $built_in{$cmd[0]};
Branch: 1 branch
BranchTrueFalseTotal
if $built_in{$cmd[0]} 1 6 7
85 }
86  
87 6 system $cmd;
88 6 ▶ die "external command failed" if $?;
Branch: 1 branch
BranchTrueFalseTotal
if $? 1 5 6
89 }
90  
91 sub _run_with_code
92 6 ▶{
Subroutine _run_with_code: called CC=3 SCAR=11.0
93 6 my($build, @cmd) = @_;
94 6 my $code = pop @cmd;
95 6 $build->log("+ @cmd");
96 6 my %args = ( command => \@cmd );
97  
98 6 ▶ if($built_in{$cmd[0]})
Branch: 1 branch
BranchTrueFalseTotal
if ($built_in{$cmd[0]}) { } 1 5 6
99 {
100 1 my $error;
101 1 ▶ ($args{out}, $args{err}, $error) = capture {
Subroutine __ANON__: called CC=1 SCAR=0.0
102 1 eval { $built_in{$cmd[0]}->(@cmd) };
103 1 $@;
104 1 };
105 1 ▶ $args{exit} = $error eq '' ? 0 : 2;
Branch: 1 branch
BranchTrueFalseTotal
$error eq '' ? : 1 0 1
106 1 $args{builtin} = 1;
107 }
108 else
109 {
110 5 ▶ ($args{out}, $args{err}, $args{exit}) = capture {
Subroutine __ANON__: called CC=1 SCAR=0.0
111 5 system @cmd; $?
112 5 };
113 }
114 6 $build->log("[output consumed by Alien::Build recipe]");
115 6 $code->($build, \%args);
116 }
117  
118  
119 sub _apply
120 9 ▶{
Subroutine _apply: called CC=2 SCAR=6.9
121 9 my($where, $prop, $value) = @_;
122 9 ▶ if($where =~ /^(.*?)\.(.*?)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($where =~ /^(.*?)\.(.*?)$/) { } 6 3 9
123 {
124 6 _apply($2, $prop->{$1}, $value);
125 }
126 else
127 {
128 3 $prop->{$where} = $value;
129 }
130 }
131  
132 sub execute
133 23 ▶{
Subroutine execute: called CC=10 SCAR=23.0
Pod documented
134 23 my($self, $build) = @_;
135 23 my $intr = $build->meta->interpolator;
136  
137 23 foreach my $command (@{ $self->{commands} })
138 {
139 33 ▶ if(ref($command) eq 'CODE')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $command eq 'CODE') { } 2 31 33
elsif (ref $command eq 'ARRAY') { } 24 7 31
140 {
141 2 $command->($build);
142 }
143 elsif(ref($command) eq 'ARRAY')
144 {
145 24 my($command, @args) = @$command;
146 24 my $code;
147 24 ▶ $code = pop @args if $args[-1] && ref($args[-1]) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if $args[-1] and ref $args[-1] eq "CODE" 3 21 24
Condition100%3/3
$args[-1] and ref $args[-1] eq "CODE"
!ll&&!rl&&r
6153
MC/DC100%2/2
$args[-1] and ref $args[-1] eq "CODE"
$args[-1] ref $args[-1] eq "CODE"
Truth table100%3/3
A and B
A= $args[-1]B= ref $args[-1] eq "CODE"
ABresult
0X0
100
111
148  
149 24 ▶ if($args[-1] && ref($args[-1]) eq 'SCALAR')
Branch: 1 branch
BranchTrueFalseTotal
if ($args[-1] and ref $args[-1] eq "SCALAR") 3 21 24
Condition100%3/3
$args[-1] and ref $args[-1] eq "SCALAR"
!ll&&!rl&&r
6153
MC/DC100%2/2
$args[-1] and ref $args[-1] eq "SCALAR"
$args[-1] ref $args[-1] eq "SCALAR"
Truth table100%3/3
A and B
A= $args[-1]B= ref $args[-1] eq "SCALAR"
ABresult
0X0
100
111
150 {
151 3 my $dest = ${ pop @args };
152 3 ▶ if($dest =~ /^\%\{((?:alien|)\.(?:install|runtime|hook)\.[a-z\.0-9_]+)\}$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($dest =~ /^\%\{((?:alien|)\.(?:install|runtime|hook)\.[a-z\.0-9_]+)\}$/) { } 3 0 3
153 {
154 3 $dest = $1;
155 3 $dest =~ s/^\./alien./;
156 3 ▶ $code = sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
157 3 my($build, $args) = @_;
158 3 ▶ die "external command failed" if $args->{exit};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"exit"} 0 3 3
159 3 my $out = $args->{out};
160 3 chomp $out;
161 3 _apply($dest, $build->_command_prop, $out);
162 3 };
163 }
164 else
165 {
166 0 die "illegal destination: $dest";
167 }
168 }
169  
170 24 ($command, @args) = map { $intr->interpolate($_, $build) } ($command, @args);
171  
172 24 ▶ if($code)
Branch: 1 branch
BranchTrueFalseTotal
if ($code) { } 6 18 24
173 {
174 6 _run_with_code $build, $command, @args, $code;
175 }
176 else
177 {
178 18 _run_list $build, $command, @args;
179 }
180 }
181 else
182 {
183 7 my $command = $intr->interpolate($command, $build);
184 7 _run_string $build, $command;
185 }
186 }
187 }
188  
189 10 1;
190  
191 __END__
« blib/lib/Alien/Build/Plugin/Extract/ArchiveTar.pm ↑ Summary blib/lib/Alien/Base/PkgConfig.pm »