blib/lib/Kook/Recipe.pm

filter: Statementstmt 84.2% 32 / 38 Branchbran 75.0% 18 / 24 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 75.6% 56 / 74 CC 14 SCAR 25.2
CC
14
Cov
78%
new
16.7
match
2.0
BEGIN
1.0
CRAP 12.5
« blib/lib/Kook/Util.pm ↑ Summary blib/lib/Kook/Kitchen.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 38 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 38 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 package Kook::Recipe;
12 38 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 38 our $DEFAULT_DESCS = {
15 "all" => "cook all products",
16 "clean" => "remove by-products",
17 "clear" => "remove products and by-products",
18 "help" => "show help",
19 "install" => "install product",
20 "setup" => "setup configuration",
21 "test" => "do test",
22 "uninstall" => "uninstall product",
23 };
24  
25 249 ▶sub new {
Subroutine new: called CC=13 SCAR=28.2
Pod undocumented
26 249 my ($class, $product, $ingreds, $values) = @_;
27 249 ▶ if (ref($ingreds) eq 'ARRAY') { # short notation
Branch: 2 branches
BranchTrueFalseTotal
if (ref $ingreds eq 'ARRAY') { } 7 242 249
elsif (ref $ingreds eq 'HASH') { } 242 0 242
28 0 ▶ if (! defined($values)) { $values = { ingreds => $ingreds }; }
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $values) { } 0 7 7
elsif (ref $values eq 'HASH') { } 7 0 7
29 7 elsif (ref($values) eq 'HASH') { $values->{'ingreds'} = $ingreds; }
30 0 else { die "Recipe->new(): invalid datatype for 3rd argument."; }
31 }
32 elsif (ref($ingreds) eq 'HASH') { # normal notation
33 242 $values = $ingreds;
34 }
35 else {
36 0 die "Recipe->new(): invalid datatype for 2nd argument.";
37 }
38 249 my %hash = %$values;
39 ## pattern;
40 249 my $pattern;
41 249 ▶ if (Kook::Util::has_metachar($product)) {
Branch: 1 branch
BranchTrueFalseTotal
if (Kook::Util::has_metachar($product)) 50 199 249
42 50 $pattern = Kook::Util::meta2rexp($product);
43 }
44 ## kind
45 249 my $kind = $hash{kind};
46 249 ▶ if ($kind) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind) { } 33 216 249
47 33 ▶ $kind eq "task" || $kind eq "file" or
Branch: 1 branch
BranchTrueFalseTotal
$kind eq "task" or $kind eq "file" or die "'${kind}': invalid kind (expected 'task' or 'file')." 33 0 33
Condition33%1/3
$kind eq "task" or $kind eq "file"
l!l&&r!l&&!r
0330
MC/DC0%0/2
$kind eq "task" or $kind eq "file"
$kind eq "task" $kind eq "file"
Truth table33%1/3
A or B
A= $kind eq "task"B= $kind eq "file"
ABresult
1X1
011
000
48 die "'$kind': invalid kind (expected 'task' or 'file').";
49 } else {
50 216 ▶ $hash{kind} = $product =~ /^[-_a-z0-9]+$/ ? 'task' : 'file';
Branch: 1 branch
BranchTrueFalseTotal
$product =~ /^[-_a-z0-9]+$/ ? : 122 94 216
51 }
52 ## desc
53 249 ▶ unless (defined $hash{desc}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $hash{"desc"}) 114 135 249
54 114 my $desc = $DEFAULT_DESCS->{$product};
55 114 ▶ $hash{desc} = $desc if $desc;
Branch: 1 branch
BranchTrueFalseTotal
if $desc 0 114 114
56 }
57 ##
58 my $this = {
59 product => $product,
60 pattern => $pattern,
61 kind => delete $hash{kind},
62 ingreds => delete $hash{ingreds},
63 byprods => delete $hash{byprods}, # not used
64 coprods => delete $hash{coprods}, # not used
65 desc => delete $hash{desc},
66 spices => delete $hash{spices},
67 method => delete $hash{method},
68 249 };
69 249 ▶ if (%hash) {
Branch: 1 branch
BranchTrueFalseTotal
if (%hash) 0 249 249
70 0 my $keys = join ',', map { "'$_'" } keys %hash;
71 0 die "$keys: unknown keys for recipe()."
72 }
73 ##
74 249 return bless($this, $class);
75 }
76  
77 889 ▶sub match {
Subroutine match: called CC=2 SCAR=6.9
Pod undocumented
78 889 my ($this, $target_product) = @_;
79 return $this->{pattern} ? ($target_product =~ $this->{pattern})
80 889 ▶ : ($target_product eq $this->{product});
Branch: 1 branch
BranchTrueFalseTotal
$this->{'pattern'} ? : 121 768 889
81 }
82  
83  
84 38 1;
« blib/lib/Kook/Util.pm ↑ Summary blib/lib/Kook/Kitchen.pm »