| 1 | ### | ||||||||||||
| 2 | ### $Release: 0.0100 $ | ||||||||||||
| 3 | ### $Copyright: copyright(c) 2009-2011 kuwata-lab.com all rights reserved. $ | ||||||||||||
| 4 | ### $License: MIT License $ | ||||||||||||
| 5 | ### | ||||||||||||
| 6 | |||||||||||||
| 7 | 37 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 37 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | |||||||||||||
| 11 | package Kook::Cookbook; | ||||||||||||
| 12 | 37 | ▶ | use Data::Dumper; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | 37 | ▶ | use Kook::Util; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 37 | ▶ | use Kook::Sandbox; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 37 | ▶ | use Kook::Misc ('_debug', '_trace'); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 37 | ▶ | use Kook::Util ('repr'); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | |||||||||||||
| 19 | 47 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 20 | 47 | my ($class, $bookname, $properties) = @_; | |||||||||||
| 21 | 47 | my $this = { | |||||||||||
| 22 | bookname => $bookname, | ||||||||||||
| 23 | specific_task_recipes => [], | ||||||||||||
| 24 | generic_task_recipes => [], | ||||||||||||
| 25 | specific_file_recipes => [], | ||||||||||||
| 26 | generic_task_recipes => [], | ||||||||||||
| 27 | materials => [], | ||||||||||||
| 28 | property_tuples => [], | ||||||||||||
| 29 | default => undef, | ||||||||||||
| 30 | desc => undef, | ||||||||||||
| 31 | }; | ||||||||||||
| 32 | 47 | $this = bless $this, $class; | |||||||||||
| 33 | 47 | ▶ | $this->load_file($bookname, $properties) if $bookname; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 34 | 47 | return $this; | |||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | 4 | ▶ | sub default_product { | ||||||||||
|
Subroutine
default_product: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 38 | 4 | my ($this) = @_; | |||||||||||
| 39 | #return $this->{context}->{kook_default_product}; | ||||||||||||
| 40 | #return $Kook::default_product; | ||||||||||||
| 41 | 4 | return $this->{default}; | |||||||||||
| 42 | } | ||||||||||||
| 43 | |||||||||||||
| 44 | 44 | ▶ | sub load_file { | ||||||||||
|
Subroutine
load_file: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||
| 45 | 44 | my ($this, $filename, $properties) = @_; | |||||||||||
| 46 | 44 | $this->{bookname} = $filename; | |||||||||||
| 47 | 44 | ▶ | -f $filename or die "$filename: not found.\n"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 48 | 44 | my $content = Kook::Util::read_file($filename); | |||||||||||
| 49 | 44 | $this->load($content, $filename, $properties); | |||||||||||
| 50 | } | ||||||||||||
| 51 | |||||||||||||
| 52 | 47 | ▶ | sub load { | ||||||||||
|
Subroutine
load: called CC=11 SCAR=24.1
Pod
undocumented
| |||||||||||||
| 53 | 47 | my ($this, $content, $bookname, $properties) = @_; | |||||||||||
| 54 | 47 | ▶ | $bookname = '(kook)' if ! $bookname; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | 47 | Kook::Sandbox::_eval($content, $bookname, $properties); | |||||||||||
| 56 | 47 | ▶ | ! $@ or die("[ERROR] kookbook has error:\n$@\n"); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 57 | 47 | $this->{property_tuples} = \@Kook::Sandbox::_property_tuples; | |||||||||||
| 58 | 47 | ▶ | $this->{default} = $Kook::Sandbox::kook_default if $Kook::Sandbox::kook_default; # for backward compatibility | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 59 | 47 | ▶ | $this->{desc} = $Kook::Sandbox::kook_desc if $Kook::Sandbox::kook_desc; # for backward compatibility | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 60 | 47 | my $kook = $Kook::Sandbox::kook; | |||||||||||
| 61 | 47 | ▶ | $this->{default} = $kook->{default} if $kook->{default}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 62 | 47 | ▶ | $this->{desc} = $kook->{desc} if $kook->{desc}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 63 | ## masks | ||||||||||||
| 64 | 47 | my $TASK = 0x0; | |||||||||||
| 65 | 47 | my $FILE = 0x1; | |||||||||||
| 66 | 47 | my $SPECIFIC = 0x0; | |||||||||||
| 67 | 47 | my $GENERIC = 0x2; | |||||||||||
| 68 | ## create recipes | ||||||||||||
| 69 | 47 | my $recipes = [ | |||||||||||
| 70 | [], # SPECIFIC | TASK | ||||||||||||
| 71 | [], # SPECIFIC | FILE | ||||||||||||
| 72 | [], # GENERIC | TASK | ||||||||||||
| 73 | [], # GNERIC | FILE | ||||||||||||
| 74 | ]; | ||||||||||||
| 75 | ## TODO: materials | ||||||||||||
| 76 | 47 | for my $recipe (@Kook::Sandbox::_recipes) { | |||||||||||
| 77 | 249 | ▶ | my $flag = $recipe->{kind} eq 'task' ? $TASK : $FILE; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 78 | 249 | ▶ | $flag = $flag | ($recipe->{pattern} ? $GENERIC : $SPECIFIC); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 79 | 249 | push @{$recipes->[$flag]}, $recipe; | |||||||||||
| 80 | } | ||||||||||||
| 81 | 47 | $this->{specific_task_recipes} = $recipes->[$SPECIFIC | $TASK]; ## TODO: use dict | |||||||||||
| 82 | 47 | $this->{specific_file_recipes} = $recipes->[$SPECIFIC | $FILE]; ## TODO: use dict | |||||||||||
| 83 | 47 | $this->{generic_task_recipes} = $recipes->[$GENERIC | $TASK]; ## TODO: support priority | |||||||||||
| 84 | 47 | $this->{generic_file_recipes} = $recipes->[$GENERIC | $FILE]; ## TODO: support priority | |||||||||||
| 85 | 47 | ▶ | if ($Kook::Config::DEBUG_LEVEL >= 2) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 86 | 2 | _trace("specific task recipes: " . $this->_repr_products($this->{specific_task_recipes})); | |||||||||||
| 87 | 2 | _trace("specific file recipes: " . $this->_repr_products($this->{specific_file_recipes})); | |||||||||||
| 88 | 2 | _trace("generic task recipes: " . $this->_repr_products($this->{generic_task_recipes})); | |||||||||||
| 89 | 2 | _trace("generic file recipes: " . $this->_repr_products($this->{generic_file_recipes})); | |||||||||||
| 90 | } | ||||||||||||
| 91 | } | ||||||||||||
| 92 | |||||||||||||
| 93 | 8 | ▶ | sub _repr_products { | ||||||||||
|
Subroutine
_repr_products: called CC=1 SCAR=0.0
| |||||||||||||
| 94 | 8 | my ($this, $recipes) = @_; | |||||||||||
| 95 | 8 | my @names = map { $_->{product} } @$recipes; | |||||||||||
| 96 | 8 | return repr(\@names); | |||||||||||
| 97 | } | ||||||||||||
| 98 | |||||||||||||
| 99 | 184 | ▶ | sub material_p { | ||||||||||
|
Subroutine
material_p: called CC=3 SCAR=13.1
Pod
undocumented
| |||||||||||||
| 100 | 184 | my ($this, $target) = @_; | |||||||||||
| 101 | 184 | for my $item (@{$this->{materials}}) { | |||||||||||
| 102 | 0 | ▶ | return 1 if $item eq $target; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 103 | } | ||||||||||||
| 104 | 184 | return 0; | |||||||||||
| 105 | } | ||||||||||||
| 106 | |||||||||||||
| 107 | 189 | ▶ | sub find_recipe { | ||||||||||
|
Subroutine
find_recipe: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||
| 108 | 189 | my ($this, $target) = @_; | |||||||||||
| 109 | my $recipes_tuple = [ | ||||||||||||
| 110 | $this->{specific_task_recipes}, | ||||||||||||
| 111 | $this->{specific_file_recipes}, | ||||||||||||
| 112 | $this->{generic_task_recipes}, | ||||||||||||
| 113 | $this->{generic_file_recipes}, | ||||||||||||
| 114 | 189 | ]; | |||||||||||
| 115 | 189 | for my $recipes (@$recipes_tuple) { | |||||||||||
| 116 | 581 | for my $recipe (@$recipes) { | |||||||||||
| 117 | 889 | ▶ | if ($recipe->match($target)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 118 | 120 | ▶ | my $recipe_name = $recipe->{name} || ''; | ||||||||||
|
Condition50%1/2
$recipe->{'name'} || ''
MC/DC0%0/1
$recipe->{'name'} || ''
$recipe->{'name'}
Truth table50%1/2
A
A= $recipe->{'name'}
| |||||||||||||
| 119 | 120 | _debug("Cookbook#find_recipe(): target=$target, func=$recipe_name, product=$recipe->{product}", 2); | |||||||||||
| 120 | 120 | return $recipe; | |||||||||||
| 121 | } | ||||||||||||
| 122 | } | ||||||||||||
| 123 | } | ||||||||||||
| 124 | } | ||||||||||||
| 125 | |||||||||||||
| 126 | |||||||||||||
| 127 | 37 | 1; | |||||||||||