mcoder.pm

filter: Statementstmt 97.0% 99 / 102 Branchbran 82.2% 51 / 62 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 95.4% 21 / 22 Podpod 0.0% 0 / 4 totaltotal 90.0% 171 / 190 CC 40 SCAR 18.6
CC
40
Cov
91%
export_accessor
18.2
export_proxy
7.2
import
6.0
CRAP 6.4
↑ Summary mcoder/array/calculated.pm »
1 package mcoder;
2  
3 6 our $VERSION = '0.10';
4  
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 our $debug;
10  
11 5 my %mcoder;
12  
13 12 ▶sub import {
Subroutine import: called CC=6 SCAR=17.9
14 12 shift;
15 12 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 16 12 28
16 16 my $kind=shift;
17 16 ▶ my @kind=(ref $kind eq 'ARRAY') ? @$kind : ($kind);
Branch: 1 branch
BranchTrueFalseTotal
ref $kind eq 'ARRAY' ? : 4 12 16
18 16 my $args=shift;
19 16 ▶ my @args=(ref $args eq 'ARRAY') ? @$args : ($args);
Branch: 1 branch
BranchTrueFalseTotal
ref $args eq 'ARRAY' ? : 9 7 16
20  
21 16 for my $k (@kind) {
22 23 ▶ exists $mcoder{$k} or
Branch: 1 branch
BranchTrueFalseTotal
exists $mcoder{$k} or croak("unknow mcoder type '${k}'") 23 0 23
23 croak "unknow mcoder type '$k'";
24 23 &{$mcoder{$k}}($k, @args)
25 }
26 }
27 }
28  
29 2 ▶sub export_proxy {
Subroutine export_proxy: called CC=7 SCAR=19.7
Pod undocumented
30 2 shift;
31 2 my $delegate=shift;
32 2 my $caller=caller(1);
33 2 foreach my $m (@_) {
34 4 ▶ my @m=(ref($m) eq 'HASH') ? %$m : ($m, $m);
Branch: 1 branch
BranchTrueFalseTotal
ref $m eq 'HASH' ? : 0 4 4
35 4 ▶ while (@m) {
Branch: 1 branch
BranchTrueFalseTotal
if (@m) 4 4 8
36 4 my $name=shift @m;
37 4 my $method=shift @m;
38 4 ▶ $method=~/^\w+$/ and $method.='(@_)';
Branch: 1 branch
BranchTrueFalseTotal
$method =~ /^\w+$/ and $method .= '(@_)' 4 0 4
39 4 my $def=
40 "sub ${caller}::${name} { shift->$delegate->$method }";
41 4 ▶ carp "mcoder def>> $def" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $mcoder::debug 0 4 4
42 4 ▶ eval $def;
Subroutine run: called CC=1 SCAR=0.0
Subroutine talk: called CC=1 SCAR=0.0
43 4 ▶ $@ and croak "proxy method definition failed: $@";
Branch: 1 branch
BranchTrueFalseTotal
$@ and croak("proxy method definition failed: $@") 0 4 4
44 }
45 }
46 }
47  
48 18 ▶sub export_accessor {
Subroutine export_accessor: called CC=18 SCAR=29.0
Pod undocumented
49 18 my $type=shift;
50 18 my $caller=caller(1);
51 18 foreach my $m (@_) {
52 26 ▶ my @m=(ref($m) eq 'HASH') ? %$m : ($m, $m);
Branch: 1 branch
BranchTrueFalseTotal
ref $m eq 'HASH' ? : 0 26 26
53 26 ▶ while (@m) {
Branch: 1 branch
BranchTrueFalseTotal
if (@m) 26 26 52
54 26 my $name=shift @m;
55 26 my $attr=shift @m;
56 26 ▶ $attr=~/^\w+$/ and $attr="{q(".$attr.")}";
Branch: 1 branch
BranchTrueFalseTotal
$attr =~ /^\w+$/ and $attr = '{q(' . $attr . ')}' 26 0 26
57 26 my $def;
58 # if ($type eq 'accessor') {
59 # $def="\@_ > 1 ? shift->$attr=\$_[0] : shift->$attr";
60 # }
61 # elsif
62 26 ▶ if ($type eq 'get') {
Branch: 11 branches
BranchTrueFalseTotal
if ($type eq 'get') { } 7 19 26
elsif ($type eq 'array_get') { } 1 18 19
elsif ($type eq 'set') { } 5 13 18
elsif ($type eq 'array_set') { } 2 11 13
elsif ($type eq 'bool_set') { } 3 8 11
elsif ($type eq 'calculated') { } 1 7 8
elsif ($type eq 'array_calculated') { } 1 6 7
elsif ($type eq 'delete') { } 1 5 6
elsif ($type eq 'undef') { } 1 4 5
elsif ($type eq 'bool_unset') { } 3 1 4
elsif ($type eq 'virtual') { } 1 0 1
63 7 $def="\$_[0]->$attr";
64 }
65 elsif ($type eq 'array_get') {
66 1 $def="\@{(\$_[0]->$attr)||[]}";
67 }
68 elsif ($type eq 'set') {
69 5 $name='set_'.$name;
70 5 $def="\$_[0]->$attr=\$_[1]";
71 }
72 elsif ($type eq 'array_set') {
73 2 $name='set_'.$name;
74 2 $def="my \$t=shift; \$t->$attr=\\\@_";
75 }
76 elsif ($type eq 'bool_set') {
77 3 $name='set_'.$name;
78 3 $def="\$_[0]->$attr=(\@_>1 ? \$_[1] : 1)";
79 }
80 elsif ($type eq 'calculated') {
81 1 $def="my \$t=shift; "
82 ."if (defined \$t->$attr) { \$t->$attr } "
83 ."else { \$t->$attr=\$t->_calculate_$name }";
84 }
85 elsif ($type eq 'array_calculated') {
86 1 $def="my \$t=shift; "
87 ."if (defined \$t->$attr) { \@{\$t->$attr} } "
88 ."else { my \@a=\$t->_calculate_$name; \$t->$attr=\\\@a; \@a }";
89 }
90 elsif ($type eq 'delete') {
91 1 $name='delete_'.$name;
92 1 $def="my \$t=shift; exists \$t->$attr and delete \$t->$attr";
93 }
94 elsif ($type eq 'undef') {
95 1 $name='undef_'.$name;
96 1 $def="\$_[0]->$attr=undef";
97 }
98 elsif ($type eq 'bool_unset') {
99 3 $name='unset_'.$name;
100 3 $def="\$_[0]->$attr=undef";
101 }
102 elsif ($type eq 'virtual') {
103 1 $def=qq(Carp::croak("undefined virtual method called (".\$_[0]."->$name)"))
104 }
105 else {
106 0 die "internal error (unknow type $type)"
107 }
108 26 my $def1= "sub ${caller}::${name} { $def }";
109 26 ▶ carp "mcoder def >> $def1" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $mcoder::debug 0 26 26
110 0 ▶ eval $def1;
Subroutine delete_weight: called CC=2 SCAR=6.9
Subroutine dont: called CC=1 SCAR=0.0
Subroutine is_good: called CC=1 SCAR=0.0
Subroutine runner: called CC=1 SCAR=0.0
Subroutine set_is_good: called CC=2 SCAR=6.9
Subroutine set_runner: not called CC=1 SCAR=0.0
Subroutine set_sons: called CC=1 SCAR=0.0
Subroutine set_walker: called CC=1 SCAR=0.0
Subroutine set_weight: called CC=1 SCAR=0.0
Subroutine sons: called CC=2 SCAR=6.9
Subroutine undef_weight: called CC=1 SCAR=0.0
Subroutine unset_is_good: called CC=1 SCAR=0.0
Branch: 4 branches
BranchTrueFalseTotal
exists $t->{"weight"} and delete $t->{"weight"} 1 2 3
@_ > 1 ? : 1 2 3
if (defined $t->{'sons'}) { } 2 1 3
if (defined $t->{'weight'}) { } 2 3 5
111 26 ▶ $@ and croak "$type method definition failed $@";
Branch: 1 branch
BranchTrueFalseTotal
$@ and croak("$type method definition failed $@") 0 26 26
112 }
113 }
114 }
115  
116 3 ▶sub export_new {
Subroutine export_new: called CC=4 SCAR=13.9
Pod undocumented
117 3 shift;
118 5 my $caller=caller(1);
119 5 foreach my $name (@_) {
120 6 my $def="sub ${caller}::${name} { my \$c=shift; "
121 ."\@_ & 1 "
122 ."and croak q(Odd number of elements passed to constructor); "
123 ."bless {\@_}, \$c }";
124 3 ▶ carp "mcoder def >> $def" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $mcoder::debug 0 4 4
125 4 eval $def;
126 5 ▶ $@ and croak "constructor method definition failed $@";
Branch: 1 branch
BranchTrueFalseTotal
$@ and croak("constructor method definition failed $@") 2 3 5
127 }
128 }
129  
130 4 ▶sub export_virtual {
Subroutine export_virtual: called CC=1 SCAR=0.0
Pod undocumented
131 3 shift;
132
133 }
134  
135 5 %mcoder=( proxy => \&export_proxy,
136 # accesor => \&export_accesor,
137 set => \&export_accessor,
138 array_set => \&export_accessor,
139 get => \&export_accessor,
140 array_get => \&export_accessor,
141 bool_unset => \&export_accessor,
142 bool_set => \&export_accessor,
143 calculated => \&export_accessor,
144 array_calculated => \&export_accessor,
145 delete => \&export_accessor,
146 undef => \&export_accessor,
147 new => \&export_new,
148 virtual => \&export_accessor );
149  
150 5 1;
151 __END__
↑ Summary mcoder/array/calculated.pm »