blib/lib/Kook/Kitchen.pm

filter: Statementstmt 92.1% 224 / 243 Branchbran 81.5% 75 / 92 Conditioncond 83.3% 20 / 24 MC/DCmcdc 53.8% 7 / 13 Subroutinesub 93.5% 29 / 31 Podpod 0.0% 0 / 4 totaltotal 87.2% 355 / 407 CC 59 SCAR 24.5
CC
59
Cov
89%
cook
28.0
_create_cooking_tree
9.3
new
7.9
CRAP 11.6
« blib/lib/Kook/Recipe.pm ↑ Summary blib/lib/Kook/Commands.pm »
1 ###
2 ### $Release: 0.0100 $
3 ### $Copyright: copyright(c) 2009-2011 kuwata-lab.com all rights reserved. $
4 ### $License: MIT License $
5 ###
6  
7 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 36 ▶no warnings 'misc'; # suppress warning "Can't locate package Cookable" (for Perl 5.8)
Subroutine BEGIN: called CC=1 SCAR=0.0
10 36 ▶no warnings 'syntax'; # suppress warning "Can't locate package Cookable" (for Perl 5.10 or later)
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 ##
14 ## create cooking object tree and invoke recipe methods.
15 ##
16 ## ex.
17 ## my $cookbook = Kook::Cookbook->new("Kookbook.py");
18 ## my $kitchen = Kook::Kitchen->new($cookbook);
19 ## my $argv = ["hello.o", "-h", "-v"];
20 ## $kitchen->start_cooking($argv); # recipe is invoked and "hello.o" will be created
21 ##
22 package Kook::Kitchen;
23 36 ▶use Exporter ('import');
Subroutine BEGIN: called CC=1 SCAR=0.0
24 36 our @EXPORT_OK = ('Kitchen');
25 36 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 36 ▶use Kook::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 37 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
30 37 my ($class, $cookbook, $properties) = @_;
31 37 my $this = {
32 cookbook => $cookbook,
33 properties => $properties,
34 };
35 37 return bless($this, $class);
36 }
37  
38 34 ▶sub create_cooking_tree {
Subroutine create_cooking_tree: called CC=2 SCAR=7.0
Pod undocumented
39 34 my ($this, $target_product, $cookables) = @_;
40 34 ▶ $cookables = {} unless defined $cookables;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cookables 34 0 34
41 34 my $cookbook = $this->{cookbook};
42 34 my $root = $this->_create_cooking_tree($cookbook, $target_product, $cookables);
43 32 return $root;
44 }
45  
46 203 ▶sub _create_cooking_tree {
Subroutine _create_cooking_tree: called CC=9 SCAR=22.3
47 203 my ($this, $cookbook, $target, $cookables, $parent_product) = @_;
48 203 ▶ return $cookables->{$target} if ($cookables->{$target});
Branch: 1 branch
BranchTrueFalseTotal
if $cookables->{$target} 19 184 203
49 184 my $cookable;
50 184 ▶ if ($cookbook->material_p($target)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cookbook->material_p($target)) { } 0 184 184
51 0 ▶ -f $target or die "$target: material not found.";
Branch: 1 branch
BranchTrueFalseTotal
-f $target or die "${target}: material not found." 0 0 0
52 0 $cookable = Kook::Material->new($target);
53 }
54 else {
55 184 my $recipe = $cookbook->find_recipe($target);
56 184 ▶ if ($recipe) { $cookable = Kook::Cooking->new($target, $recipe); }
Branch: 2 branches
BranchTrueFalseTotal
if ($recipe) { } 115 69 184
elsif (-f $target) { } 67 2 69
57 67 elsif (-f $target) { $cookable = Kook::Material->new($target); }
58 else {
59 2 ▶ $parent_product ? die "$target: no such recipe or material (required for '$parent_product').\n"
Branch: 1 branch
BranchTrueFalseTotal
$parent_product ? : 1 1 2
60 : die "$target: no such recipe or material.\n";
61 }
62 }
63 #assert $cookable;
64 182 $cookables->{$target} = $cookable;
65 182 ▶ if ($cookable->{ingreds}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cookable->{"ingreds"}) 115 67 182
66 115 for my $ingred (@{$cookable->{ingreds}}) {
67 #python: if isinstance(ingred, ConditionalFile):
68 #python: filename = ingred()
69 #python: if not filename: continue
70 #python: ingred = filename
71 #python: if isinstance($ingred, IfExists):
72 #python: if not exists(ingred.filename): continue
73 169 my $child_cookable = $this->_create_cooking_tree($cookbook, $ingred, $cookables, $target);
74 168 push(@{$cookable->{children}}, $child_cookable);
75 }
76 }
77 181 return $cookable;
78 }
79  
80 ## die if tree has a loop
81 32 ▶sub check_cooking_tree {
Subroutine check_cooking_tree: called CC=3 SCAR=11.0
Pod undocumented
82 32 my ($this, $root) = @_;
83 32 ▶ return unless $root->{children};
Branch: 1 branch
BranchTrueFalseTotal
unless $root->{"children"} 0 32 32
84 32 my $route = [];
85 32 my $visited = {};
86 32 my $errmsg = $this->_check_cooking_tree($root, $route, $visited);
87 32 ▶ ! $errmsg or die "$root->{product}: $errmsg";
Branch: 1 branch
BranchTrueFalseTotal
not $errmsg or die qq[$root->{"product"}: $errmsg] 31 1 32
88 #assert $#route == -1;
89 #assert $#visited == -1;
90 }
91  
92 132 ▶sub _check_cooking_tree {
Subroutine _check_cooking_tree: called CC=7 SCAR=19.5
93 132 my ($this, $cooking, $route, $visited) = @_;
94 132 push(@$route, $cooking->{product});
95 132 $visited->{$cooking->{product}} = 1;
96 132 for my $child (@{$cooking->{children}}) {
97 186 my $prod = $child->{product};
98 186 ▶ if (exists($visited->{$prod})) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $visited->{$prod}) { } 1 185 186
elsif ($child->{'children'}) { } 100 85 185
99 1 my $i = 0;
100 1 for my $item (@$route) {
101 3 ▶ last if $item eq $child->{product};
Branch: 1 branch
BranchTrueFalseTotal
if $item eq $child->{"product"} 1 2 3
102 2 $i++;
103 }
104 1 my $len = @$route;
105 1 my @looped = @$route[$i..$len-1];
106 1 push(@looped, $child->{product});
107 1 my $s = join "->", @looped;
108 1 return "recipe is looped ($s).\n";
109 }
110 elsif ($child->{children}) {
111 #assert $child->isa(Cooking)
112 100 my $errmsg = $this->_check_cooking_tree($child, $route, $visited);
113 100 ▶ return $errmsg if $errmsg;
Branch: 1 branch
BranchTrueFalseTotal
if $errmsg 4 96 100
114 }
115 }
116 #assert $#route >= 0
117 127 my $prod = pop @$route;
118 #assert $prod eq $cooking->{product};
119 #assert exists $visited->{$prod}
120 127 delete $visited->{$prod};
121 127 return;
122 }
123  
124 31 ▶sub start_cooking {
Subroutine start_cooking: called CC=3 SCAR=11.2
Pod undocumented
125 31 my ($this, $target, @argv) = @_;
126 31 ▶ $target or die "start_cooking(): target is required.";
Branch: 1 branch
BranchTrueFalseTotal
$target or die "start_cooking(): target is required." 31 0 31
127 ## create tree of cookable object
128 31 my $root = $this->create_cooking_tree($target);
129 29 $this->check_cooking_tree($root);
130 #assert $root->isa(Cookable);
131 #assert $root->{product} eq $target;
132 29 ▶ ! $root->isa('Kook::Material') or
Branch: 1 branch
BranchTrueFalseTotal
$root->isa("Kook::Material") and die "${target}: is a material (= a file to which no recipe matched)." 0 29 29
133 die "$target: is a material (= a file to which no recipe matched).";
134 ## start cooking
135 29 $root->cook(1, \@argv);
136 }
137  
138  
139 ###
140 ### abstract class for Cooking and Material.
141 ###
142 package Kook::Cookable;
143  
144 0 ▶sub cook {
Subroutine cook: not called CC=1 SCAR=6.9
145 0 my ($this, $depth, $argv, $parent_mtime) = @_;
146 0 die "cook(): not implemented yet.";
147 }
148  
149 0 ▶sub has_product_file {
Subroutine has_product_file: not called CC=1 SCAR=6.9
150 0 my ($this) = @_;
151 0 die "has_product_file(): not implemented yet.";
152 }
153  
154 36 our $CONTENT_CHANGED = 3; # recipe is invoked, and product content is changed when recipe is FileRecipe
155 36 our $MTIME_UPDATED = 2; # file content of product is not changed (recipe may be invoked or not)
156 36 our $NOT_INVOKED = 1; # recipe is not invoked (= skipped), for example product is newer than all ingredients
157  
158  
159 ###
160 ### represents material file.
161 ###
162 package Kook::Material;
163 36 our @ISA = ('Cookable');
164  
165 36 ▶use Kook::Misc ('_debug');
Subroutine BEGIN: called CC=1 SCAR=0.0
166  
167 67 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
168 67 my ($class, $filename) = @_;
169 67 my $this = {
170 product => $filename,
171 };
172 67 return bless($this, $class);
173 }
174  
175 61 ▶sub cook {
Subroutine cook: called CC=1 SCAR=0.0
176 61 my ($this, $depth, $argv) = @_;
177 #assert -f $this->{product};
178 61 _debug("material '$this->{product}'", $depth);
179 61 return $NOT_INVOKED;
180 }
181  
182 33 ▶sub has_product_file {
Subroutine has_product_file: called CC=1 SCAR=0.0
183 33 my ($this) = @_;
184 33 return 1;
185 }
186  
187  
188 ###
189 ### represens recipe invocation. in other words, Recipe is 'definition', Cooking is 'execution'.
190 ###
191 package Kook::Cooking;
192 36 our @ISA = ('Cookable');
193 36 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
194 36 ▶use File::Temp ('tempfile');
Subroutine BEGIN: called CC=1 SCAR=0.0
195 36 ▶use File::Compare ('compare');
Subroutine BEGIN: called CC=1 SCAR=0.0
196  
197 36 ▶use Kook;
Subroutine BEGIN: called CC=1 SCAR=0.0
198 36 ▶use Kook::Misc ('_debug', '_trace', '_report_msg', '_report_cmd');
Subroutine BEGIN: called CC=1 SCAR=0.0
199  
200 115 ▶sub new {
Subroutine new: called CC=7 SCAR=20.7
201 115 my ($class, $target, $recipe) = @_;
202 115 my $product = $target;
203 115 ▶ my @ingreds = $recipe->{ingreds} ? @{$recipe->{ingreds}} : ();
Branch: 1 branch
BranchTrueFalseTotal
$recipe->{'ingreds'} ? : 108 7 115
204 0 ▶ my @byprods = $recipe->{byprods} ? @{$recipe->{byprods}} : ();
Branch: 1 branch
BranchTrueFalseTotal
$recipe->{'byprods'} ? : 0 115 115
205 0 ▶ my @coprods = $recipe->{coprods} ? @{$recipe->{coprods}} : ();
Branch: 1 branch
BranchTrueFalseTotal
$recipe->{'coprods'} ? : 0 115 115
206 115 ▶ my @spices = $recipe->{spices} ? @{$recipe->{spices}} : ();
Branch: 1 branch
BranchTrueFalseTotal
$recipe->{'spices'} ? : 4 111 115
207 115 my $m = [];
208 115 ▶ if ($recipe->{pattern}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recipe->{"pattern"}) 46 69 115
209 ## TODO: support if_exists()
210 46 my $pat = $recipe->{pattern};
211 46 ▶ $target =~ $pat or die "$target: not matched to '$pat'.";
Branch: 1 branch
BranchTrueFalseTotal
$target =~ /$pat/ or die "${target}: not matched to '${pat}'." 46 0 46
212 46 $m = [$&, $1, $2, $3, $4, $5, $6, $7, $8, $9];
213 46 @ingreds = map { s/\$\((\d+)\)/$m->[$1]/ge; $_ } @ingreds;
214 0 @byprods = map { s/\$\((\d+)\)/$m->[$1]/ge; $_ } @byprods;
215 0 @coprods = map { s/\$\((\d+)\)/$m->[$1]/ge; $_ } @coprods;
216 }
217 115 my $this = {
218 product => $product,
219 ingreds => \@ingreds,
220 byprods => \@byprods,
221 coprods => \@coprods,
222 ingred => $ingreds[0],
223 byprod => $byprods[0],
224 coprod => $coprods[0],
225 spices => \@spices,
226 recipe => $recipe,
227 "m" => $m,
228 cooked => undef,
229 argv => [],
230 children => [],
231 };
232 115 return bless($this, $class);
233 }
234  
235 19 ▶sub has_product_file {
Subroutine has_product_file: called CC=1 SCAR=0.0
236 19 my ($this) = @_;
237 19 return $this->{recipe}->{kind} eq "file";
238 }
239  
240 ##
241 ## pseudo-code:
242 ##
243 ## if CONENT_CHANGED in self.children:
244 ## invoke recipe
245 ## if new content is same as old:
246 ## return MTIME_UPDATED
247 ## else:
248 ## return CONTENT_CHANGED
249 ## elif MTIME_UPDATED in self.children:
250 ## # not invoke recipe function
251 ## touch product file
252 ## return MTIME_UPDATED
253 ## else:
254 ## # not invoke recipe function
255 ## return NOT_INVOKED
256 ##
257 119 ▶sub cook {
Subroutine cook: called CC=27 SCAR=33.3
258 119 my ($this, $depth, $argv) = @_;
259 119 my $is_file_recipe = $this->{recipe}->{kind} eq "file";
260 119 my $product = $this->{product};
261 ## return if already cooked
262 119 ▶ if ($this->{cooked}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"cooked"}) 17 102 119
263 17 _debug("pass $product (already cooked)", $depth);
264 17 return $this->{cooked};
265 }
266 ## get mtime of product file if it exists
267 102 _debug("begin $product", $depth);
268 102 ▶ my $product_mtime = $is_file_recipe && -f $product ? (stat $product)[9] : 0;
Branch: 1 branch
BranchTrueFalseTotal
$is_file_recipe && -f $product ? : 42 60 102
Condition100%3/3
$is_file_recipe and -f $product
!ll&&!rl&&r
243642
MC/DC100%2/2
$is_file_recipe and -f $product
$is_file_recipe -f $product
Truth table100%3/3
A and B
A= $is_file_recipeB= -f $product
ABresult
0X0
100
111
269 ## invoke ingredients' recipes
270 102 my $child_status = $NOT_INVOKED;
271 102 ▶ if ($this->{children}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"children"}) 102 0 102
272 102 for my $child (@{$this->{children}}) {
273 151 my $ret = $child->cook($depth+1, []);
274 #assert $ret;
275 151 ▶ $child_status = $ret if $ret > $child_status;
Branch: 1 branch
BranchTrueFalseTotal
if $ret > $child_status 56 95 151
276 151 ▶ if ($product_mtime && $ret == $NOT_INVOKED && $child->has_product_file()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($product_mtime and $ret == $Kook::Cookable::NOT_INVOKED and $child->has_product_file) 52 99 151
Condition83%5/6
$product_mtime and $ret == $Kook::Cookable::NOT_INVOKED and $child->has_product_file
!ll&&!rl&&r
99052
$product_mtime and $ret == $Kook::Cookable::NOT_INVOKED
!ll&&!rl&&r
792052
MC/DC66%2/3
$product_mtime and $ret == $Kook::Cookable::NOT_INVOKED and $child->has_product_file
$product_mtime $ret == $Kook::Cookable::NOT_INVOKED $child->has_product_file
Truth table75%3/4
A and B and C
A= $product_mtimeB= $ret == $Kook::Cookable::NOT_INVOKEDC= $child->has_product_file
ABCresult
0XX0
10X0
1100
1111
277 #assert -f $child->{product};
278 52 ▶ if ((stat $child->{product})[9] > $product_mtime) {
Branch: 1 branch
BranchTrueFalseTotal
if ((stat $child->{"product"})[9] > $product_mtime) 10 42 52
279 10 _trace("child file '$child->{product}' is newer than product '$this->{product}'.", $depth);
280 10 $child_status = $CONTENT_CHANGED;
281 }
282 }
283 }
284 }
285 ## there are some cases to skip recipe invocation (ex. product is newer than ingredients)
286 102 my $sig = $this->_signature();
287 102 ▶ if ($this->_can_skip($child_status, $depth)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->_can_skip($child_status, $depth)) 21 81 102
288 21 ▶ if ($child_status == $MTIME_UPDATED) {
Branch: 2 branches
BranchTrueFalseTotal
if ($child_status == $Kook::Cookable::MTIME_UPDATED) { } 4 17 21
elsif ($child_status == $Kook::Cookable::NOT_INVOKED) { } 17 0 17
289 #assert -f $product;
290 4 _report_msg("$product $sig", $depth);
291 4 _debug("touch and skip $product ($sig)", $depth);
292 4 _report_cmd("touch $product # skipped");
293 4 my $now = time();
294 4 utime $now, $now, $product;
295 4 return $this->{cooked} = $MTIME_UPDATED;
296 }
297 elsif ($child_status == $NOT_INVOKED) {
298 17 _debug("skip $product ($sig)", $depth);
299 17 return $this->{cooked} = $NOT_INVOKED;
300 }
301 else {
302 #assert $child_status == Kook::Cookable::CONTENT_CHANGED;
303 ## don't skip recipe invocation
304 }
305 }
306 ## invoke recipe function
307 81 my $ret;
308 my $tmp_filename;
309 81 eval {
310 ## if product file exists, rename it to temporary filename
311 81 ▶ if ($product_mtime) {
Branch: 1 branch
BranchTrueFalseTotal
if ($product_mtime) 21 60 81
312 21 my ($tmp_fh, $tmp_fname) = tempfile();
313 21 close $tmp_fh;
314 21 $tmp_filename = $tmp_fname;
315 21 rename $product, $tmp_filename;
316 21 _trace("product '$product' is renamed to '$tmp_filename'");
317 }
318 ## invoke recipe
319 81 ▶ my $s = $is_file_recipe ? 'create' : 'perform';
Branch: 1 branch
BranchTrueFalseTotal
$is_file_recipe ? : 57 24 81
320 81 _debug("$s $product ($sig)", $depth);
321 81 _report_msg("$product ($sig)", $depth);
322 81 $this->_invoke_recipe_with($argv);
323 ## check whether product file created or not
324 79 ▶ if ($is_file_recipe && ! $Kook::Config::NOEXEC && ! -f $product) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_file_recipe and not $Kook::Config::NOEXEC and not -f $product) 0 79 79
Condition83%5/6
$is_file_recipe and not $Kook::Config::NOEXEC and not -f $product
!ll&&!rl&&r
26530
$is_file_recipe and not $Kook::Config::NOEXEC
!ll&&!rl&&r
22453
MC/DC0%0/3
$is_file_recipe and not $Kook::Config::NOEXEC and not -f $product
$is_file_recipe not $Kook::Config::NOEXEC not -f $product
Truth table75%3/4
A and not(B) and not(C)
A= $is_file_recipeB= not $Kook::Config::NOEXECC= not -f $product
ABCresult
0XX0
10X0
1100
1111
325 0 die "$product: product not creatd ($sig).";
326 }
327 ## if new product file is same as old, return MTIME_UPDATED, else return CONTENT_CHANGED
328 79 my $msg;
329 79 ▶ if ($Kook::Config::COMPARE_CONTENTS && $product_mtime && compare($product, $tmp_filename) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Kook::Config::COMPARE_CONTENTS and $product_mtime and compare($product, $tmp_filename) == 0) { } 13 66 79
Condition83%5/6
$Kook::Config::COMPARE_CONTENTS and $product_mtime and compare($product, $tmp_filename) == 0
!ll&&!rl&&r
58813
$Kook::Config::COMPARE_CONTENTS and $product_mtime
!ll&&!rl&&r
05821
MC/DC66%2/3
$Kook::Config::COMPARE_CONTENTS and $product_mtime and compare($product, $tmp_filename) == 0
$Kook::Config::COMPARE_CONTENTS $product_mtime compare($product, $tmp_filename) == 0
Truth table75%3/4
A and B and C
A= $Kook::Config::COMPARE_CONTENTSB= $product_mtimeC= compare($product, $tmp_filename) == 0
ABCresult
0XX0
10X0
1100
1111
330 13 $ret = $MTIME_UPDATED;
331 13 $msg = "end $product (content not changed, mtime updated)";
332 }
333 else {
334 66 $ret = $CONTENT_CHANGED;
335 66 $msg = "end $product (content changed)";
336 }
337 79 _debug($msg, $depth);
338 };
339 81 ▶ if ($tmp_filename && -f $tmp_filename) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp_filename and -f $tmp_filename) 21 60 81
Condition66%2/3
$tmp_filename and -f $tmp_filename
!ll&&!rl&&r
60021
MC/DC50%1/2
$tmp_filename and -f $tmp_filename
$tmp_filename -f $tmp_filename
Truth table66%2/3
A and B
A= $tmp_filenameB= -f $tmp_filename
ABresult
0X0
100
111
340 21 unlink $tmp_filename;
341 21 _trace("temporary file '$tmp_filename' is removed.");
342 }
343 81 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 2 79 81
344 2 ▶ if ($product_mtime) {
Branch: 1 branch
BranchTrueFalseTotal
if ($product_mtime) 0 2 2
345 0 _report_msg("(remove $product because unexpected error thrown ($sig)", $depth);
346 0 ▶ unlink $product if -f $product;
Branch: 1 branch
BranchTrueFalseTotal
if -f $product 0 0 0
347 }
348 2 die $@;
349 }
350 79 return $this->{cooked} = $ret;
351 }
352  
353 106 ▶sub _signature {
Subroutine _signature: called CC=1 SCAR=0.0
354 106 my ($this) = @_;
355 106 return "recipe=".$this->{recipe}->{product}; # signature
356 }
357  
358 102 ▶sub _can_skip {
Subroutine _can_skip: called CC=6 SCAR=18.0
359 102 my ($this, $child_status, $depth) = @_;
360 102 my $product = $this->{product};
361 102 ▶ if ($Kook::Config::FORCED) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Kook::Config::FORCED) 5 97 102
362 #_trace("cannot skip: invoked forcedly.", $depth);
363 5 return 0;
364 }
365 97 ▶ if ($this->{recipe}->{kind} eq "task") {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"recipe"}{"kind"} eq "task") 23 74 97
366 23 _trace("cannot skip: task recipe should be invoked in any case.", $depth);
367 23 return 0;
368 }
369 74 ▶ unless (@{$this->{children}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$this->{"children"};}) 0 74 74
370 0 _trace("cannot skip: no children for product '$product'.", $depth);
371 0 return 0;
372 }
373 74 ▶ unless (-e $this->{product}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $this->{"product"}) 36 38 74
374 36 _trace("cannot skip: product '$product' not found.", $depth);
375 36 return 0;
376 }
377 #
378 38 ▶ if ($child_status == $CONTENT_CHANGED) {
Branch: 1 branch
BranchTrueFalseTotal
if ($child_status == $Kook::Cookable::CONTENT_CHANGED) 17 21 38
379 17 _trace("cannot skip: there is newer file in children than product '$product'.", $depth);
380 17 return 0;
381 }
382 #if ($child_status == $NOT_INVOKED) {
383 # my $timestamp = (stat $product)[9];
384 # for my $child (@{$this->{children}}) {
385 # my $child_has_product_file = ! ($child->{recipe} && $child->{recipe}->{kind} eq "task");
386 # if ($child_has_product_file && (stat $child->{product})[9] > $timestamp) {
387 # print("cannot skip: child '$child->{product}' is newer than product '$product'.\n");
388 # _trace("cannot skip: child '$child->{product}' is newer than product '$product'.", $depth);
389 # return 0;
390 # }
391 # }
392 #}
393 #
394 21 _trace("recipe for '$product' can be skipped.", $depth);
395 21 return 1;
396 }
397  
398 81 ▶sub _invoke_recipe_with {
Subroutine _invoke_recipe_with: called CC=3 SCAR=11.0
399 81 my ($this, $argv) = @_;
400 81 ▶ return unless $this->{recipe}->{method};
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"recipe"}{"method"} 17 64 81
401 64 $this->{argv} = $argv;
402 64 ▶ if (@{$this->{spices}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$this->{'spices'};}) { } 4 60 64
403 4 my ($opts, $rests) = $this->parse_cmdopts($argv);
404 #$this->{opts} = $opts;
405 #$this->{rests} = $rests;
406 2 $this->{recipe}->{method}->($this, $opts, $rests);
407 }
408 else {
409 60 $this->{recipe}->{method}->($this, undef, $argv);
410 }
411 }
412  
413 4 ▶sub parse_cmdopts {
Subroutine parse_cmdopts: called CC=1 SCAR=0.0
414 4 my ($this, $argv) = @_;
415 4 my $sig = $this->_signature();
416 4 my $parser = $Kook::Config::CMDOPT_PARSER_CLASS->new($this->{spices});
417 4 my ($opts, $rests) = $parser->parse($argv);
418 2 _trace("parse_cmdopts() ($sig): opts=$opts, rests=$rests");
419 2 return $opts, $rests;
420 }
421  
422  
423 36 1;
« blib/lib/Kook/Recipe.pm ↑ Summary blib/lib/Kook/Commands.pm »