| 1 | package MooseX::Singleton::Role::Meta::Instance; | ||||||||||
| 2 | 7 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 7 | ▶ | use Scalar::Util qw(weaken blessed); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 7 | our $VERSION = '0.30'; | |||||||||
| 6 | |||||||||||
| 7 | 58 | ▶ | sub get_singleton_instance { | ||||||||
|
Subroutine
get_singleton_instance: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 8 | 58 | my ( $self, $instance ) = @_; | |||||||||
| 9 | |||||||||||
| 10 | 58 | ▶ | return $instance if blessed $instance; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 11 | |||||||||||
| 12 | # optimization: it's really slow to go through new_object for every access | ||||||||||
| 13 | # so return the singleton if we see it already exists, which it will every | ||||||||||
| 14 | # single except the first. | ||||||||||
| 15 | 7 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 18 | ▶ | return ${"$instance\::singleton"} if defined ${"$instance\::singleton"}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | |||||||||||
| 18 | # We need to go through ->new in order to make sure BUILD and | ||||||||||
| 19 | # BUILDARGS get called. | ||||||||||
| 20 | 3 | return $instance->meta->name->new; | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | 0 | ▶ | override clone_instance => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 24 | 0 | my ( $self, $instance ) = @_; | |||||||||
| 25 | 0 | $self->get_singleton_instance($instance); | |||||||||
| 26 | 7 | }; | |||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | override get_slot_value => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 29 | 0 | my ( $self, $instance, $slot_name ) = @_; | |||||||||
| 30 | $self->is_slot_initialized( $instance, $slot_name ) | ||||||||||
| 31 | 0 | ▶ | ? $self->get_singleton_instance($instance)->{$slot_name} | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | : undef; | ||||||||||
| 33 | 7 | }; | |||||||||
| 34 | |||||||||||
| 35 | 8 | ▶ | override set_slot_value => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 36 | 8 | my ( $self, $instance, $slot_name, $value ) = @_; | |||||||||
| 37 | 8 | $self->get_singleton_instance($instance)->{$slot_name} = $value; | |||||||||
| 38 | 7 | }; | |||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | override deinitialize_slot => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 41 | 0 | my ( $self, $instance, $slot_name ) = @_; | |||||||||
| 42 | 0 | delete $self->get_singleton_instance($instance)->{$slot_name}; | |||||||||
| 43 | 7 | }; | |||||||||
| 44 | |||||||||||
| 45 | 0 | ▶ | override is_slot_initialized => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 46 | 0 | my ( $self, $instance, $slot_name, $value ) = @_; | |||||||||
| 47 | 0 | ▶ | exists $self->get_singleton_instance($instance)->{$slot_name} ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 7 | }; | |||||||||
| 49 | |||||||||||
| 50 | 0 | ▶ | override weaken_slot_value => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 51 | 0 | my ( $self, $instance, $slot_name ) = @_; | |||||||||
| 52 | 0 | weaken $self->get_singleton_instance($instance)->{$slot_name}; | |||||||||
| 53 | 7 | }; | |||||||||
| 54 | |||||||||||
| 55 | 25 | ▶ | override inline_slot_access => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 56 | 25 | my ( $self, $instance, $slot_name ) = @_; | |||||||||
| 57 | 25 | sprintf "%s->meta->instance_metaclass->get_singleton_instance(%s)->{%s}", | |||||||||
| 58 | $instance, $instance, $slot_name; | ||||||||||
| 59 | 7 | }; | |||||||||
| 60 | |||||||||||
| 61 | 7 | ▶ | no Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 62 | |||||||||||
| 63 | 7 | 1; | |||||||||
| 64 | |||||||||||
| 65 | # ABSTRACT: Instance metaclass role for MooseX::Singleton | ||||||||||
| 66 | |||||||||||
| 67 | __END__ | ||||||||||