Class/Multiton.pm

filter: Statementstmt 95.0% 38 / 40 Branchbran 70.0% 7 / 10 Conditioncond 53.3% 8 / 15 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 88.8% 8 / 9 Podpod n/a totaltotal 76.8% 63 / 82 CC 11 SCAR 20.5
CC
11
Cov
82%
_singleton
12.6
_multiton_key
2.0
BEGIN
1.0
CRAP 7.7
« Class/Accessor.pm ↑ Summary Class/Abstract.pm »
1 #!/usr/bin/perl
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 {
5 package OOP::Perlish::Class::Multiton;
6 2 ▶ use OOP::Perlish::Class::Singleton;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶ use base qw(OOP::Perlish::Class::Singleton);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶ sub _multiton_key(@) { return '___STUB___' }
Subroutine _multiton_key: not called CC=1 SCAR=6.9
11  
12 sub _singleton(@)
13 4 ▶ {
Subroutine _singleton: called CC=11 SCAR=25.3
14 4 my ($self, %opts) = @_;
15 4 ▶ my $class = ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
400
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
16  
17 4 ▶ my $multiton_name = $opts{$self->_multiton_key()} if( exists( $opts{$self->_multiton_key()} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{$self->_multiton_key} 4 0 4
18 4 ▶ return unless($multiton_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $multiton_name 0 4 4
19  
20  
21 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 ▶ ${ $class . '::____MULTITON_REFS' } = {} unless(defined(${ $class . '::____MULTITON_REFS' }) && ref(${ $class . '::____MULTITON_REFS' }) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless defined ${$class . '::____MULTITON_REFS';} and ref ${$class . '::____MULTITON_REFS';} eq "HASH" 1 3 4
Condition66%2/3
defined ${$class . '::____MULTITON_REFS';} and ref ${$class . '::____MULTITON_REFS';} eq "HASH"
!ll&&!rl&&r
103
MC/DC50%1/2
defined ${$class . '::____MULTITON_REFS';} and ref ${$class . '::____MULTITON_REFS';} eq "HASH"
defined ${$class . '::____MULTITON_REFS';} ref ${$class . '::____MULTITON_REFS';} eq "HASH"
Truth table66%2/3
A and B
A= defined ${$class . '::____MULTITON_REFS';}B= ref ${$class . '::____MULTITON_REFS';} eq "HASH"
ABresult
0X0
100
111
23 4 my $multiton_refs = ${ $class . '::____MULTITON_REFS' };
24 2 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26  
27 4 ▶ if( defined($multiton_refs) && ref($multiton_refs) eq 'HASH' && exists( $multiton_refs->{$multiton_name} ) && blessed( $multiton_refs->{$multiton_name} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $multiton_refs and ref $multiton_refs eq 'HASH' and exists $multiton_refs->{$multiton_name} and builtin::blessed($multiton_refs->{$multiton_name})) { } 2 2 4
Condition55%5/9
defined $multiton_refs and ref $multiton_refs eq "HASH" and exists $multiton_refs->{$multiton_name} and builtin::blessed($multiton_refs->{$multiton_name})
!ll&&!rl&&r
202
defined $multiton_refs and ref $multiton_refs eq "HASH" and exists $multiton_refs->{$multiton_name}
!ll&&!rl&&r
022
defined $multiton_refs and ref $multiton_refs eq "HASH"
!ll&&!rl&&r
004
MC/DC25%1/4
defined $multiton_refs and ref $multiton_refs eq "HASH" and exists $multiton_refs->{$multiton_name} and builtin::blessed($multiton_refs->{$multiton_name})
defined $multiton_refs ref $multiton_refs eq "HASH" exists $multiton_refs->{$multiton_name} builtin::blessed($multiton_refs->{$multiton_name})
Truth table40%2/5
A and B and C and D
A= defined $multiton_refsB= ref $multiton_refs eq "HASH"C= exists $multiton_refs->{$multiton_name}D= builtin::blessed($multiton_refs->{$multiton_name})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
28 2 ▶ $self->debug( 'Singleton of ' . $class . ' for key ' . $multiton_name . ' already initialized; NOT reinitialized!!' ) if( scalar keys %opts > 1 );
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts > 1 0 2 2
29 2 return $multiton_refs->{$multiton_name};
30 }
31 else {
32 2 $multiton_refs->{$multiton_name} = $class->new( %opts, _____oop_perlish_class__initialize_singleton => 1 );
33 2 return $multiton_refs->{$multiton_name};
34 }
35 0 return;
36 }
37 }
38 2 1;
39  
40 =head1 NAME
41 =head1 VERSION
42 =head1 SYNOPSIS
43 =head1 EXPORT
44 =head1 FUNCTIONS
45 =head1 AUTHOR
46 =head1 BUGS
47 =head1 SUPPORT
48 =head1 ACKNOWLEDGEMENTS
49 =head1 COPYRIGHT & LICENSE
« Class/Accessor.pm ↑ Summary Class/Abstract.pm »