Class/Singleton.pm

filter: Statementstmt 98.0% 49 / 50 Branchbran 100% 6 / 6 Conditioncond 55.5% 5 / 9 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 88.8% 72 / 81 CC 7 SCAR 10.7
CC
7
Cov
92%
_singleton
6.1
_magic_constructor_arg_handler_singleton
2.0
BEGIN
1.0
CRAP 2.9
« Class/Abstract.pm ↑ Summary Class/UnitTests/Meta.pm »
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
BranchTrueFalseTotal
if (not exists $opts->{'_____oop_perlish_class__initialize_singleton'}) { } 7 3 10
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
l!l&&r!l&&!r
300
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if (defined $singleton and ref $singleton and builtin::blessed($singleton)) { } 2 1 3
Condition66%4/6
defined $singleton and ref $singleton and builtin::blessed($singleton)
!ll&&!rl&&r
102
defined $singleton and ref $singleton
!ll&&!rl&&r
102
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)
ABCresult
0XX0
10X0
1100
1111
40 2 ▶ $singleton->debug( 'Singleton of ' . $class . ' already initialized; NOT reinitialized!!' ) if( scalar keys %opts );
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 1 1 2
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__
« Class/Abstract.pm ↑ Summary Class/UnitTests/Meta.pm »