blib/lib/Makefile/Parser.pm

filter: Statementstmt 40.1% 247 / 615 Branchbran 38.2% 94 / 246 Conditioncond 58.6% 34 / 58 MC/DCmcdc 41.1% 14 / 34 Subroutinesub 72.0% 31 / 43 Podpod 100% 10 / 10 totaltotal 42.7% 430 / 1006 SCAR 85.4
CC
155
Cov
41%
_process_func_ref
2732.4
_split_args
182.0
run_commands
72.0
CRAP 5138.3
« blib/lib/Makefile/AST.pm ↑ Summary blib/lib/Makefile/Parser/GmakeDB.pm »
1 package Makefile::Parser;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Cwd qw/ realpath /;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use List::MoreUtils qw( uniq pairwise ) ;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Text::Balanced qw( gen_extract_tagged );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 #use Smart::Comments;
11  
12 #our $Debug = 0;
13 1 our $Strict = 0;
14 1 our $VERSION = '0.215';
15 1 our $Error;
16 1 our $Runtime = undef;
17  
18 # usage: $class->new;
19 sub new {
20 10 ▶ my $proto = shift;
Subroutine new: called CC=2 SCAR=7.0
Pod documented
21 10 ▶ my $class = ref $proto || $proto;
Condition66%2/3
ref $proto || $proto
l!l&&r!l&&!r
190
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table66%2/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
22 10 my $self = bless {
23 _vars => {}, # all the definitions of variables
24 _tars => undef, # all the targets
25 _default => undef, # default target
26 _depends => {}, # all the dependencies
27 _imps => [], # targets in implicit rules
28 }, $class;
29 10 return $self;
30 }
31  
32 1 my $extract_interp_1 = gen_extract_tagged('\$[(]', '[)]', '');
33 1 my $extract_interp_2 = gen_extract_tagged('\$[{]', '[}]', '');
34  
35 sub _extract_interp {
36 3589 ▶ my ($res) = $extract_interp_1->($_[0]);
Subroutine _extract_interp: called CC=2 SCAR=6.9
37 3589 ▶ if (!$res) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res) 2374 1215 3589
38 2374 ($res) = $extract_interp_2->($_[0]);
39 }
40 3589 $res;
41 }
42  
43 # usage: $obj->parse($filename);
44 sub parse {
45 15 ▶ my ($self, $file, $vars) = @_;
Subroutine parse: called CC=40 SCAR=37.1
Pod documented
46 15 ▶ $file ||= 'Makefile';
Condition100%2/2
$file ||= "Makefile"
l!l
96
MC/DC100%1/1
$file ||= "Makefile"
$file
Truth table100%2/2
A
A= $file
Aresult
11
00
47 15 ▶ my %init_vars = %$vars if $vars;
Branch: 1 branch
BranchTrueFalseTotal
if $vars 0 15 15
48  
49 15 $self->{_file} = $file;
50 $self->{_vars} = {
51 15 MAKE => $0,
52 CC => 'cc',
53 SHELL => 'sh',
54 %init_vars,
55 };
56 15 undef $self->{_tars};
57 15 undef $self->{_default};
58 15 $self->{_depends} = {};
59 15 $self->{_imps} = [];
60  
61 15 my $rvars = $self->{_vars};
62 15 my $in;
63 15 ▶ unless (open $in, $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $in, $file) 2 13 15
64 2 $Error = "Cannot open $file for reading: $!";
65 2 return undef;
66 }
67  
68 13 my $state = 'S_IDLE';
69 13 my ($var, $value, $tar_name, $tar, $colon_type, $depends, $cmd);
70 13 my @cmds;
71 13 my %tars;
72 #%$rvars = ();
73 13 my $first_tar = 1;
74 13 ▶ while (<$in>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $in)) 3245 13 3258
75 3247 ▶ next if /^\s*#/ and $state ne 'S_IN_VAL';
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*#/ and $state ne "S_IN_VAL" 364 2883 3247
Condition66%2/3
/^\s*#/ and $state ne "S_IN_VAL"
!ll&&!rl&&r
28830364
MC/DC50%1/2
/^\s*#/ and $state ne "S_IN_VAL"
/^\s*#/ $state ne "S_IN_VAL"
Truth table66%2/3
A and B
A= /^\s*#/B= $state ne "S_IN_VAL"
ABresult
0X0
100
111
76 2883 ▶ next if /^\s*$/ and $state ne 'S_IN_VAL';
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*$/ and $state ne "S_IN_VAL" 981 1902 2883
Condition100%3/3
/^\s*$/ and $state ne "S_IN_VAL"
!ll&&!rl&&r
188814981
MC/DC100%2/2
/^\s*$/ and $state ne "S_IN_VAL"
/^\s*$/ $state ne "S_IN_VAL"
Truth table100%3/3
A and B
A= /^\s*$/B= $state ne "S_IN_VAL"
ABresult
0X0
100
111
77 #$tar_name = '' unless defined $var;
78 #warn "(tar: $tar_name) Switching to tate $state with $_";
79 #warn $state if $state ne 'S_IDLE';
80 1902 chomp;
81 #if (/TEST_VERBOSE=/) {
82 #### line: $_
83 #### state: $state
84 #}
85  
86 # expand the value of use-defined variables:
87 #s/\$[\{\(](\w+)[\}\)]/exists $rvars->{$1} ? $rvars->{$1} : $&/ge;
88 1902 $_ = $self->_process_refs($_);
89  
90 1902 ▶ if (($state eq 'S_IDLE' or $state eq 'S_CMD') and /^(\w+) \s* :?= \s* (.*)$/xo) {
Branch: 8 branches
BranchTrueFalseTotal
if ($state eq 'S_IDLE' || $state eq 'S_CMD' and /^(\w+) \s* :?= \s* (.*)$/ox) { } 271 1631 1902
elsif ($state eq 'S_IN_VAL') { } 58 1573 1631
elsif ($state eq 'S_IDLE' || $state eq 'S_CMD' and /^(\.\w+) (\.\w+) \s* (::?)\s*$/ox) { } 2 1571 1573
elsif ($state eq 'S_IDLE' || $state eq 'S_CMD' and /^(\S[^:]*) (::?) \s* (.*)$/ox) { } 599 972 1571
elsif ($state eq 'S_IN_DEPENDS' and /^\s+ (.*)$/ox) { } 14 958 972
elsif ($state eq 'S_CMD' and /^\s+(.*)/o) { } 825 133 958
elsif ($state eq 'S_IN_CMD' and /^\s+(.*)/o) { } 133 0 133
elsif ($Makefile::Parser::Strict) { } 0 0 0
Condition100%6/6
$state eq "S_IDLE" || $state eq "S_CMD" and /^(\w+) \s* :?= \s* (.*)$/ox
!ll&&!rl&&r
2051426271
$state eq "S_IDLE" or $state eq "S_CMD"
l!l&&r!l&&!r
2851412205
MC/DC100%3/3
$state eq "S_IDLE" || $state eq "S_CMD" and /^(\w+) \s* :?= \s* (.*)$/ox
$state eq "S_IDLE" $state eq "S_CMD" /^(\w+) \s* :?= \s* (.*)$/ox
Truth table100%5/5
A or B and C
A= $state eq "S_IDLE"B= $state eq "S_CMD"C= /^(\w+) \s* :?= \s* (.*)$/ox
ABCresult
00X0
1X00
0100
1X11
0111
91 271 $var = $1;
92 271 $value = $2;
93 #warn "matched $var = $value\n";
94 271 ▶ if ($value =~ m{\\\s*$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /\\\s*$/) { } 29 242 271
95 29 $value .= "\n";
96 29 $state = 'S_IN_VAL' ;
97 } else {
98 242 $value =~ s/#.*//m;
99 242 $rvars->{$var} = $value;
100 ### variable: $var
101 ### value: $value
102 242 $state = 'S_IDLE';
103 }
104 #warn "$1 * $2 * $3";
105  
106 } elsif ($state eq 'S_IN_VAL') {
107 #warn $1;
108 58 my $line = $_;
109 #warn "adding value line $line\n";
110 58 $value .= "$line\n";
111 58 ▶ if ($line !~ m{\\\s*$}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ /\\\s*$/) 29 29 58
112 29 $state = 'S_IDLE' ;
113 #warn "Processing value '$value'\n";
114 29 $value =~ s/[ \t]*\\\n[ \t]*/ /sg;
115 29 $value =~ s/#.*//smg;
116 #warn "Finale value '$value'\n";
117 29 $value =~ s/\n//gs;
118 29 $value =~ s/^\s+|\s+$//gs;
119 29 $rvars->{$var} = $value;
120 #warn "$var <=> $value\n";
121 }
122  
123 ▶ } elsif (($state eq 'S_IDLE' or $state eq 'S_CMD') and /^(\.\w+) (\.\w+) \s* (::?)\s*$/xo) {
Condition100%6/6
$state eq "S_IDLE" || $state eq "S_CMD" and /^(\.\w+) (\.\w+) \s* (::?)\s*$/ox
!ll&&!rl&&r
14714242
$state eq "S_IDLE" or $state eq "S_CMD"
l!l&&r!l&&!r
1051321147
MC/DC66%2/3
$state eq "S_IDLE" || $state eq "S_CMD" and /^(\.\w+) (\.\w+) \s* (::?)\s*$/ox
$state eq "S_IDLE" $state eq "S_CMD" /^(\.\w+) (\.\w+) \s* (::?)\s*$/ox
Truth table80%4/5
A or B and C
A= $state eq "S_IDLE"B= $state eq "S_CMD"C= /^(\.\w+) (\.\w+) \s* (::?)\s*$/ox
ABCresult
00X0
1X00
0100
1X11
0111
124 2 $_ = "%$2 $3 %$1\n";
125 #warn $_;
126 2 redo;
127  
128 ▶ } elsif (($state eq 'S_IDLE' or $state eq 'S_CMD') and /^(\S[^:]*) (::?) \s* (.*)$/xo) {
Condition100%6/6
$state eq "S_IDLE" || $state eq "S_CMD" and /^(\S[^:]*) (::?) \s* (.*)$/ox
!ll&&!rl&&r
147825599
$state eq "S_IDLE" or $state eq "S_CMD"
l!l&&r!l&&!r
1051319147
MC/DC100%3/3
$state eq "S_IDLE" || $state eq "S_CMD" and /^(\S[^:]*) (::?) \s* (.*)$/ox
$state eq "S_IDLE" $state eq "S_CMD" /^(\S[^:]*) (::?) \s* (.*)$/ox
Truth table80%4/5
A or B and C
A= $state eq "S_IDLE"B= $state eq "S_CMD"C= /^(\S[^:]*) (::?) \s* (.*)$/ox
ABCresult
00X0
1X00
0100
1X11
0111
129 599 $tar_name = $1;
130 599 $colon_type = $2;
131 599 $depends = $3;
132 599 $tar_name =~ s/^\s+|\s+$//g;
133  
134 599 my $cmd;
135 599 ▶ if ($depends =~ s/;(.*)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depends =~ s/;(.*)//) 0 599 599
136 0 $cmd = $1;
137 }
138  
139 # Ignore .SUFFIXES currently:
140 599 ▶ next if $tar_name eq '.SUFFIXES';
Branch: 1 branch
BranchTrueFalseTotal
if $tar_name eq ".SUFFIXES" 1 598 599
141  
142 #warn "Adding target $tar_name...\n";
143 598 $tar = Makefile::Target->new($tar_name, $colon_type);
144 598 ▶ if (my $old_tars = $tars{$tar_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $old_tars = $tars{$tar_name}) { } 3 595 598
145 3 ▶ if ($colon_type eq ':') {
Branch: 1 branch
BranchTrueFalseTotal
if ($colon_type eq ':') { } 2 1 3
146 2 $tar->add_prereq($old_tars->[0]->prereqs);
147 2 ▶ if (my @cmd = $old_tars->[0]->commands) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@cmd) = $old_tars->[0]->commands) 1 1 2
148 1 $tar->add_command(@cmd);
149 }
150 2 @$old_tars = $tar;
151 } else {
152 1 push @$old_tars, $tar;
153 }
154 } else {
155 595 $tars{$tar_name} = [$tar];
156 }
157 598 ▶ if ($tar_name =~ m/%/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tar_name =~ /%/) 9 589 598
158 9 push @{$self->{_imps}}, $tar_name;
159 }
160 598 ▶ if ($first_tar) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first_tar) 13 585 598
161 13 $self->{_default} = $tar;
162 13 $first_tar = 0;
163 }
164 598 ▶ if ($depends =~ s/\s+\\$//o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depends =~ s/\s+\\$//o) { } 14 584 598
165 14 $state = 'S_IN_DEPENDS';
166 } else {
167 584 $depends =~ s/\^\\$/\\/;
168 584 $state = 'S_CMD';
169 }
170 598 my @depends = split /\s+/, $depends;
171 598 map { $self->{_depends}->{$_} = 1 } @depends;
172 598 $tar->add_depend(@depends);
173 598 ▶ $tar->add_command($cmd) if defined $cmd;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cmd 0 598 598
174 }
175 ▶ elsif ($state eq 'S_IN_DEPENDS' and /^\s+ (.*)$/xo) {
Condition66%2/3
$state eq "S_IN_DEPENDS" and /^\s+ (.*)$/ox
!ll&&!rl&&r
958014
MC/DC50%1/2
$state eq "S_IN_DEPENDS" and /^\s+ (.*)$/ox
$state eq "S_IN_DEPENDS" /^\s+ (.*)$/ox
Truth table66%2/3
A and B
A= $state eq "S_IN_DEPENDS"B= /^\s+ (.*)$/ox
ABresult
0X0
100
111
176 14 $depends = $1;
177 14 ▶ if ($depends !~ s/\s+\\$//o) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($depends =~ s/\s+\\$//o) 14 0 14
178 14 $depends =~ s/\^\\$/\\/;
179 14 my @depends = split /\s+/, $depends;
180 14 map { $self->{_depends}->{$_} = 1 } @depends;
181 14 $tar->add_depend(@depends);
182 14 $state = 'S_CMD';
183 }
184 }
185 ▶ elsif ($state eq 'S_CMD' and /^\s+(.*)/o) {
Condition66%2/3
$state eq "S_CMD" and /^\s+(.*)/o
!ll&&!rl&&r
1330825
MC/DC50%1/2
$state eq "S_CMD" and /^\s+(.*)/o
$state eq "S_CMD" /^\s+(.*)/o
Truth table66%2/3
A and B
A= $state eq "S_CMD"B= /^\s+(.*)/o
ABresult
0X0
100
111
186 825 $cmd = $1;
187 825 ▶ if ($cmd =~ s/\s+\\$//o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ s/\s+\\$//o) { } 35 790 825
188 35 $state = 'S_IN_CMD';
189 } else {
190 790 $tar->add_command($cmd);
191 }
192 }
193 ▶ elsif ($state eq 'S_IN_CMD' and /^\s+(.*)/o) {
Condition33%1/3
$state eq "S_IN_CMD" and /^\s+(.*)/o
!ll&&!rl&&r
00133
MC/DC0%0/2
$state eq "S_IN_CMD" and /^\s+(.*)/o
$state eq "S_IN_CMD" /^\s+(.*)/o
Truth table33%1/3
A and B
A= $state eq "S_IN_CMD"B= /^\s+(.*)/o
ABresult
0X0
100
111
194 133 $cmd .= " $1";
195 133 ▶ if ($cmd !~ s/\s+\\$//o) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cmd =~ s/\s+\\$//o) 35 98 133
196 35 $tar->add_command($cmd);
197 35 $state = 'S_CMD';
198 }
199 }
200 elsif ($Strict) {
201 0 $Error = "syntax error: line $.: $_\n";
202 0 return undef;
203 } else {
204 0 warn "I dunno how to do with it: $_\n";
205 }
206 }
207 13 $self->{_tars} = \%tars;
208 13 $self->post_parse;
209 #warn Data::Dumper->Dump([\%tars], ['TARGETS']);
210 13 close $in;
211 13 return $self;
212 }
213  
214 sub post_parse {
215 13 ▶ my $self = shift;
Subroutine post_parse: called CC=4 SCAR=13.9
Pod documented
216 13 my $rdepends = $self->{_depends};
217 13 my $rimps = $self->{_imps};
218 13 for (keys %$rdepends) {
219 942 ▶ next if /%/;
Branch: 1 branch
BranchTrueFalseTotal
if /%/ 9 933 942
220 #warn "Trying to match implicit rules one by one against $_...\n";
221 933 $self->solve_imp($_);
222 }
223 13 for (@$rimps) {
224 9 delete $self->{_tars}->{$_};
225 }
226 }
227  
228 sub solve_imp {
229 948 ▶ my ($self, $depend) = @_;
Subroutine solve_imp: called CC=5 SCAR=16.1
Pod documented
230 948 my $rimps = $self->{_imps};
231 948 for my $imp (@$rimps) {
232 72 my $obj = $self->target($imp);
233 72 ▶ die "Rules for $imp not found" unless $obj and ref $obj;
Branch: 1 branch
BranchTrueFalseTotal
unless $obj and ref $obj 0 72 72
Condition33%1/3
$obj and ref $obj
!ll&&!rl&&r
0072
MC/DC0%0/2
$obj and ref $obj
$obj ref $obj
Truth table33%1/3
A and B
A= $objB= ref $obj
ABresult
0X0
100
111
234 72 my $regex = quotemeta($imp);
235 72 $regex =~ s/\\%/(.+)/; # `%' can match any nonempty substring
236 #warn "Processing regex $regex...\n";
237 72 ▶ if ($depend =~ m/^$regex$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depend =~ /^$regex$/) 15 57 72
238 #warn "Succeeded to match $imp against $depend!\n";
239 15 my $matched_part = $1;
240 15 my $tar = Makefile::Target->new($depend, $obj->colon_type);
241 15 my $dep;
242 my @deps = map {
243 15 s/%/$matched_part/;
244 15 $self->{_depends}->{$_} = 1;
245 #warn "Recursively solving dependent gole $_...\n";
246 15 $self->solve_imp($_);
247 15 $dep = $_;
248 15 $_
249 } $obj->depends;
250 15 $tar->add_depend(@deps);
251 my @cmds = map {
252 15 s/\$</$dep/g;
253 15 s/\$\*/$matched_part/g;
254 15 $_
255 } $obj->commands;
256 15 $tar->add_command(@cmds);
257 15 $self->{_tars}->{$depend} = [$tar];
258 }
259 }
260 }
261  
262 sub var {
263 26 ▶ my ($self, $var) = @_;
Subroutine var: called CC=2 SCAR=6.9
Pod documented
264 26 ▶ $self->parse if !defined $self->{_file};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_file"} 1 25 26
265 26 return $self->{_vars}->{$var};
266 }
267  
268 sub vars {
269 2 ▶ my $self = shift;
Subroutine vars: called CC=2 SCAR=6.9
Pod documented
270 2 ▶ $self->parse if !defined $self->{_file};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_file"} 1 1 2
271 2 return keys %{$self->{_vars}};
272 }
273  
274 sub target {
275 96 ▶ my ($self, $tar_name) = @_;
Subroutine target: called CC=5 SCAR=16.1
Pod documented
276 96 ▶ $self->parse if !defined $self->{_file};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_file"} 2 94 96
277 96 ▶ return $self->{_default} if !defined $tar_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tar_name 2 94 96
278 94 my $tars = $self->{_tars}->{$tar_name};
279 94 ▶ $tars ||= [];
Condition50%1/2
$tars ||= []
l!l
940
MC/DC0%0/1
$tars ||= []
$tars
Truth table50%1/2
A
A= $tars
Aresult
11
00
280 94 ▶ wantarray ? @$tars : $tars->[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 91 94
281 }
282  
283 sub targets {
284 5 ▶ my $self = shift;
Subroutine targets: called CC=2 SCAR=6.9
Pod documented
285 5 ▶ $self->parse if !defined $self->{_file};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_file"} 1 4 5
286 5 return map { @$_ } values %{$self->{_tars}};
287 }
288  
289 sub roots {
290 6 ▶ my $self = shift;
Subroutine roots: called CC=4 SCAR=13.9
Pod documented
291 6 ▶ $self->parse if !defined $self->{_file};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_file"} 1 5 6
292 6 my %depends = %{$self->{_depends}};
293 6 my %tars = %{$self->{_tars}};
294 6 my @roots = ();
295 6 my ($key, $val);
296 6 ▶ while (($key, $val) = each %tars) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %tars) 187 6 193
297 #next if $key =~ m/%/;
298 187 ▶ next if $depends{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $depends{$key} 162 25 187
299 25 push @roots, $key;
300 }
301 6 return @roots;
302 }
303  
304 sub error {
305 3 ▶ return $Error;
Subroutine error: called CC=1 SCAR=0.0
Pod documented
306 }
307  
308 sub _solve_refs_in_tokens ($$) {
309 1902 ▶ my ($self, $tokens) = @_;
Subroutine _solve_refs_in_tokens: called CC=13 SCAR=33.4
310 1902 ▶ return '' if !$tokens;
Branch: 1 branch
BranchTrueFalseTotal
unless $tokens 0 1902 1902
311 1902 my $rvars = $self->{_vars};
312 1902 my @new_tokens;
313 1902 for my $token (@$tokens) {
314 5276 ▶ if ($token =~ /^\$[{(](.*)[)}]$/) {
Branch: 4 branches
BranchTrueFalseTotal
if ($token =~ /^\$[{(](.*)[)}]$/) { } 1217 4059 5276
elsif ($token =~ /^\$[\@<|]$/) { } 369 3690 4059
elsif ($token =~ /^\$\$$/) { } 0 3690 3690
elsif ($token =~ /^\$(.)$/) { } 101 3589 3690
315 1217 my $s = $1;
316 1217 ▶ if ($s =~ /^([-\w]+)\s+(.*)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($s =~ /^([-\w]+)\s+(.*)$/) { } 0 1217 1217
elsif ($s =~ /^(\S+?):(\S+?)=(\S+)$/) { } 0 1217 1217
317 0 my $res = $self->_process_func_ref($1, $2);
318 0 ▶ if (defined $res) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $res) 0 0 0
319 0 push @new_tokens, $res;
320 0 next;
321 }
322 } elsif ($s =~ /^(\S+?):(\S+?)=(\S+)$/) {
323 0 my ($var, $from, $to) = ($1, $2, $3);
324 0 my $res = $self->_process_func_ref(
325 'patsubst', "\%$from,\%$to,\$($var)"
326 );
327 0 ▶ if (defined $res) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $res) 0 0 0
328 0 push @new_tokens, $res;
329 0 next;
330 }
331 }
332 1217 ▶ if (exists $rvars->{$s}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rvars->{$s}) { } 1216 1 1217
333 1216 push @new_tokens, $rvars->{$s};
334 1216 next;
335 } else {
336 # FIXME: undefined var == ''
337 #push @new_tokens, '';
338 #next;
339 }
340 } elsif ($token =~ /^\$[@<|]$/) {
341 # currently do nothing with the automatic vars
342 } elsif ($token =~ /^\$\$$/) {
343 0 push @new_tokens, '$';
344 0 next;
345 } elsif ($token =~ /^\$(.)$/) {
346 101 ▶ if (exists $rvars->{$1}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rvars->{$1}) { } 0 101 101
347 0 push @new_tokens, $rvars->{$1};
348 0 next;
349 } else {
350 # FIXME: undef var == ''
351 # push @new_tokens, '';
352 # next;
353 }
354 ### found single-letter variable: $1
355 ### value: $rvars->{$1}
356 ### token: $token
357 }
358 4060 push @new_tokens, $token;
359 }
360 ### retval: join '', @$tokens
361 1902 return join '', @new_tokens;
362 }
363  
364 sub _process_refs {
365 1902 ▶ my ($self, $s) = @_;
Subroutine _process_refs: called CC=5 SCAR=16.2
366 1902 my @tokens = '';
367 1902 while (1) {
368 6692 ▶ if ($s =~ /\G[^\$]+/gc) {
Branch: 4 branches
BranchTrueFalseTotal
if ($s =~ /\G[^\$]+/cg) { } 3103 3589 6692
elsif (my $res = _extract_interp($s)) { } 1217 2372 3589
elsif ($s =~ /\G\$./cg) { } 470 1902 2372
elsif ($s =~ /\G./cg) { } 0 1902 1902
369 3103 $tokens[-1] .= $&;
370 } elsif (my $res = _extract_interp($s)) {
371 1217 push @tokens, $res, '';
372 } elsif ($s =~ /\G\$./gc) {
373 470 push @tokens, $&, '';
374 } elsif ($s =~ /\G./gc) {
375 0 $tokens[-1] .= $&;
376 } else {
377 1902 last;
378 }
379 }
380 ### tokens: @tokens
381 1902 return $self->_solve_refs_in_tokens(\@tokens);
382 }
383  
384 sub _pat2re ($@) {
385 0 ▶ my ($pat, $capture) = @_;
Subroutine _pat2re: not called CC=2 SCAR=17.9
386 0 $pat = quotemeta $pat;
387 0 ▶ if ($capture) {
Branch: 1 branch
BranchTrueFalseTotal
if ($capture) { } 0 0 0
388 0 $pat =~ s/\\\%/(\\S*)/g;
389 } else {
390 0 $pat =~ s/\\\%/\\S*/g;
391 }
392 0 $pat;
393 }
394  
395 sub _text2words ($) {
396 0 ▶ my ($text) = @_;
Subroutine _text2words: not called CC=1 SCAR=6.9
397 0 $text =~ s/^\s+|\s+$//g;
398 0 split /\s+/, $text;
399 }
400  
401 sub _check_numeric ($$$$) {
402 0 ▶ my ($self, $func, $order, $n) = @_;
Subroutine _check_numeric: not called CC=2 SCAR=17.9
403 0 ▶ if ($n !~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $n =~ /^\d+$/) 0 0 0
404 0 warn $self->{_file}, ":$.: ",
405 "*** non-numeric $order argument to `$func' function: '$n'. Stop.\n";
406 0 exit(2);
407 }
408 }
409  
410 sub _check_greater_than ($$$$$) {
411 0 ▶ my ($self, $func, $order, $n, $value) = @_;
Subroutine _check_greater_than: not called CC=2 SCAR=17.9
412 0 ▶ if ($n <= $value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n <= $value) 0 0 0
413 0 warn $self->{_file}, ":$.: *** $order argument to `$func' function must be greater than $value. Stop.\n";
414 0 exit(2);
415 }
416 }
417  
418 sub _trim ($@) {
419 0 ▶ for (@_) {
Subroutine _trim: not called CC=2 SCAR=17.9
420 0 s/^\s+|\s+$//g;
421 }
422 }
423  
424 sub _split_args($$$$) {
425 0 ▶ my ($self, $func, $s, $m, $n) = @_;
Subroutine _split_args: not called CC=13 SCAR=52.0
426 0 ▶ $n ||= $m;
Condition0%0/3
$n ||= $m
l!l&&r!l&&!r
000
MC/DC0%0/2
$n ||= $m
$n $m
Truth table0%0/3
A ||= B
A= $nB= $m
ABresult
1X1
011
000
427 0 my @tokens = '';
428 0 my @args;
429 ### $n
430 0 ▶ while (@args <= $n) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args <= $n) 0 0 0
431 ### split args: @args
432 ### split tokens: @tokens
433 0 ▶ if ($s =~ /\G\s+/gc) {
Branch: 6 branches
BranchTrueFalseTotal
if ($s =~ /\G\s+/cg) { } 0 0 0
elsif ($s =~ /\G[^\$,]+/cg) { } 0 0 0
elsif ($s =~ /\G,/cg) { } 0 0 0
elsif (my $res = _extract_interp($s)) { } 0 0 0
elsif ($s =~ /\G\$./cg) { } 0 0 0
elsif ($s =~ /\G./cg) { } 0 0 0
434 0 push @tokens, $&, '';
435 }
436 elsif ($s =~ /\G[^\$,]+/gc) {
437 0 $tokens[-1] .= $&;
438 }
439 elsif ($s =~ /\G,/gc) {
440 0 ▶ if (@args < $n - 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args < $n - 1) { } 0 0 0
441 0 push @args, [grep { $_ ne '' } @tokens];
442 0 @tokens = '';
443 } else {
444 0 $tokens[-1] .= $&;
445 }
446 }
447 elsif (my $res = _extract_interp($s)) {
448 0 push @tokens, $res, '';
449 }
450 elsif ($s =~ /\G\$./gc) {
451 0 push @tokens, $&, '';
452 }
453 elsif ($s =~ /\G./gc) {
454 0 $tokens[-1] .= $&;
455 }
456 else {
457 0 ▶ if (@args <= $n - 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args <= $n - 1) 0 0 0
458 0 push @args, [grep { $_ ne '' } @tokens];
459 }
460 0 ▶ last if @args >= $m and @args <= $n;
Branch: 1 branch
BranchTrueFalseTotal
if @args >= $m and @args <= $n 0 0 0
Condition0%0/3
@args >= $m and @args <= $n
!ll&&!rl&&r
000
MC/DC0%0/2
@args >= $m and @args <= $n
@args >= $m @args <= $n
Truth table0%0/3
A and B
A= @args >= $mB= @args <= $n
ABresult
0X0
100
111
461 0 warn $self->{_file}, ":$.: ",
462 "*** insufficient number of arguments (",
463 scalar(@args), ") to function `$func'. Stop.\n";
464 0 exit(2);
465 }
466 }
467 0 return @args;
468 }
469  
470 sub _trim_tokens ($) {
471 0 ▶ my $tokens = shift;
Subroutine _trim_tokens: not called CC=5 SCAR=34.0
472 0 ▶ return if !@$tokens;
Branch: 1 branch
BranchTrueFalseTotal
unless @$tokens 0 0 0
473 0 ▶ if ($tokens->[0] =~ /^\s+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens->[0] =~ /^\s+$/) 0 0 0
474 0 shift @$tokens;
475 }
476 0 ▶ return if !@$tokens;
Branch: 1 branch
BranchTrueFalseTotal
unless @$tokens 0 0 0
477 0 ▶ if ($tokens->[-1] =~ /^\s+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens->[-1] =~ /^\s+$/) 0 0 0
478 0 pop @$tokens;
479 }
480 }
481  
482 sub _process_func_ref ($$$) {
483 0 ▶ my ($self, $name, $args) = @_;
Subroutine _process_func_ref: not called CC=53 SCAR=79.1
484 #### process func ref: $name
485 0 $name = $self->_process_refs($name);
486 0 my @args;
487 0 my $nargs = scalar(@args);
488 0 ▶ if ($name eq 'subst') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "subst") 0 0 0
489 0 my @args = $self->_split_args($name, $args, 3);
490 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
491 ### arguments: @args
492 0 my ($from, $to, $text) = @args;
493 0 $from = quotemeta($from);
494 0 $text =~ s/$from/$to/g;
495 0 return $text;
496 }
497 0 ▶ if ($name eq 'patsubst') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "patsubst") 0 0 0
498 0 my @args = $self->_split_args($name, $args, 3);
499 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
500 0 my ($pattern, $replacement, $text) = @args;
501 0 my $re = _pat2re($pattern, 1);
502 0 $replacement =~ s/\%/\${1}/g;
503 0 $replacement = qq("$replacement");
504 #### pattern: $re
505 #### replacement: $replacement
506 #### text: $text
507 0 my $code = "s/^$re\$/$replacement/e";
508 #### code: $code
509 0 my @words = _text2words($text);
510 0 map { eval $code; } @words;
511 0 return join ' ', grep { $_ ne '' } @words;
512 }
513 0 ▶ if ($name eq 'strip') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "strip") 0 0 0
514 0 my @args = $self->_split_args($name, $args, 1);
515 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
516 0 my ($string) = @args;
517 0 $string =~ s/^\s+|\s+$//g;
518 0 $string =~ s/\s+/ /g;
519 0 return $string;
520 }
521 0 ▶ if ($name eq 'findstring') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "findstring") 0 0 0
522 0 my @args = $self->_split_args($name, $args, 2);
523 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
524 0 my ($find, $in) = @args;
525 0 ▶ if (index($in, $find) >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($in, $find) != -1) { } 0 0 0
526 0 return $find;
527 } else {
528 0 return '';
529 }
530 0 my ($patterns, $text) = @args;
531 0 my @regexes = map { _pat2re($_) }
532 split /\s+/, $patterns;
533 ### regexes: @regexes
534 0 my $regex = join '|', map { "(?:$_)" } @regexes;
535 ### regex: $regex
536 0 my @words = _text2words($text);
537 0 return join ' ', grep /^$regex$/, @words;
538  
539 }
540 0 ▶ if ($name eq 'filter') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "filter") 0 0 0
541 0 my @args = $self->_split_args($name, $args, 2);
542 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
543 0 my ($patterns, $text) = @args;
544 0 my @regexes = map { _pat2re($_) }
545 split /\s+/, $patterns;
546 ### regexes: @regexes
547 0 my $regex = join '|', map { "(?:$_)" } @regexes;
548 ### regex: $regex
549 0 my @words = _text2words($text);
550 0 return join ' ', grep /^$regex$/, @words;
551 }
552 0 ▶ if ($name eq 'filter-out') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "filter-out") 0 0 0
553 0 my @args = $self->_split_args($name, $args, 2);
554 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
555 0 my ($patterns, $text) = @args;
556 0 my @regexes = map { _pat2re($_) }
557 split /\s+/, $patterns;
558 ### regexes: @regexes
559 0 my $regex = join '|', map { "(?:$_)" } @regexes;
560 ### regex: $regex
561 0 my @words = _text2words($text);
562 0 return join ' ', grep !/^$regex$/, @words;
563 }
564 0 ▶ if ($name eq 'sort') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "sort") 0 0 0
565 0 my @args = $self->_split_args($name, $args, 1);
566 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
567 0 my ($list) = @args;
568 0 _trim($list);
569 0 return join ' ', uniq sort split /\s+/, $list;
570 }
571 0 ▶ if ($name eq 'words') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "words") 0 0 0
572 0 my @args = $self->_split_args($name, $args, 1);
573 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
574 0 my ($text) = @args;
575 0 my @words = _text2words($text);
576 0 return scalar(@words);
577 }
578 0 ▶ if ($name eq 'word') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "word") 0 0 0
579 0 my @args = $self->_split_args($name, $args, 2);
580 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
581 0 my ($n, $text) = @args;
582 0 _trim($n);
583 0 $self->_check_numeric('word', 'first', $n);
584 0 $self->_check_greater_than('word', 'first', $n, 0);
585 0 my @words = _text2words($text);
586 0 ▶ return $n > @words ? '' : $words[$n - 1];
Branch: 1 branch
BranchTrueFalseTotal
$n > @words ? : 0 0 0
587 }
588 0 ▶ if ($name eq 'wordlist') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "wordlist") 0 0 0
589 0 my @args = $self->_split_args($name, $args, 3);
590 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
591 0 my ($s, $e, $text) = @args;
592 0 _trim($s, $e, $text);
593 0 $self->_check_numeric('wordlist', 'first', $s);
594 0 $self->_check_numeric('wordlist', 'second', $e);
595 0 $self->_check_greater_than('wordlist', 'first', $s, 0);
596 0 $self->_check_greater_than('wordlist', 'second', $s, -1);
597 0 my @words = _text2words($text);
598 0 ▶ if ($s > $e || $s > @words || $e == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s > $e or $s > @words or $e == 0) 0 0 0
Condition0%0/6
$s > $e or $s > @words or $e == 0
l!l&&r!l&&!r
000
$s > $e or $s > @words
l!l&&r!l&&!r
000
MC/DC0%0/3
$s > $e or $s > @words or $e == 0
$s > $e $s > @words $e == 0
Truth table0%0/4
A or B or C
A= $s > $eB= $s > @wordsC= $e == 0
ABCresult
1XX1
01X1
0011
0000
599 0 return '';
600 }
601 0 ▶ $e = @words if $e > @words;
Branch: 1 branch
BranchTrueFalseTotal
if $e > @words 0 0 0
602 0 return join ' ', @words[$s-1..$e-1];
603 }
604 0 ▶ if ($name eq 'firstword') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "firstword") 0 0 0
605 0 my @args = $self->_split_args($name, $args, 1);
606 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
607 0 my ($text) = @args;
608 0 my @words = _text2words($text);
609 0 ▶ return @words > 0 ? $words[0] : '';
Branch: 1 branch
BranchTrueFalseTotal
@words > 0 ? : 0 0 0
610 }
611 0 ▶ if ($name eq 'lastword') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "lastword") 0 0 0
612 0 my @args = $self->_split_args($name, $args, 1);
613 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
614 0 my ($text) = @args;
615 0 my @words = _text2words($text);
616 0 ▶ return @words > 0 ? $words[-1] : '';
Branch: 1 branch
BranchTrueFalseTotal
@words > 0 ? : 0 0 0
617 }
618 0 ▶ if ($name eq 'dir') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "dir") 0 0 0
619 0 my @args = $self->_split_args($name, $args, 1);
620 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
621 0 my ($text) = @args;
622 0 my @names = _text2words($text);
623 0 ▶ return join ' ', map { /.*\// ? $& : './' } @names;
Branch: 1 branch
BranchTrueFalseTotal
m[.*/] ? : 0 0 0
624 }
625 0 ▶ if ($name eq 'notdir') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "notdir") 0 0 0
626 0 my @args = $self->_split_args($name, $args, 1);
627 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
628 0 my ($text) = @args;
629 0 my @names = _text2words($text);
630 0 return join ' ', map { s/.*\///; $_ } @names;
631 }
632 0 ▶ if ($name eq 'suffix') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "suffix") 0 0 0
633 0 my @args = $self->_split_args($name, $args, 1);
634 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
635 0 my ($text) = @args;
636 0 my @names = _text2words($text);
637 0 ▶ my $s = join ' ', map { /.*(\..*)/ ? $1 : '' } @names;
Branch: 1 branch
BranchTrueFalseTotal
/.*(\..*)/ ? : 0 0 0
638 0 $s =~ s/\s+$//g;
639 0 return $s;
640 }
641 0 ▶ if ($name eq 'basename') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "basename") 0 0 0
642 0 my @args = $self->_split_args($name, $args, 1);
643 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
644 0 my ($text) = @args;
645 0 my @names = _text2words($text);
646 0 ▶ my $s = join ' ', map { /(.*)\./ ? $1 : $_ } @names;
Branch: 1 branch
BranchTrueFalseTotal
/(.*)\./ ? : 0 0 0
647 0 $s =~ s/\s+$//g;
648 0 return $s;
649 }
650 0 ▶ if ($name eq 'addsuffix') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "addsuffix") 0 0 0
651 0 my @args = $self->_split_args($name, $args, 2);
652 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
653 0 my ($suffix, $text) = @args;
654 #_trim($suffix);
655 0 my @names = _text2words($text);
656 0 return join ' ', map { $_ . $suffix } @names;
657 }
658 0 ▶ if ($name eq 'addprefix') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "addprefix") 0 0 0
659 0 my @args = $self->_split_args($name, $args, 2);
660 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
661 0 my ($suffix, $text) = @args;
662 #_trim($suffix);
663 0 my @names = _text2words($text);
664 0 return join ' ', map { $suffix . $_ } @names;
665 }
666 0 ▶ if ($name eq 'join') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "join") 0 0 0
667 0 my @args = $self->_split_args($name, $args, 2);
668 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
669 0 my ($list_1, $list_2) = @args;
670 0 my @list_1 = _text2words($list_1);
671 0 my @list_2 = _text2words($list_2);
672 return join ' ', pairwise {
673 1 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
674 0 ▶ $a . $b
Subroutine __ANON__: not called CC=1 SCAR=6.9
675 0 } @list_1, @list_2;
676 }
677 0 ▶ if ($name eq 'wildcard') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "wildcard") 0 0 0
678 0 my @args = $self->_split_args($name, $args, 1);
679 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
680 0 my ($pattern) = @args;
681 0 return join ' ', grep { -e $_ } glob $pattern;
682 }
683 0 ▶ if ($name eq 'realpath') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "realpath") 0 0 0
684 1 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
685 0 my @args = $self->_split_args($name, $args, 1);
686 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
687 0 my ($text) = @args;
688 0 my @names = _text2words($text);
689 0 return join ' ', map { realpath($_) } @names;
690 }
691 0 ▶ if ($name eq 'abspath') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "abspath") 0 0 0
692 0 my @args = $self->_split_args($name, $args, 1);
693 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
694 0 my ($text) = @args;
695 0 my @names = _text2words($text);
696 0 my @paths = map { File::Spec->rel2abs($_) } @names;
697 0 for my $path (@paths) {
698 0 my @f = split '/', $path;
699 0 my @new_f;
700 0 for (@f) {
701 0 ▶ if ($_ eq '..') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq '..') { } 0 0 0
702 0 pop @new_f;
703 } else {
704 0 push @new_f, $_;
705 }
706 }
707 0 $path = join '/', @new_f;
708 }
709 0 return join ' ', @paths;
710 }
711 0 ▶ if ($name eq 'shell') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "shell") 0 0 0
712 0 my @args = $self->_split_args($name, $args, 1);
713 0 map { $_ = $self->_solve_refs_in_tokens($_) } @args;
714 0 my ($cmd) = @args;
715 0 my $output = `$cmd`;
716 0 $output =~ s/(?:\r?\n)+$//g;
717 0 $output =~ s/\r?\n/ /g;
718 0 return $output;
719 }
720 0 ▶ if ($name eq 'if') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "if") 0 0 0
721 0 my @args = $self->_split_args($name, $args, 2, 3);
722 #map { $_ = $self->_solve_refs_in_tokens($_) } @args;
723 0 my ($condition, $then_part, $else_part) = @args;
724 0 _trim_tokens($condition);
725 0 $condition = $self->_solve_refs_in_tokens($condition);
726 0 ▶ return $condition eq '' ?
Branch: 1 branch
BranchTrueFalseTotal
$condition eq '' ? : 0 0 0
727 $self->_solve_refs_in_tokens($else_part)
728 :
729 $self->_solve_refs_in_tokens($then_part);
730 }
731 0 ▶ if ($name eq 'or') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "or") 0 0 0
732 0 my @args = $self->_split_args($name, $args, 1, 1000_000_000);
733 #map { $_ = $self->_solve_refs_in_tokens($_) } @args;
734 0 for my $arg (@args) {
735 0 _trim_tokens($arg);
736 0 my $value = $self->_solve_refs_in_tokens($arg);
737 0 ▶ return $value if $value ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $value ne "" 0 0 0
738 }
739 0 return '';
740 }
741 0 ▶ if ($name eq 'and') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "and") 0 0 0
742 0 my @args = $self->_split_args($name, $args, 1, 1000_000_000);
743 #map { $_ = $self->_solve_refs_in_tokens($_) } @args;
744 ### arguments for 'and': @args
745 0 my $value;
746 0 for my $arg (@args) {
747 0 _trim_tokens($arg);
748 0 $value = $self->_solve_refs_in_tokens($arg);
749 0 ▶ return '' if $value eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "" 0 0 0
750 }
751 0 return $value;
752 }
753 0 ▶ if ($name eq 'foreach') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "foreach") 0 0 0
754 0 my @args = $self->_split_args($name, $args, 3);
755 0 my ($var, $list, $text) = @args;
756 0 $var = $self->_solve_refs_in_tokens($var);
757 0 $list = $self->_solve_refs_in_tokens($list);
758 0 my @words = _text2words($list);
759 # save the original status of $var
760 0 my $rvars = $self->{_vars};
761 0 my $not_exist = !exists $rvars->{$var};
762 0 my $old_val = $rvars->{$var};
763  
764 0 my @results;
765 0 for my $word (@words) {
766 0 $rvars->{$var} = $word;
767 #warn "$word";
768 0 push @results, $self->_solve_refs_in_tokens($text);
769 }
770  
771 # restore the original status of $var
772 0 ▶ if ($not_exist) {
Branch: 1 branch
BranchTrueFalseTotal
if ($not_exist) { } 0 0 0
773 0 delete $rvars->{$var};
774 } else {
775 0 $rvars->{$var} = $old_val;
776 }
777  
778 0 return join ' ', @results;
779 }
780 0 ▶ if ($name eq 'error') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "error") 0 0 0
781 0 my ($text) = $self->_split_args($name, $args, 1);
782 0 $text = $self->_solve_refs_in_tokens($text);
783 0 warn $self->{_file}, ":$.: *** $text. Stop.\n";
784 0 ▶ exit(2) if $Runtime;
Branch: 1 branch
BranchTrueFalseTotal
if $Makefile::Parser::Runtime 0 0 0
785 0 return '';
786 }
787 0 ▶ if ($name eq 'warning') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "warning") 0 0 0
788 0 my ($text) = $self->_split_args($name, $args, 1);
789 0 $text = $self->_solve_refs_in_tokens($text);
790 0 warn $self->{_file}, ":$.: $text\n";
791 0 return '';
792 }
793 0 ▶ if ($name eq 'info') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "info") 0 0 0
794 0 my ($text) = $self->_split_args($name, $args, 1);
795 0 $text = $self->_solve_refs_in_tokens($text);
796 0 print "$text\n";
797 0 return '';
798 }
799  
800 0 return undef;
801 }
802  
803 #######################################
804  
805 package Makefile::Target;
806  
807 use overload
808 260 ▶ '""' => sub { shift->name },
Subroutine __ANON__: called CC=1 SCAR=0.0
809 36 ▶ 'cmp' => sub { my ($a,$b) = @_; "$a" cmp "$b" },
Subroutine __ANON__: called CC=1 SCAR=0.0
810 0 ▶ 'eq' => sub { my ($a,$b) = @_; "$a" eq "$b" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
811 1 ▶ 'lt' => sub { my ($a,$b) = @_; "$a" lt "$b" };
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine __ANON__: not called CC=1 SCAR=0.6
812  
813 # usage: $class->new($name, $colon_type)
814 sub new {
815 613 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
816 613 my $self = {
817 _name => shift,
818 _colon_type => shift,
819 _commands => [],
820 _depends => [],
821 };
822 613 return bless $self, $class;
823 }
824  
825 sub name {
826 1125 ▶ return shift->{_name};
Subroutine name: called CC=1 SCAR=0.0
827 }
828  
829 sub colon_type {
830 22 ▶ return shift->{_colon_type};
Subroutine colon_type: called CC=1 SCAR=0.0
831 }
832  
833 sub prereqs {
834 39 ▶ return @{shift->{_depends}};
Subroutine prereqs: called CC=1 SCAR=0.0
835 }
836  
837 1 *depends = \&prereqs;
838  
839 sub add_prereq {
840 629 ▶ push @{shift->{_depends}}, @_;
Subroutine add_prereq: called CC=1 SCAR=0.0
841 }
842  
843 1 *add_depend = \&add_prereq;
844  
845 sub commands {
846 29 ▶ return @{shift->{_commands}};
Subroutine commands: called CC=1 SCAR=0.0
847 }
848  
849 sub add_command {
850 841 ▶ my $self = shift;
Subroutine add_command: called CC=2 SCAR=6.9
851 841 my @cmds = @_;
852 841 my $name = $self->name;
853 841 ▶ if ($name !~ m/%/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name =~ /%/) 832 9 841
854 832 map { s/\$\@/$self->{_name}/g } @cmds;
855 }
856 841 push @{$self->{_commands}}, @cmds;
857 }
858  
859 sub run_commands {
860 0 ▶ my $self = shift;
Subroutine run_commands: not called CC=8 SCAR=42.8
861 0 my @cmd = $self->commands;
862 0 for my $cmd (@cmd) {
863 0 my ($quiet, $continue);
864 0 while (1) {
865 0 ▶ if ($cmd =~ s/^\s*\@//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmd =~ s/^\s*\@//) { } 0 0 0
elsif ($cmd =~ s/^\s*-//) { } 0 0 0
866 0 $quiet = 1;
867 } elsif ($cmd =~ s/^\s*-//) {
868 0 $continue = 1;
869 } else {
870 0 last;
871 }
872 }
873 0 $cmd =~ s/^\s+|\s+$//gs;
874 0 ▶ next if $cmd =~ /^$/;
Branch: 1 branch
BranchTrueFalseTotal
if $cmd =~ /^$/ 0 0 0
875 0 ▶ print "$cmd\n" unless $quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $quiet 0 0 0
876 # currently only 'sh' is specified
877 0 system('/bin/sh', '-c', $cmd);
878 0 ▶ if ($? != 0 && !$continue) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0 and not $continue) 0 0 0
Condition0%0/3
$? != 0 and not $continue
!ll&&!rl&&r
000
MC/DC0%0/2
$? != 0 and not $continue
$? != 0 not $continue
Truth table0%0/3
A and not(B)
A= $? != 0B= not $continue
ABresult
0X0
100
111
879 0 die "$cmd returns nonzero status value: $?\n";
880 }
881 }
882 }
883  
884 1 1;
885 __END__
« blib/lib/Makefile/AST.pm ↑ Summary blib/lib/Makefile/Parser/GmakeDB.pm »