| 1 | |||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use v5.10; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use feature q (state); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | package Context::Singleton::Frame::DB; | ||||||||||||||||||||||||||||
| 9 | 9 | $Context::Singleton::Frame::DB::VERSION = '1.0.9'; | |||||||||||||||||||||||||||
| 10 | 9 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 9 | ▶ | use Class::Load; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 9 | ▶ | use Module::Pluggable::Object; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 9 | ▶ | use Ref::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 9 | ▶ | use Context::Singleton::Singleton; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 9 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | has cache | ||||||||||||||||||||||||||||
| 21 | => is => ro | ||||||||||||||||||||||||||||
| 22 | 4 | ▶ | => default => sub { +{} } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 9 | => init_arg => undef | |||||||||||||||||||||||||||
| 24 | ; | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | has plugins | ||||||||||||||||||||||||||||
| 27 | => is => ro | ||||||||||||||||||||||||||||
| 28 | 4 | ▶ | => default => sub { +{} } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 9 | => init_arg => undef | |||||||||||||||||||||||||||
| 30 | ; | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 4 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 4 | my ($db) = @_; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 4 | $db->contrive (q (Class::Load), ( | |||||||||||||||||||||||||||
| 36 | value => q (Class::Load), | ||||||||||||||||||||||||||||
| 37 | )); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | $db->contrive (q (class_loader), ( | ||||||||||||||||||||||||||||
| 40 | dep => [ q (Class::Load) ], | ||||||||||||||||||||||||||||
| 41 | 1 | ▶ | as => sub { $_[0]->can (q (load_class)) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | 4 | )); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 363 | ▶ | sub _ensure_singleton { | ||||||||||||||||||||||||||
|
Subroutine
_ensure_singleton: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 46 | 363 | my ($db, $name) = @_; | |||||||||||||||||||||||||||
| 47 | 363 | my $lookup_key = $db->_lookup_key ($name); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 363 | ▶ | return $db->cache->{$lookup_key} //= Context::Singleton::Singleton::->new (singleton => $name); | ||||||||||||||||||||||||||
|
Condition66%2/3
$db->cache->{$lookup_key} //= "Context::Singleton::Singleton"->new("singleton", $name)
MC/DC0%0/2
$db->cache->{$lookup_key} //= "Context::Singleton::Singleton"->new("singleton", $name)
$db->cache->{$lookup_key}
"Context::Singleton::Singleton"->new("singleton", $name)
Truth table66%2/3
A //= B
A= $db->cache->{$lookup_key}B= "Context::Singleton::Singleton"->new("singleton", $name)
| |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 584 | ▶ | sub _lookup_key { | ||||||||||||||||||||||||||
|
Subroutine
_lookup_key: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 53 | 584 | my ($db, $name) = @_; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 584 | return $name; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 221 | ▶ | sub _search_singleton { | ||||||||||||||||||||||||||
|
Subroutine
_search_singleton: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | 221 | my ($db, $name) = @_; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 221 | return $db->cache->{ $db->_lookup_key ($name) }; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 320 | ▶ | sub contrive { | ||||||||||||||||||||||||||
|
Subroutine
contrive: called CC=6 SCAR=18.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | 320 | my ($db, $name, %def) = @_; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 320 | ▶ | if ($def{class}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 1 | $db->contrive_class ($def{class}); | |||||||||||||||||||||||||||
| 69 | 1 | ▶ | $def{builder} //= q (new); | ||||||||||||||||||||||||||
|
Condition50%1/2
$def{"builder"} //= "new"
MC/DC0%0/1
$def{"builder"} //= "new"
$def{"builder"}
Truth table50%1/2
A
A= $def{"builder"}
| |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 320 | ▶ | if ($def{class} // $def{deduce}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$def{"class"} // $def{"deduce"}
MC/DC50%1/2
$def{"class"} // $def{"deduce"}
$def{"class"}
$def{"deduce"}
Truth table66%2/3
A // B
A= $def{"class"}B= $def{"deduce"}
| |||||||||||||||||||||||||||||
| 73 | 1 | ▶ | $def{this} = $def{class} // $def{deduce}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$def{"class"} // $def{"deduce"}
MC/DC0%0/2
$def{"class"} // $def{"deduce"}
$def{"class"}
$def{"deduce"}
Truth table33%1/3
A // B
A= $def{"class"}B= $def{"deduce"}
| |||||||||||||||||||||||||||||
| 74 | 1 | delete $def{class}; | |||||||||||||||||||||||||||
| 75 | 1 | delete $def{deduce}; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 320 | $db->_ensure_singleton ($name)->add_builder (\ %def); | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 320 | return; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 3 | ▶ | sub contrive_class { | ||||||||||||||||||||||||||
|
Subroutine
contrive_class: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 84 | 3 | my ($db, $name) = @_; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | return | ||||||||||||||||||||||||||||
| 87 | 3 | ▶ | if $db->_search_singleton ($name) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | ; | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 3 | $db->contrive ($name, ( | |||||||||||||||||||||||||||
| 91 | dep => [ q (class_loader) ], | ||||||||||||||||||||||||||||
| 92 | as => eval qq (sub { \$_[0]->(q[$name]) && q[$name] }), | ||||||||||||||||||||||||||||
| 93 | )); | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 3 | return; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 44 | ▶ | sub instance { | ||||||||||||||||||||||||||
|
Subroutine
instance: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 99 | 44 | state $instance = __PACKAGE__->new; | |||||||||||||||||||||||||||
| 100 | 44 | return $instance; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 6 | ▶ | sub load_rules { | ||||||||||||||||||||||||||
|
Subroutine
load_rules: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 104 | 6 | my ($db, @packages) = @_; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 6 | for my $package (@packages) { | |||||||||||||||||||||||||||
| 107 | 6 | ▶ | $db->plugins->{ $package } //= do { | ||||||||||||||||||||||||||
|
Condition66%2/3
$db->plugins->{$package} //= do {
"Module::Pluggable::Object"->new("require", 1, "search_path", [$package])->plugins;
1
}
MC/DC0%0/2
$db->plugins->{$package} //= do {
"Module::Pluggable::Object"->new("require", 1, "search_path", [$package])->plugins;
1
}
$db->plugins->{$package}
do {
"Module::Pluggable::Object"->new("require", 1, "search_path", [$package])->plugins;
1
}
Truth table66%2/3
A //= B
A= $db->plugins->{$package}B= do {
"Module::Pluggable::Object"->new("require", 1, "search_path", [$package])->plugins;
1
}
| |||||||||||||||||||||||||||||
| 108 | 5 | Module::Pluggable::Object->new ( | |||||||||||||||||||||||||||
| 109 | require => 1, | ||||||||||||||||||||||||||||
| 110 | search_path => [ $package ], | ||||||||||||||||||||||||||||
| 111 | )->plugins; | ||||||||||||||||||||||||||||
| 112 | 5 | 1; | |||||||||||||||||||||||||||
| 113 | }; | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 6 | return; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 146 | ▶ | sub search_builder_for { | ||||||||||||||||||||||||||
|
Subroutine
search_builder_for: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 120 | 146 | my ($db, $name) = @_; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | return | ||||||||||||||||||||||||||||
| 123 | 146 | ▶ | unless my $singleton = $db->_search_singleton ($name) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | ; | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 63 | return $singleton->builders; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 72 | ▶ | sub search_trigger_for { | ||||||||||||||||||||||||||
|
Subroutine
search_trigger_for: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 130 | 72 | my ($db, $name) = @_; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | return | ||||||||||||||||||||||||||||
| 133 | 72 | ▶ | unless my $singleton = $db->_search_singleton ($name) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | ; | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 12 | return $singleton->on_destroy; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 43 | ▶ | sub trigger { | ||||||||||||||||||||||||||
|
Subroutine
trigger: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 140 | 43 | my ($db, $name, $code) = @_; | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 43 | $db->_ensure_singleton ($name)->add_on_destroy ($code); | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 43 | return; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 9 | 1; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =pod | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =encoding utf-8 | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head1 NAME | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | Context::Singleton::DB - Internal class storing singleton rules. | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | This is internal package. | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | Branislav ZahradnĂk <barney.cpan@gmail.com> | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =head1 COPYRIGHT AND LICENCE | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | This module is part of L<Context::Singleton> distribution. | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =cut | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||