| 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
| |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if (! defined($values)) { $values = { ingreds => $ingreds }; } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 42 | 50 | $pattern = Kook::Util::meta2rexp($product); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | ## kind | ||||||||||||||||||||||||||||
| 45 | 249 | my $kind = $hash{kind}; | |||||||||||||||||||||||||||
| 46 | 249 | ▶ | if ($kind) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 33 | ▶ | $kind eq "task" || $kind eq "file" or | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$kind eq "task" or $kind eq "file"
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"
| |||||||||||||||||||||||||||||
| 48 | die "'$kind': invalid kind (expected 'task' or 'file')."; | ||||||||||||||||||||||||||||
| 49 | } else { | ||||||||||||||||||||||||||||
| 50 | 216 | ▶ | $hash{kind} = $product =~ /^[-_a-z0-9]+$/ ? 'task' : 'file'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | ## desc | ||||||||||||||||||||||||||||
| 53 | 249 | ▶ | unless (defined $hash{desc}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 114 | my $desc = $DEFAULT_DESCS->{$product}; | |||||||||||||||||||||||||||
| 55 | 114 | ▶ | $hash{desc} = $desc if $desc; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 38 | 1; | |||||||||||||||||||||||||||