NG/Class.pm

filter: Statementstmt 70.1% 47 / 67 Branchbran 14.2% 2 / 14 Conditioncond 40.0% 2 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 75.0% 9 / 12 Podpod 100% 1 / 1 totaltotal 60.7% 62 / 102 CC 12 SCAR 22.9
CC
12
Cov
59%
__ANON__
20.0
__ANON__
20.0
def
9.5
CRAP 9.9
« NG/EMail.pm ↑ Summary NG/DB.pm »
1 package NG::Class;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head2 def
7 def_class Animal => ['sex', 'leg_color'] => {
8 sound => sub { .... },
9 run => sub { .... },
10 };
11
12 def_class Dog => Animal => ['head_color'] => {
13 eat => sub { ... },
14 run => sub { ... }, # override method
15 };
16
17 my $x = Dog->new;
18 $x->eat('bone');
19 =cut
20 5 ▶sub def {
Subroutine def: called CC=6 SCAR=22.5
Pod documented
21 5 my $class = shift;
22 5 my $methods = pop;
23 5 my $attrs = pop;
24 5 ▶ my $parent = shift || 'NG::Object';
Condition100%2/2
shift() || 'NG::Object'
l!l
23
MC/DC100%1/1
shift() || 'NG::Object'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
25
26  
27 5 eval "package $class";
28 1 ▶ eval "use $parent";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
29 5 ▶ if( $parent ne 'undef' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent ne "undef") 5 0 5
30 5 *t = eval('*'.$class.'::ISA');
31 5 *t = [$parent];
32 }
33  
34 5 for my $method ( keys %{$methods} ) {
35 28 ▶ if(ref($methods->{$method}) eq 'CODE'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $methods->{$method} eq "CODE") 28 0 28
36 28 *t = eval('*'.$class.'::'.$method);
37 28 *t = $methods->{$method};
38 }
39 }
40  
41 5 for my $attr ( @{$attrs} ) {
42 1 *t = eval('*'.$class.'::'.$attr);
43 0 ▶ *t = sub :lvalue {
Subroutine __ANON__: not called CC=1 SCAR=6.9
44 0 shift->{$attr};
45 1 };
46 }
47  
48 5 *t = eval('*'.$class.'::meta');
49 0 ▶ *t = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
50 0 my (@attr_list, @method_list, %seen);
51 0 ▶ if( $parent ne 'undef' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent ne "undef") 0 0 0
52 0 ▶ push @attr_list, @{ $parent->meta->{attrs} } if $parent->meta->{attrs};
Branch: 1 branch
BranchTrueFalseTotal
if $parent->meta->{"attrs"} 0 0 0
53 0 ▶ push @method_list, @{ $parent->meta->{methods} } if $parent->meta->{methods};
Branch: 1 branch
BranchTrueFalseTotal
if $parent->meta->{"methods"} 0 0 0
54 }
55 0 push @attr_list, @{$attrs};
56 0 push @method_list, keys %{$methods};
57 0 return { attrs => [ grep { not $seen{$_}++ } @attr_list ],
58 0 methods => [ grep { not $seen{$_}++ } @method_list ],
59 };
60 5 };
61  
62 5 *t = eval('*'.$class.'::new');
63 0 ▶ *t = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
64 0 my ($class, @args) = @_;
65 0 ▶ push @args, '' if $#args % 2 == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $#args % 2 == 0 0 0 0
66 0 ▶ my $o = bless {@args}, ref $class || $class;
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
67 0 ▶ if(defined $methods->{build}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $methods->{"build"}) 0 0 0
68 0 $o->build(@args);
69 }
70 0 $o;
71 }
72  
73 5 }
74  
75 1 1;
« NG/EMail.pm ↑ Summary NG/DB.pm »