| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||