Base/Singleton.pm

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