| 1 | |||||||||||
| 2 | 9 | ▶ | use v5.10; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 9 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 9 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | package Context::Singleton::Singleton; | ||||||||||
| 7 | 9 | $Context::Singleton::Singleton::VERSION = '1.0.9'; | |||||||||
| 8 | { | ||||||||||
| 9 | 9 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 9 | ▶ | use Context::Singleton::Frame::Builder::Value; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 9 | ▶ | use Context::Singleton::Frame::Builder::Hash; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 9 | ▶ | use Context::Singleton::Frame::Builder::Array; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 9 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 9 | has singleton | |||||||||
| 18 | => is => ro | ||||||||||
| 19 | => required => 1 | ||||||||||
| 20 | ; | ||||||||||
| 21 | |||||||||||
| 22 | has _builders | ||||||||||
| 23 | => is => ro | ||||||||||
| 24 | 27 | ▶ | => default => sub { [] } | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 9 | => init_arg => undef | |||||||||
| 26 | ; | ||||||||||
| 27 | |||||||||||
| 28 | has _on_destroy | ||||||||||
| 29 | => is => ro | ||||||||||
| 30 | 27 | ▶ | => default => sub { [] } | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 9 | => init_arg => undef | |||||||||
| 32 | ; | ||||||||||
| 33 | |||||||||||
| 34 | 320 | ▶ | sub _build_builder { | ||||||||
|
Subroutine
_build_builder: called CC=1 SCAR=0.0
| |||||||||||
| 35 | 320 | my ($db, $def) = @_; | |||||||||
| 36 | |||||||||||
| 37 | 320 | $db->_guess_builder_class ($def)->new (%$def); | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 320 | ▶ | sub _guess_builder_class { | ||||||||
|
Subroutine
_guess_builder_class: called CC=3 SCAR=11.0
| |||||||||||
| 41 | 320 | my ($db, $def) = @_; | |||||||||
| 42 | |||||||||||
| 43 | return Context::Singleton::Frame::Builder::Value:: | ||||||||||
| 44 | if exists $def->{value} | ||||||||||
| 45 | 320 | ▶ | ; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | |||||||||||
| 47 | return Context::Singleton::Frame::Builder::Hash:: | ||||||||||
| 48 | if Ref::Util::is_hashref ($def->{dep}) | ||||||||||
| 49 | 269 | ▶ | ; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | |||||||||||
| 51 | 269 | return Context::Singleton::Frame::Builder::Array::; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 320 | ▶ | sub add_builder { | ||||||||
|
Subroutine
add_builder: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 55 | 320 | my ($self, $def) = @_; | |||||||||
| 56 | |||||||||||
| 57 | 320 | push @{ $self->_builders }, $self->_build_builder ($def); | |||||||||
| 58 | |||||||||||
| 59 | 320 | return; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 43 | ▶ | sub add_on_destroy { | ||||||||
|
Subroutine
add_on_destroy: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 63 | 43 | my ($self, $code) = @_; | |||||||||
| 64 | |||||||||||
| 65 | 43 | push @{ $self->_on_destroy }, $code; | |||||||||
| 66 | |||||||||||
| 67 | 43 | return; | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 63 | ▶ | sub builders { | ||||||||
|
Subroutine
builders: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 71 | 63 | my ($self) = @_; | |||||||||
| 72 | |||||||||||
| 73 | 63 | return @{ $self->_builders }; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 12 | ▶ | sub on_destroy { | ||||||||
|
Subroutine
on_destroy: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 77 | 12 | my ($self) = @_; | |||||||||
| 78 | |||||||||||
| 79 | 12 | return @{ $self->_on_destroy }; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 9 | 1; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | =pod | ||||||||||
| 86 | |||||||||||
| 87 | =encoding utf-8 | ||||||||||
| 88 | |||||||||||
| 89 | =head1 NAME | ||||||||||
| 90 | |||||||||||
| 91 | Context::Singleton::Singleton - Internal class holding one singleton's builders and destroy callbacks. | ||||||||||
| 92 | |||||||||||
| 93 | =head1 DESCRIPTION | ||||||||||
| 94 | |||||||||||
| 95 | This is internal package. | ||||||||||
| 96 | |||||||||||
| 97 | =head1 AUTHOR | ||||||||||
| 98 | |||||||||||
| 99 | Branislav ZahradnĂk <barney.cpan@gmail.com> | ||||||||||
| 100 | |||||||||||
| 101 | =head1 COPYRIGHT AND LICENCE | ||||||||||
| 102 | |||||||||||
| 103 | This module is part of L<Context::Singleton> distribution. | ||||||||||
| 104 | |||||||||||
| 105 | =cut | ||||||||||