| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 50 | |||||||||||
| 51 | 7 | ▶ | if($self){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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; | |||||||||