Singleton/Role/Object.pm

filter: Statementstmt 100% 24 / 24 Branchbran 100% 6 / 6 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 91.8% 45 / 49 CC 6 SCAR 10.4
CC
6
Cov
97%
__ANON__
5.0
initialize
2.0
BEGIN
1.0
CRAP 2.8
« Singleton/Role/Meta/Method/Constructor.pm ↑ Summary Singleton/Role/Meta/Instance.pm »
1 package MooseX::Singleton::Role::Object;
2 7 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use Carp qw( confess );
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 7 our $VERSION = '0.30';
6  
7 12 ▶sub instance { shift->new }
Subroutine instance: called CC=1 SCAR=0.0
Pod undocumented
8  
9 3 ▶sub initialize {
Subroutine initialize: called CC=2 SCAR=6.9
Pod undocumented
10 3 my ( $class, @args ) = @_;
11  
12 3 my $existing = $class->meta->existing_singleton;
13 3 ▶ confess "Singleton is already initialized" if $existing;
Branch: 1 branch
BranchTrueFalseTotal
if $existing 1 2 3
14  
15 2 return $class->new(@args);
16 }
17  
18 15 ▶override new => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
19 15 my ( $class, @args ) = @_;
20  
21 15 my $existing = $class->meta->existing_singleton;
22 15 ▶ confess "Singleton is already initialized" if $existing and @args;
Branch: 1 branch
BranchTrueFalseTotal
if $existing and @args 1 14 15
Condition100%3/3
$existing and @args
!ll&&!rl&&r
951
MC/DC100%2/2
$existing and @args
$existing @args
Truth table100%3/3
A and B
A= $existingB= @args
ABresult
0X0
100
111
23  
24 # Otherwise BUILD will be called repeatedly on the existing instance.
25 # -- rjbs, 2008-02-03
26 14 ▶ return $existing if $existing and !@args;
Branch: 1 branch
BranchTrueFalseTotal
if $existing and not @args 5 9 14
Condition66%2/3
$existing and not @args
!ll&&!rl&&r
905
MC/DC50%1/2
$existing and not @args
$existing not @args
Truth table66%2/3
A and not(B)
A= $existingB= not @args
ABresult
0X0
100
111
27  
28 9 return super();
29 7 };
30  
31 1 ▶sub _clear_instance {
Subroutine _clear_instance: called CC=1 SCAR=0.0
32 1 my ($class) = @_;
33 1 $class->meta->clear_singleton;
34 }
35  
36 7 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 7 1;
39  
40 # ABSTRACT: Object class role for MooseX::Singleton
41  
42 __END__
« Singleton/Role/Meta/Method/Constructor.pm ↑ Summary Singleton/Role/Meta/Instance.pm »