| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | { | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | package OOP::Perlish::Class::Singleton; | ||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use OOP::Perlish::Class; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use base qw(OOP::Perlish::Class); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | sub _magic_constructor_arg_handler_singleton(@) | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 10 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_magic_constructor_arg_handler_singleton: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 10 | my ( $self, $opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 10 | my $key = 'return'; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 10 | my $singleton; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | ### Handle some magical arguments used for internal purposes | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 10 | ▶ | if( !exists( $opts->{_____oop_perlish_class__initialize_singleton} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | $singleton = $self->_singleton( %{$opts} ); | |||||||||||||||||||||||||||||||||||||||||
| 22 | 7 | return ( $key, [$singleton] ); | |||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | delete( $opts->{_____oop_perlish_class__initialize_singleton} ); | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | sub _singleton(@) | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_singleton: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | my ($proto, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | my $singleton = ${ $class . '::_SINGLETONREF' }; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | ▶ | use strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | ▶ | if( defined($singleton) && ref($singleton) && blessed($singleton) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $singleton and ref $singleton and builtin::blessed($singleton)
defined $singleton and ref $singleton
MC/DC33%1/3
defined $singleton and ref $singleton and builtin::blessed($singleton)
defined $singleton
ref $singleton
builtin::blessed($singleton)
Truth table50%2/4
A and B and C
A= defined $singletonB= ref $singletonC= builtin::blessed($singleton)
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | ▶ | $singleton->debug( 'Singleton of ' . $class . ' already initialized; NOT reinitialized!!' ) if( scalar keys %opts ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | return $singleton; | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | $singleton = $class->new( %opts, _____oop_perlish_class__initialize_singleton => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | ${ $class . '::_SINGLETONREF' } = $singleton; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | ▶ | use strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | return $singleton; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | __END__ | ||||||||||||||||||||||||||||||||||||||||||