GX/Class/Singleton.pm

filter: Statementstmt 93.9% 31 / 33 Branchbran 91.6% 11 / 12 Conditioncond 66.6% 6 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 80.0% 8 / 10 Podpod 100% 5 / 5 totaltotal 81.3% 61 / 75 CC 10 SCAR 11.0
CC
10
Cov
89%
new
5.0
instance
4.0
destroy
2.1
CRAP 3.0
« GX/HTML/Util.pm ↑ Summary GX/HTTP/Response.pm »
1 # ----------------------------------------------------------------------------------------------------------------------
2 # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de>
3 # File: GX/Class/Singleton.pm
4 # ----------------------------------------------------------------------------------------------------------------------
5  
6 package GX::Class::Singleton;
7  
8 76 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 76 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 76 ▶use base 'GX::Class::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 76 ▶use GX::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 # ----------------------------------------------------------------------------------------------------------------------
17 # Export mechanism
18 # ----------------------------------------------------------------------------------------------------------------------
19  
20 45 ▶sub import {
Subroutine import: called CC=2 SCAR=7.0
21  
22 45 my $package = shift;
23  
24 45 ▶ return unless $package eq __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
unless $package eq __PACKAGE__ 0 45 45
25  
26 45 unshift( @_, 'GX::Class::Object', superclass => $package );
27  
28 45 goto &GX::Class::Object::import;
29  
30 }
31  
32  
33 # ----------------------------------------------------------------------------------------------------------------------
34 # Object registry
35 # ----------------------------------------------------------------------------------------------------------------------
36  
37 76 my %OBJECTS;
38  
39  
40 # ----------------------------------------------------------------------------------------------------------------------
41 # Constructor
42 # ----------------------------------------------------------------------------------------------------------------------
43  
44 91 ▶sub new {
Subroutine new: called CC=5 SCAR=16.1
Pod documented
45  
46 91 ▶ return $_[0] if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 1 90 91
47  
48 90 my $class = shift;
49  
50 90 ▶ if ( $OBJECTS{$class} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($OBJECTS{$class}) 4 86 90
51  
52 4 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 3 4
53 1 GX::Exception->complain( "$class has already been instantiated" );
54 }
55  
56 3 return $OBJECTS{$class};
57  
58 }
59  
60 86 ▶ return $OBJECTS{$class} = eval { $class->SUPER::new( @_ ) } || GX::Exception->complain( $@ );
Condition66%2/3
eval { do { $class->SUPER::new(@_) } } || 'GX::Exception'->complain($@)
l!l&&r!l&&!r
30056
MC/DC0%0/2
eval { do { $class->SUPER::new(@_) } } || 'GX::Exception'->complain($@)
eval { do { $class->SUPER::new(@_) } } 'GX::Exception'->complain($@)
Truth table33%1/3
A || B
A= eval { do { $class->SUPER::new(@_) } }B= 'GX::Exception'->complain($@)
ABresult
1X1
011
000
61  
62 }
63  
64  
65 # ----------------------------------------------------------------------------------------------------------------------
66 # Public methods
67 # ----------------------------------------------------------------------------------------------------------------------
68  
69 0 ▶sub clear {
Subroutine clear: not called CC=1 SCAR=6.9
Pod documented
70  
71 0 return shift->instance->clear;
72  
73 }
74  
75 2 ▶sub destroy {
Subroutine destroy: called CC=2 SCAR=7.2
Pod documented
76  
77 2 ▶ return delete $OBJECTS{ ref $_[0] || $_[0] };
Condition66%2/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
110
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table66%2/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
78  
79 }
80  
81 0 ▶sub dump {
Subroutine dump: not called CC=1 SCAR=6.9
Pod documented
82  
83 0 return shift->instance->dump;
84  
85 }
86  
87 463 ▶sub instance {
Subroutine instance: called CC=4 SCAR=13.9
Pod documented
88  
89 463 ▶ return $_[0] if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 353 110 463
90  
91 110 ▶ return $OBJECTS{$_[0]} if defined $OBJECTS{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
if defined $OBJECTS{$_[0]} 39 71 110
92  
93 71 ▶ return eval { $_[0]->new } || GX::Exception->complain( $@ );
Condition66%2/3
eval { do { $_[0]->new } } || 'GX::Exception'->complain($@)
l!l&&r!l&&!r
16055
MC/DC0%0/2
eval { do { $_[0]->new } } || 'GX::Exception'->complain($@)
eval { do { $_[0]->new } } 'GX::Exception'->complain($@)
Truth table33%1/3
A || B
A= eval { do { $_[0]->new } }B= 'GX::Exception'->complain($@)
ABresult
1X1
011
000
94  
95 }
96  
97  
98 76 1;
99  
100 __END__
« GX/HTML/Util.pm ↑ Summary GX/HTTP/Response.pm »