Base/Singleton.pm

filter: Statementstmt 98.1% 53 / 54 Branchbran 77.7% 14 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 2 totaltotal 90.7% 78 / 86 CC 10 SCAR 8.9
CC
10
Cov
93%
make_singleton
4.0
new
4.0
__ANON__
2.1
CRAP 2.4
« Base/Clase.pm ↑ Summary Base.pm »
1 package Eixo::Base::Singleton;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Eixo::Base::Clase;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶sub make_singleton{
Subroutine make_singleton: called CC=4 SCAR=13.9
Pod undocumented
7 11 my ($clase, %args) = @_;
8  
9 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 11 ▶ return if(defined(&{$clase . '::SINGLETON'}));
Branch: 1 branch
BranchTrueFalseTotal
if defined &{$clase . '::SINGLETON';} 3 8 11
14  
15 8 my $instance = $clase->new(%args);
16  
17 8 ▶ *{$clase . '::SINGLETON'} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
18
19 2 return $instance;
20  
21 8 };
22  
23 8 ▶ *{$clase . '::AUTOLOAD'} = sub {
Subroutine __ANON__: called CC=2 SCAR=7.4
24  
25 28 my ($attribute) = our $AUTOLOAD =~ /\:(\w+)$/;
26  
27 28 ▶ if(my $method = $instance->can('__' . $attribute)){
Branch: 1 branch
BranchTrueFalseTotal
if (my $method = $instance->can('__' . $attribute)) { } 28 0 28
28
29 28 $instance->$method(@_[1..$#_]);
30
31 }
32 else{
33 0 die($AUTOLOAD . ' method not found');
34 }
35  
36 8 };
37
38 8 ▶ if($instance->can('initialize')){
Branch: 1 branch
BranchTrueFalseTotal
if ($instance->can("initialize")) 8 0 8
39  
40 8 $instance->initialize();
41 }
42  
43 8 ▶ if( ! $instance->can("DESTROY")){
Branch: 1 branch
BranchTrueFalseTotal
unless ($instance->can("DESTROY")) 5 3 8
44  
45 5 ▶ *{$clase . '::DESTROY'} = sub {}
Subroutine __ANON__: not called CC=1 SCAR=0.0
46  
47 5 }
48  
49 8 $instance;
50 }
51  
52 10 ▶sub new{
Subroutine new: called CC=4 SCAR=13.9
Pod undocumented
53 10 my ($class, @args) = @_;
54
55 10 ▶ my $self = ($class->can('SINGLETON')) ? $class->SINGLETON : undef;
Branch: 1 branch
BranchTrueFalseTotal
$class->can('SINGLETON') ? : 2 8 10
56
57 10 ▶ if($self){
Branch: 1 branch
BranchTrueFalseTotal
if ($self) { } 2 8 10
58 2 $self->__chainInitialize;
59  
60 2 $self->initialize(@args);
61 }
62 else{
63 8 $self = bless({}, $class);
64  
65 8 $self->__chainInitialize;
66
67 8 ▶ $self->__initialize if($self->can('__initialize'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("__initialize") 8 0 8
68  
69 }
70  
71  
72 10 $self;
73  
74 }
75  
76  
77  
78 21 ▶sub __createSetterGetter{
Subroutine __createSetterGetter: called CC=2 SCAR=6.9
79 21 my ($class, $attribute, $value) = @_;
80  
81 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
82  
83 21 ▶ unless(defined(&{$class . '::__' . $attribute})){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &{$class . '::__' . $attribute;}) 21 0 21
84  
85 21 ▶ *{$class . '::__' . $attribute} = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
86  
87 28 my ($self, $value) = @_;
88  
89 28 ▶ if(defined($value)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 7 21 28
90
91 7 $self->{$attribute} = $value;
92
93 7 $self;
94 }
95 else{
96
97 21 $self->{$attribute};
98 }
99  
100 21 };
101  
102 }
103 }
104  
105  
106 4 1;
« Base/Clase.pm ↑ Summary Base.pm »