Singleton/Role/Meta/Class.pm

filter: Statementstmt 100% 51 / 51 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 2 totaltotal 94.4% 68 / 72 CC 3 SCAR 2.4
CC
3
Cov
96%
__ANON__
2.0
existing_singleton
2.0
BEGIN
1.0
CRAP 1.3
« Singleton/Role/Meta/Instance.pm ↑ Summary Singleton.pm »
1 package MooseX::Singleton::Role::Meta::Class;
2 7 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use MooseX::Singleton::Role::Meta::Instance;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use MooseX::Singleton::Role::Meta::Method::Constructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 our $VERSION = '0.30';
7  
8 27 ▶sub existing_singleton {
Subroutine existing_singleton: called CC=2 SCAR=6.9
Pod undocumented
9 27 my ($class) = @_;
10 27 my $pkg = $class->name;
11  
12 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # create exactly one instance
15 27 ▶ if ( defined ${"$pkg\::singleton"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined ${"${pkg}::singleton";}) 7 20 27
16 7 return ${"$pkg\::singleton"};
17 }
18  
19 20 return;
20 }
21  
22 1 ▶sub clear_singleton {
Subroutine clear_singleton: called CC=1 SCAR=0.0
Pod undocumented
23 1 my ($class) = @_;
24 1 my $pkg = $class->name;
25 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 undef ${"$pkg\::singleton"};
27 }
28  
29 9 ▶override _construct_instance => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
30 9 my ($class) = @_;
31  
32 # create exactly one instance
33 9 my $existing = $class->existing_singleton;
34 9 ▶ return $existing if $existing;
Branch: 1 branch
BranchTrueFalseTotal
if $existing 0 9 9
35  
36 9 my $pkg = $class->name;
37 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
38 7 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
39 9 return ${"$pkg\::singleton"} = super;
40 7 };
41  
42 7 ▶if ( $Moose::VERSION >= 1.9900 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Moose::VERSION >= "1.99") 7 0 7
43 2 ▶ override _inline_params => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
44 2 my $self = shift;
45  
46 return
47 2 'my $existing = do {',
48 'no strict "refs";',
49 'no warnings "once";',
50 '\${"$class\::singleton"};',
51 '};',
52 'return ${$existing} if ${$existing};',
53 super();
54 7 };
55  
56 2 ▶ override _inline_extra_init => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
57 2 my $self = shift;
58  
59 2 return '${$existing} = $instance;';
60 7 };
61 }
62  
63 7 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 7 1;
66  
67 # ABSTRACT: Metaclass role for MooseX::Singleton
68  
69 __END__
« Singleton/Role/Meta/Instance.pm ↑ Summary Singleton.pm »