blib/lib/Soo.pm

filter: Statementstmt 96.2% 77 / 80 Branchbran 59.0% 13 / 22 Conditioncond 40.0% 6 / 15 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 100% 16 / 16 Podpod n/a totaltotal 80.1% 113 / 141 CC 18 SCAR 14.8
CC
18
Cov
82%
__ANON__
9.9
__ANON__
6.5
__ANON__
3.3
CRAP 4.4
↑ Summary
1 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Soo;
5  
6 5 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 our $VERSION = '0.0.4';
9  
10  
11 5 ▶my $extends = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
12 5 my $parent = shift;
13 5 eval "require $parent;";
14 3 ▶ eval "package ${\scalar(caller)}; use parent -norequire, '$parent';";
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 };
16  
17 42 ▶my $has = sub {
Subroutine __ANON__: called CC=3 SCAR=11.9
18 42 my ($method, $meta) = @_;
19  
20 42 my $package = caller;
21  
22 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 42 ▶ if($method eq 'new') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "new") 0 42 42
25 5 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 0 ▶ *{"$package\::__soo_new_set__"} = $meta->{set} if($meta->{set});
Branch: 1 branch
BranchTrueFalseTotal
if $meta->{"set"} 0 0 0
27 0 return;
28 }
29  
30 49 ▶ my $fn = sub {
Subroutine __ANON__: called CC=8 SCAR=22.9
31 49 my $self = shift;
32  
33 49 ▶ my $set = $meta->{set} || sub {$_[1]};
Subroutine __ANON__: called CC=1 SCAR=0.6
Condition33%1/3
$meta->{'set'} || sub { $_[1]; }
l!l&&r!l&&!r
0490
MC/DC0%0/2
$meta->{'set'} || sub { $_[1]; }
$meta->{'set'} sub { $_[1]; }
Truth table33%1/3
A || B
A= $meta->{'set'}B= sub { $_[1]; }
ABresult
1X1
011
000
34  
35 49 my @call = caller(1);
36 49 ▶ @call = caller(0) unless(@call);
Branch: 1 branch
BranchTrueFalseTotal
unless @call 0 49 49
37 49 my ($callpkg, $callfn) = split(/::/, $call[3]);
38  
39 49 ▶ $self->__soo_get_set__($method, $set->($self, shift)) if(@_ && ( $meta->{rw} || ($callpkg eq 'Soo' && $callfn eq '__ANON__') ));
Branch: 1 branch
BranchTrueFalseTotal
if @_ and $meta->{"rw"} || $callpkg eq "Soo" && $callfn eq "__ANON__" 7 42 49
Condition44%4/9
@_ and $meta->{"rw"} || $callpkg eq "Soo" && $callfn eq "__ANON__"
!ll&&!rl&&r
4207
$meta->{"rw"} or $callpkg eq "Soo" and $callfn eq "__ANON__"
l!l&&r!l&&!r
070
$callpkg eq "Soo" and $callfn eq "__ANON__"
!ll&&!rl&&r
007
MC/DC25%1/4
@_ and $meta->{"rw"} || $callpkg eq "Soo" && $callfn eq "__ANON__"
@_ $meta->{"rw"} $callpkg eq "Soo" $callfn eq "__ANON__"
Truth table40%2/5
A and B or C and D
A= @_B= $meta->{"rw"}C= $callpkg eq "Soo"D= $callfn eq "__ANON__"
ABCDresult
0XXX0
100X0
10100
11XX1
10111
40  
41 49 ▶ $self->__soo_get_set__($method) || $meta->{default};
Branch: 1 branch
BranchTrueFalseTotal
$self->__soo_get_set__($method) or $meta->{"default"} 14 35 49
42 42 };
43  
44 # set method
45 42 *{"$package\::$method"} = $fn;
46  
47 5 };
48  
49 7 ▶my $new = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
50 7 my ($class, $params) = @_;
51  
52 7 my $self = bless({}, $class);
53  
54 # init/clean context
55 7 $self->__soo_init__;
56  
57 # constructor set
58 7 $params = $self->__soo_new_set__($params);
59  
60 # default behaviour of the constructor is receive a hash ref
61 7 $self->$_($params->{$_}) foreach (keys %$params);
62  
63 7 $self;
64 5 };
65  
66 11 ▶sub import {
Subroutine import: called CC=3 SCAR=11.1
67 11 my $package = caller;
68  
69 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
70  
71 # context, we will use this closure context to encapsulate data and provide readonly or readwrite capabilities
72 # the context is at class level and will differ object data by using the object ref as key
73 11 my $context = {};
74  
75 11 ▶ *{"$package\::__soo_init__"} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
76 7 $context->{+shift} = {};
77 11 };
78  
79 11 ▶ *{"$package\::__soo_get_set__"} = sub {
Subroutine __ANON__: called CC=6 SCAR=18.7
80 56 my $self = shift;
81 56 my $field = shift;
82  
83 56 ▶ return unless($field);
Branch: 1 branch
BranchTrueFalseTotal
unless $field 0 56 56
84  
85 56 my @call = caller(1);
86 56 ▶ @call = caller(0) unless(@call);
Branch: 1 branch
BranchTrueFalseTotal
unless @call 0 56 56
87 56 my ($callpkg, $callfn) = split(/::/, $call[3]);
88  
89 56 ▶ croak "Access denied for $callpkg\::$callfn" unless($callpkg eq 'Soo' && $callfn eq '__ANON__');
Branch: 1 branch
BranchTrueFalseTotal
unless $callpkg eq "Soo" and $callfn eq "__ANON__" 0 56 56
Condition33%1/3
$callpkg eq "Soo" and $callfn eq "__ANON__"
!ll&&!rl&&r
0056
MC/DC0%0/2
$callpkg eq "Soo" and $callfn eq "__ANON__"
$callpkg eq "Soo" $callfn eq "__ANON__"
Truth table33%1/3
A and B
A= $callpkg eq "Soo"B= $callfn eq "__ANON__"
ABresult
0X0
100
111
90  
91 56 ▶ $context->{$self}->{$field} = shift if(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 7 49 56
92  
93 56 $context->{$self}->{$field};
94 11 };
95  
96 # export extends
97 11 *{"$package\::extends"} = $extends;
98  
99 # export has
100 11 *{"$package\::has"} = $has;
101  
102 # default constructor
103 11 ▶ *{"$package\::new"} = $new unless(defined(*{"$package\::new"}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined *{"${package}::new";} 11 0 11
104  
105 # default constructor setter
106 11 ▶ *{"$package\::__soo_new_set__"} = sub {$_[1]} unless(defined(*{"$package\::__soo_new_set__"}));
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless defined *{"${package}::__soo_new_set__";} 11 0 11
107  
108 }
109  
110  
111 5 1;
112  
113 __END__
↑ Summary