| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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];
}
MC/DC0%0/2
$meta->{'set'} || sub {
$_[1];
}
$meta->{'set'}
sub {
$_[1];
}
Truth table33%1/3
A || B
A= $meta->{'set'}B= sub {
$_[1];
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 49 | my @call = caller(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 49 | ▶ | @call = caller(0) unless(@call); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition44%4/9
@_ and $meta->{"rw"} || $callpkg eq "Soo" && $callfn eq "__ANON__"
$meta->{"rw"} or $callpkg eq "Soo" and $callfn eq "__ANON__"
$callpkg eq "Soo" and $callfn eq "__ANON__"
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__"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 49 | ▶ | $self->__soo_get_set__($method) || $meta->{default}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 56 | my @call = caller(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 56 | ▶ | @call = caller(0) unless(@call); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$callpkg eq "Soo" and $callfn eq "__ANON__"
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__"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 56 | ▶ | $context->{$self}->{$field} = shift if(@_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||