blib/lib/Kook/Main.pm

filter: Statementstmt 70.2% 184 / 262 Branchbran 54.8% 57 / 104 Conditioncond 59.3% 19 / 32 MC/DCmcdc 42.8% 9 / 21 Subroutinesub 70.5% 24 / 34 Podpod 0.0% 0 / 3 totaltotal 64.2% 293 / 456 CC 69 SCAR 32.2
CC
69
Cov
65%
_invoke
132.0
_show_help_for
42.0
invoke
22.0
CRAP 24.9
↑ Summary blib/lib/Kook/Util.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 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 35 ▶no warnings 'uninitialized'; # suppress warning 'Use of uninitialized value'
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 package Kook::Main;
13 35 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 35 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 35 ▶use Kook;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 35 ▶use Kook::Util ('read_file');
Subroutine BEGIN: called CC=1 SCAR=0.0
18 35 ▶use Kook::Cookbook;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 35 ▶use Kook::Kitchen;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 33 ▶sub new {
Subroutine new: called CC=4 SCAR=14.0
Pod undocumented
22 33 my ($class, $argv, $command) = @_;
23 33 ▶ if (! $argv || ! @$argv) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($argv and @$argv) 2 31 33
Condition66%2/3
$argv and @$argv
!ll&&!rl&&r
0231
MC/DC50%1/2
$argv and @$argv
$argv @$argv
Truth table66%2/3
A and B
A= $argvB= @$argv
ABresult
0X0
100
111
24 2 my @a = @ARGV; # how to copy array?
25 2 $argv = \@a;
26 }
27 33 ▶ $command = basename($0) unless $command;
Branch: 1 branch
BranchTrueFalseTotal
unless $command 33 0 33
28 33 my $this = {
29 argv => $argv,
30 command => $command,
31 };
32 33 return bless $this, $class;
33 }
34  
35 0 ▶sub invoke {
Subroutine invoke: not called CC=1 SCAR=6.9
Pod undocumented
36 0 my ($this) = @_;
37 0 die "invoke(): not implemented yet.";
38 }
39  
40 0 ▶sub main {
Subroutine main: not called CC=1 SCAR=6.9
Pod undocumented
41 0 my ($this) = @_;
42 0 die "invoke(): not implemented yet.";
43 }
44  
45 25 ▶sub _load_property_file {
Subroutine _load_property_file: called CC=4 SCAR=19.2
46 25 my ($this, $filename) = @_;
47 25 ▶ $filename = $Kook::Config::PROPERTIES_FILENAME unless $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless $filename 25 0 25
48 25 my $props = {};
49 25 ▶ if (-f $filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $filename) 0 25 25
50 0 my $content = read_file($filename);
51 0 my $ret = eval("# line 1 \"$filename\"\n" . $content);
52 0 ▶ if ($ret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret) 0 0 0
53 0 my %tmp = (%$props, %$ret);
54 0 $props = \%tmp;
55 }
56 #map { $props->{$_} = $ret->{$_} } keys %$ret if $ret;
57 #@$props { keys %$ret } = values %$ret if $ret;
58 }
59 25 return $props;
60 }
61  
62  
63 package Kook::MainCommand;
64 35 our @ISA = ('Kook::Main');
65 35 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 35 ▶use Cwd ('realpath');
Subroutine BEGIN: called CC=1 SCAR=0.0
67  
68 35 ▶use Kook::Util ('repr');
Subroutine BEGIN: called CC=1 SCAR=0.0
69  
70 35 my $optdef_strs = [
71 "-h: help",
72 #"--help: help",
73 "-V: version",
74 "-D[N]: debug level (default: 1)",
75 "-q: quiet",
76 "-f file: kookbook",
77 "-F: forcedly",
78 "-n: not execute (dry run)",
79 "-l: list public recipes",
80 "-L: list all recipes",
81 "-R: search Kookbook in parent directory recursively",
82 "--name=value: property name and value",
83 "--name: property name and value(=True)",
84 ];
85  
86 33 ▶sub invoke {
Subroutine invoke: called CC=22 SCAR=30.9
87 33 my ($this) = @_;
88 ## parse command-line options
89 33 my $optparser = Kook::Util::CommandOptionParser->new($optdef_strs);
90 33 my ($opts, $longopts, $rests) = $optparser->parse2($this->{argv}, $this->{command});
91 #print "*** debug: opts=", Dumper($opts);
92 #print "*** debug: longopts=", Dumper($longopts);
93 #print "*** debug: rests=", Dumper($rests);
94 ## handle options
95 31 ▶ if ($opts->{h} || $longopts->{help} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"h"} or $longopts->{"help"} == 1) 1 30 31
Condition66%2/3
$opts->{"h"} or $longopts->{"help"} == 1
l!l&&r!l&&!r
1030
MC/DC50%1/2
$opts->{"h"} or $longopts->{"help"} == 1
$opts->{"h"} $longopts->{"help"} == 1
Truth table66%2/3
A or B
A= $opts->{"h"}B= $longopts->{"help"} == 1
ABresult
1X1
011
000
96 1 print "$this->{command} - build tool like Make, Rake, Ant, or Cook\n";
97 1 print $optparser->help();
98 1 return 0;
99 }
100 30 ▶ if ($opts->{V}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"V"}) 1 29 30
101 1 print $Kook::VERSION, "\n";
102 1 return 0;
103 }
104 29 ▶ if ($opts->{q}) { $Kook::Config::VERBOSE = 0; }
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"q"}) 1 28 29
105 29 ▶ if ($opts->{F}) { $Kook::Config::FORCED = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"F"}) 1 28 29
106 29 ▶ if ($opts->{n}) { $Kook::Config::NOEXEC = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"n"}) 1 28 29
107 29 ▶ if ($opts->{D}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"D"}) 3 26 29
108 3 my $v = $opts->{D};
109 3 ▶ $v =~ /^\d+$/ or die "-D$v: integer is required.\n";
Branch: 1 branch
BranchTrueFalseTotal
$v =~ /^\d+$/ or die "-D${v}: integer is required.\n" 3 0 3
110 3 $Kook::Config::DEBUG_LEVEL = 0 + $v;
111 }
112 ## find cookbook
113 29 ▶ my $bookname = $opts->{f} || $Kook::Config::COOKBOOK_FILENAME;
Condition66%2/3
$opts->{'f'} || $Kook::Config::COOKBOOK_FILENAME
l!l&&r!l&&!r
4250
MC/DC0%0/2
$opts->{'f'} || $Kook::Config::COOKBOOK_FILENAME
$opts->{'f'} $Kook::Config::COOKBOOK_FILENAME
Truth table66%2/3
A || B
A= $opts->{'f'}B= $Kook::Config::COOKBOOK_FILENAME
ABresult
1X1
011
000
114 29 my $bookpath = $bookname;
115 29 ▶ if ($opts->{R}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"R"}) 1 28 29
116 1 ▶ while (! -e $bookpath) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $bookpath) 2 1 3
117 2 my $parent = "../$bookpath";
118 2 ▶ last if realpath($parent) eq realpath($bookpath);
Branch: 1 branch
BranchTrueFalseTotal
if realpath($parent) eq realpath($bookpath) 0 2 2
119 2 $bookpath = $parent;
120 }
121 }
122 29 ▶ my $s = $opts->{f} ? '-f ' : '';
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'f'} ? : 4 25 29
123 29 ▶ -e $bookpath or die "$s$bookname: not found.\n";
Branch: 1 branch
BranchTrueFalseTotal
-e $bookpath or die "$s${bookname}: not found.\n" 26 3 29
124 26 ▶ -f $bookpath or die "$s$bookname: not a file.\n";
Branch: 1 branch
BranchTrueFalseTotal
-f $bookpath or die "$s${bookname}: not a file.\n" 25 1 26
125 ## change directory if cookbook is in parent directory
126 25 ▶ if ($bookname ne $bookpath) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bookname ne $bookpath) 1 24 25
127 1 my $path = substr($bookpath, 0, - length($bookname));
128 1 chdir $path;
129 }
130 ## property file
131 25 my $props = $this->_load_property_file();
132 25 ▶ map { $props->{$_} = $longopts->{$_} } keys %$longopts if %$longopts;
Branch: 1 branch
BranchTrueFalseTotal
if %$longopts 1 24 25
133 ## create cookbook
134 25 my $cookbook = Kook::Cookbook->new($bookname, $props);
135 ## list recipes
136 25 ▶ if ($opts->{l} || $opts->{L}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"l"} or $opts->{"L"}) 2 23 25
Condition100%3/3
$opts->{"l"} or $opts->{"L"}
l!l&&r!l&&!r
1123
MC/DC100%2/2
$opts->{"l"} or $opts->{"L"}
$opts->{"l"} $opts->{"L"}
Truth table100%3/3
A or B
A= $opts->{"l"}B= $opts->{"L"}
ABresult
1X1
011
000
137 2 $this->_list_recipes($cookbook, $opts);
138 2 return 0;
139 }
140 ## get default product if no argument
141 23 ▶ if (! @$rests) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$rests) 2 21 23
142 2 my $default_product = $cookbook->default_product();
143 2 ▶ unless ($default_product) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($default_product) 1 1 2
144 1 my $command = $this->{command};
145 1 print STDERR "*** $command: target is not given.\n";
146 1 print STDERR "*** '$command -l' or '$command -L' shows recipes and properties.\n";
147 1 print STDERR "*** (or set '\$kook->{default}' in your kookbook.)\n";
148 1 return 1;
149 }
150 1 $rests = [$default_product];
151 }
152 ## start cooking
153 22 my $kitchen = Kook::Kitchen->new($cookbook);
154 22 $kitchen->start_cooking(@$rests);
155 ##
156 18 return 0;
157 }
158  
159 2 ▶sub _list_recipes {
Subroutine _list_recipes: called CC=10 SCAR=23.3
160 2 my ($this, $cookbook, $opts) = @_;
161 2 my $show_all = $opts->{L};
162 2 my $format = $Kook::Config::RECIPE_LIST_FORMAT; # " %-20s: %s\n";
163 2 my $format2 = $Kook::Config::RECIPE_OPTS_FORMAT; # " %-20s %s\n";
164 ## find default recipe
165 2 my $default_recipe;
166 2 my $default = $cookbook->default_product();
167 2 ▶ if ($default) {
Branch: 1 branch
BranchTrueFalseTotal
if ($default) 2 0 2
168 2 $default_recipe = $cookbook->find_recipe($default);
169 2 ▶ if (! $default_recipe) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($default_recipe) 0 2 2
170 0 print STDOUT "*** \$kook->{default} = '$default': recipe not found.\n";
171 }
172 }
173 ## properties
174 2 print "Properties:\n";
175 2 for (@{$cookbook->{property_tuples}}) {
176 10 my ($name, $value, $desc) = @$_;
177 10 ▶ next if ! $show_all && $desc == -1;
Branch: 1 branch
BranchTrueFalseTotal
if not $show_all and $desc == -1 1 9 10
Condition100%3/3
not $show_all and $desc == -1
!ll&&!rl&&r
541
MC/DC100%2/2
not $show_all and $desc == -1
not $show_all $desc == -1
Truth table100%3/3
not(A) and B
A= not $show_allB= $desc == -1
ABresult
0X0
100
111
178 9 printf($format, $name, repr($value));
179 }
180 2 print "\n";
181 ## task and file recipes
182 2 my @task_recipes = ( @{$cookbook->{specific_task_recipes}}, @{$cookbook->{generic_task_recipes}} );
183 2 my @file_recipes = ( @{$cookbook->{specific_file_recipes}}, @{$cookbook->{generic_file_recipes}} );
184 2 ▶ my $kind = $default_recipe ? $default_recipe->{kind} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$default_recipe ? : 2 0 2
185 2 my $s = " (default=$default)";
186 2 my $title;
187 2 ▶ $title = "Task recipes" . ($kind eq 'task' ? $s : '') . ':';
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'task' ? : 2 0 2
188 2 $this->__list_recipes($title, \@task_recipes, $format, $format2, $show_all);
189 2 print "\n";
190 2 ▶ $title = "File recipes" . ($kind eq 'file' ? $s : '') . ':';
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'file' ? : 0 2 2
191 2 $this->__list_recipes($title, \@file_recipes, $format, $format2, $show_all);
192 2 print "\n";
193 ## tips
194 2 ▶ if (! $opts->{q}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"q"}) 2 0 2
195 2 my $tip = $this->get_tip($default);
196 2 print "(Tips: $tip)\n";
197 }
198 2 return 0;
199 }
200  
201 4 ▶sub __list_recipes {
Subroutine __list_recipes: called CC=9 SCAR=22.0
202 4 my ($this, $title, $recipes, $format, $format2, $show_all) = @_;
203 4 print $title, "\n";
204 4 for my $recipe (@$recipes) {
205 14 ▶ next unless $show_all || $recipe->{desc};
Branch: 1 branch
BranchTrueFalseTotal
unless $show_all or $recipe->{"desc"} 3 11 14
Condition100%3/3
$show_all or $recipe->{"desc"}
l!l&&r!l&&!r
743
MC/DC100%2/2
$show_all or $recipe->{"desc"}
$show_all $recipe->{"desc"}
Truth table100%3/3
A or B
A= $show_allB= $recipe->{"desc"}
ABresult
1X1
011
000
206 11 printf($format, $recipe->{product}, $recipe->{desc});
207 11 ▶ next unless $Kook::Config::VERBOSE;
Branch: 1 branch
BranchTrueFalseTotal
unless $Kook::Config::VERBOSE 0 11 11
208 11 ▶ next unless $recipe->{spices} && @{$recipe->{spices}};
Branch: 1 branch
BranchTrueFalseTotal
unless $recipe->{"spices"} and @{$recipe->{"spices"};} 9 2 11
Condition66%2/3
$recipe->{"spices"} and @{$recipe->{"spices"};}
!ll&&!rl&&r
902
MC/DC50%1/2
$recipe->{"spices"} and @{$recipe->{"spices"};}
$recipe->{"spices"} @{$recipe->{"spices"};}
Truth table66%2/3
A and B
A= $recipe->{"spices"}B= @{$recipe->{"spices"};}
ABresult
0X0
100
111
209 2 my $optparser = Kook::Util::CommandOptionParser->new($recipe->{spices});
210 2 for (@{$optparser->{helps}}) {
211 10 my ($opt, $desc) = @$_;
212 10 ▶ printf($format2, $opt, $desc) if $desc;
Branch: 1 branch
BranchTrueFalseTotal
if $desc 8 2 10
213 }
214 }
215 }
216  
217 35 our $TIPS = [
218 "you can set '\$kook->{default}' in your kookbook.",
219 "you can override properties with '--propname=propvalue'.",
220 "it is able to separate properties into 'Properties.pl' file.",
221 "try 'kk' command which is shortcat for 'plkook' command.",
222 "ingreds=>['\$(1).c', if_exists('\$(1).h')] is a friend of C programmer.",
223 #"'c%\"gcc $(ingred)\"' is more natural than '\"gcc %s\" % c.ingreds[0]'.",
224 ];
225  
226 2 ▶sub get_tip {
Subroutine get_tip: called CC=5 SCAR=19.1
227 2 my ($this, $default_product) = @_;
228 2 my $len = @$TIPS;
229 2 my $index = int(rand() * $len);
230 2 ▶ if ($default_product) {
Branch: 1 branch
BranchTrueFalseTotal
if ($default_product) { } 2 0 2
231 ## don't display tip about default product
232 2 ▶ $index ||= int(rand() * $len);
Condition33%1/3
$index ||= int((rand()) * $len)
l!l&&r!l&&!r
200
MC/DC0%0/2
$index ||= int((rand()) * $len)
$index int((rand()) * $len)
Truth table33%1/3
A ||= B
A= $indexB= int((rand()) * $len)
ABresult
1X1
011
000
233 2 ▶ $index ||= 1;
Condition50%1/2
$index ||= 1
l!l
20
MC/DC0%0/1
$index ||= 1
$index
Truth table50%1/2
A
A= $index
Aresult
11
00
234 }
235 else {
236 ## show tip about default product frequently
237 0 ▶ $index = 0 if rand() < 0.5;
Branch: 1 branch
BranchTrueFalseTotal
if rand() < "0.5" 0 0 0
238 }
239 2 return $TIPS->[$index];
240 }
241  
242 33 ▶sub main {
Subroutine main: called CC=2 SCAR=6.9
243 33 my ($this) = @_;
244 33 my $status;
245 33 eval {
246 33 $status = $this->invoke();
247 };
248 33 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 10 23 33
249 10 print STDERR $@;
250 10 $status = 1;
251 }
252 33 return $status;
253 }
254  
255  
256 package Kook::MainApplication;
257 35 our @ISA = ('Kook::Main');
258 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
259 35 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
260 35 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
261  
262 35 ▶use Kook::Misc ('_debug', '_trace');
Subroutine BEGIN: called CC=1 SCAR=0.0
263 35 ▶use Kook::Util ('repr', 'first');
Subroutine BEGIN: called CC=1 SCAR=0.0
264  
265 35 my $optdef_strs2 = [
266 "-h: help",
267 #"--help: help",
268 #"-V: version",
269 "-D[N]: debug level (default: 1)",
270 #"-q: quiet",
271 #"-f file: kookbook",
272 "-F: forcedly",
273 #"-l: list public recipes",
274 #"-L: list all recipes",
275 #"-n: not invoke (dry run)",
276 "-X file:",
277 "--name=value: property name and value",
278 "--name: property name and value(=1)",
279 ];
280  
281 0 ▶sub invoke {
Subroutine invoke: not called CC=2 SCAR=17.9
282 0 my ($this) = @_;
283 0 my $quiet = $Kook::Config::VERBOSE;
284 0 $Kook::Config::VERBOSE = 0;
285 0 eval {
286 0 $this->_invoke();
287 };
288 0 $Kook::Config::VERBOSE = $quiet;
289 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
290 }
291  
292 0 ▶sub _invoke {
Subroutine _invoke: not called CC=11 SCAR=48.8
293 0 my ($this) = @_;
294 ## parse command-line options
295 0 my $optparser = Kook::Util::CommandOptionParser->new($optdef_strs2);
296 0 my ($opts, $longopts, $rests) = $optparser->parse2($this->{argv}, $this->{command});
297 0 _trace("opts=" . repr($opts));
298 0 _trace("longopts=" . repr($longopts));
299 0 _trace("rests=" . repr($rests));
300 ## handle options
301 0 ▶ my $bookname = $opts->{X} or die "-X: script filename required.\n";
Branch: 1 branch
BranchTrueFalseTotal
my $bookname = $opts->{"X"} or die "-X: script filename required.\n" 0 0 0
302 0 $this->{command} = basename($bookname);
303 ## property file
304 0 my $props = $this->_load_property_file();
305 0 ▶ if (%$longopts) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$longopts) 0 0 0
306 0 map { $props->{$_} = $longopts->{$_} } keys %$longopts;
307 }
308 ## help
309 0 ▶ if ($opts->{h} || $longopts->{help} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"h"} or $longopts->{"help"} == 1) 0 0 0
Condition0%0/3
$opts->{"h"} or $longopts->{"help"} == 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"h"} or $longopts->{"help"} == 1
$opts->{"h"} $longopts->{"help"} == 1
Truth table0%0/3
A or B
A= $opts->{"h"}B= $longopts->{"help"} == 1
ABresult
1X1
011
000
310 0 my $target = $rests->[0];
311 0 $this->_show_help($bookname, $props, $target, $optparser);
312 0 return 0;
313 }
314 ## other options
315 #if ($opts->{V}) {
316 # print $Kook::RELEASE, "\n";
317 # return 0;
318 #}
319 #if ($opts->{q}) { $Kook::Config::VERBOSE = 0; }
320 0 ▶ if ($opts->{F}) { $Kook::Config::FORCED = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"F"}) 0 0 0
321 0 ▶ if ($opts->{D}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"D"}) 0 0 0
322 0 ▶ $opts->{D} =~ /^\d+$/ or die "-D$opts->{D}: integer is required.\n";
Branch: 1 branch
BranchTrueFalseTotal
$opts->{"D"} =~ /^\d+$/ or die qq[-D$opts->{"D"}: integer is required.\n] 0 0 0
323 0 $Kook::Config::DEBUG_LEVEL = 0 + $opts->{D};
324 }
325 ## create cookbook
326 0 my $cookbook = Kook::Cookbook->new($bookname, $props);
327 0 ▶ if (! @$rests) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$rests) 0 0 0
328 0 ▶ my $default_product = $cookbook->default_product() or
Branch: 1 branch
BranchTrueFalseTotal
my $default_product = $cookbook->default_product or die "sub-command is required (try '-h' to show all sub-commands).\n" 0 0 0
329 die "sub-command is required (try '-h' to show all sub-commands).\n";
330 0 $rests = [$default_product];
331 }
332 ## check whether recipe exists or not
333 0 my $target = $rests->[0];
334 0 my $recipes = $cookbook->{specific_task_recipes};
335 0 ▶ my $recipe = first { $_->{product} eq $target } @$recipes or
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
my $recipe = &first(sub { $_->{"product"} eq $target; } , @$recipes) or die "${target}: sub-command not found.\n" 0 0 0
336 die "$target: sub-command not found.\n";
337 ## start cooking
338 0 my $kitchen = Kook::Kitchen->new($cookbook);
339 0 $kitchen->start_cooking(@$rests);
340 ##
341 0 return 0;
342 }
343  
344 0 ▶sub _show_help {
Subroutine _show_help: not called CC=2 SCAR=17.9
345 0 my ($this, $bookname, $props, $target, $optparser) = @_;
346 0 my $cookbook = Kook::Cookbook->new($bookname, $props);
347 0 ▶ $target ? $this->_show_help_for($cookbook, $target)
Branch: 1 branch
BranchTrueFalseTotal
$target ? : 0 0 0
348 : $this->_show_help_all($cookbook, $optparser);
349 }
350  
351 0 ▶sub _show_help_for {
Subroutine _show_help_for: not called CC=6 SCAR=37.4
352 0 my ($this, $cookbook, $target) = @_;
353 0 my $recipes = $cookbook->{specific_task_recipes};
354 0 ▶ my $recipe = first { $_->{product} eq $target } @$recipes or
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
my $recipe = &first(sub { $_->{"product"} eq $target; } , @$recipes) or die "${target}: sub command not found.\n" 0 0 0
355 die "$target: sub command not found.\n";
356 0 print "$this->{command} $target - $recipe->{desc}\n";
357 0 ▶ if ($recipe->{spices} && @{$recipe->{spices}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recipe->{"spices"} and @{$recipe->{"spices"};}) 0 0 0
Condition0%0/3
$recipe->{"spices"} and @{$recipe->{"spices"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$recipe->{"spices"} and @{$recipe->{"spices"};}
$recipe->{"spices"} @{$recipe->{"spices"};}
Truth table0%0/3
A and B
A= $recipe->{"spices"}B= @{$recipe->{"spices"};}
ABresult
0X0
100
111
358 0 my $optparser = Kook::Util::CommandOptionParser->new($recipe->{spices});
359 0 for (@{$optparser->{helps}}) {
360 0 my ($opt, $desc) = @$_;
361 0 ▶ printf $Kook::Config::SUBCOMMANDS_FORMAT, $opt, $desc if $desc;
Branch: 1 branch
BranchTrueFalseTotal
if $desc 0 0 0
362 }
363 }
364 }
365  
366 0 ▶sub _show_help_all {
Subroutine _show_help_all: not called CC=3 SCAR=24.8
367 0 my ($this, $cookbook, $optparser) = @_;
368 0 my $recipes = $cookbook->{specific_task_recipes};
369 0 my $desc = $cookbook->{desc};
370 0 print "$this->{command} - $desc\n";
371 0 if (0) {
372 print "\n";
373 print "global-options:\n";
374 print $optparser->help();
375 }
376 0 print "\n";
377 0 print "sub-commands:\n";
378 0 for my $recipe (@$recipes) {
379 0 ▶ printf $Kook::Config::OPTION_HELP_FORMAT, $recipe->{product}, $recipe->{desc} if $recipe->{desc};
Branch: 1 branch
BranchTrueFalseTotal
if $recipe->{"desc"} 0 0 0
380 }
381 0 print "\n";
382 0 print "(Type '$this->{command} -h subcommand' to show options of sub-commands.)\n";
383 }
384  
385 0 ▶sub main {
Subroutine main: not called CC=1 SCAR=6.9
386 0 my ($this) = @_;
387 0 return $this->invoke();
388 }
389  
390  
391 35 1;
↑ Summary blib/lib/Kook/Util.pm »