| 1 | |||||||||||||||||||||||||||||
| 2 | package IOC::Container; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 23 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 23 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 23 | our $VERSION = '0.14'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 23 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 23 | ▶ | use IOC::Interfaces; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 23 | ▶ | use IOC::Exceptions; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 23 | ▶ | use IOC::Visitor::ServiceLocator; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 23 | ▶ | use base 'IOC::Visitable'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 47 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 47 | my ($_class, $name) = @_; | |||||||||||||||||||||||||||
| 20 | 47 | ▶ | my $class = ref($_class) || $_class; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $_class || $_class
MC/DC0%0/2
ref $_class || $_class
ref $_class
$_class
Truth table33%1/3
A || B
A= ref $_classB= $_class
| |||||||||||||||||||||||||||||
| 21 | 47 | my $container = {}; | |||||||||||||||||||||||||||
| 22 | 47 | bless($container, $class); | |||||||||||||||||||||||||||
| 23 | 47 | $container->_init($name); | |||||||||||||||||||||||||||
| 24 | 47 | return $container; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 47 | ▶ | sub _init { | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 28 | 47 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 29 | 47 | $self->{services} = {}; | |||||||||||||||||||||||||||
| 30 | 47 | $self->{service_locks} = {}; | |||||||||||||||||||||||||||
| 31 | 47 | $self->{proxies} = {}; | |||||||||||||||||||||||||||
| 32 | 47 | $self->{sub_containers} = {}; | |||||||||||||||||||||||||||
| 33 | 47 | $self->{parent_container} = undef; | |||||||||||||||||||||||||||
| 34 | 47 | ▶ | $self->{name} = $name || 'default'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$name || 'default'
MC/DC100%1/1
$name || 'default'
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 32 | ▶ | sub name { | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 32 | my ($self) = @_; | |||||||||||||||||||||||||||
| 39 | 32 | return $self->{name}; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # parent containers | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 25 | ▶ | sub setParentContainer { | ||||||||||||||||||||||||||
|
Subroutine
setParentContainer: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 25 | my ($self, $parent_container) = @_; | |||||||||||||||||||||||||||
| 46 | 25 | ▶ | (blessed($parent_container) && $parent_container->isa('IOC::Container')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($parent_container) and $parent_container->isa("IOC::Container")
MC/DC100%2/2
builtin::blessed($parent_container) and $parent_container->isa("IOC::Container")
builtin::blessed($parent_container)
$parent_container->isa("IOC::Container")
Truth table100%3/3
A and B
A= builtin::blessed($parent_container)B= $parent_container->isa("IOC::Container")
| |||||||||||||||||||||||||||||
| 47 | || throw IOC::InsufficientArguments "You must provide an IOC::Container object as a parent container"; | ||||||||||||||||||||||||||||
| 48 | 21 | $self->{parent_container} = $parent_container; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 5 | ▶ | sub getParentContainer { | ||||||||||||||||||||||||||
|
Subroutine
getParentContainer: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||
| 53 | 5 | return $self->{parent_container}; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 11 | ▶ | sub isRootContainer { | ||||||||||||||||||||||||||
|
Subroutine
isRootContainer: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 11 | my ($self) = @_; | |||||||||||||||||||||||||||
| 58 | 11 | ▶ | return defined($self->{parent_container}) ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 9 | ▶ | sub findRootContainer { | ||||||||||||||||||||||||||
|
Subroutine
findRootContainer: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||
| 63 | 9 | ▶ | return $self if $self->isRootContainer(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 1 | my $current = $self; | |||||||||||||||||||||||||||
| 65 | 1 | ▶ | $current = $current->getParentContainer() until $current->isRootContainer(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 1 | return $current; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # sub containers | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 26 | ▶ | sub addSubContainer { | ||||||||||||||||||||||||||
|
Subroutine
addSubContainer: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 26 | my ($self, $container) = @_; | |||||||||||||||||||||||||||
| 73 | 26 | ▶ | (blessed($container) && $container->isa('IOC::Container')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($container) and $container->isa("IOC::Container")
MC/DC100%2/2
builtin::blessed($container) and $container->isa("IOC::Container")
builtin::blessed($container)
$container->isa("IOC::Container")
Truth table100%3/3
A and B
A= builtin::blessed($container)B= $container->isa("IOC::Container")
| |||||||||||||||||||||||||||||
| 74 | || throw IOC::InsufficientArguments "You must provide an IOC::Container object as a sub-container"; | ||||||||||||||||||||||||||||
| 75 | 22 | my $name = $container->name(); | |||||||||||||||||||||||||||
| 76 | 22 | (!exists ${$self->{sub_containers}}{$name}) | |||||||||||||||||||||||||||
| 77 | 22 | ▶ | || throw IOC::ContainerAlreadyExists "Duplicate Sub-Container Name '${name}' in container '" . $self->{name} . "'"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 21 | $self->{sub_containers}->{$name} = $container; | |||||||||||||||||||||||||||
| 79 | 21 | $container->setParentContainer($self); | |||||||||||||||||||||||||||
| 80 | 21 | $self; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 7 | ▶ | sub addSubContainers { | ||||||||||||||||||||||||||
|
Subroutine
addSubContainers: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 7 | my ($self, @containers) = @_; | |||||||||||||||||||||||||||
| 85 | 7 | ▶ | (@containers) || throw IOC::InsufficientArguments "You must provide at least one IOC::Container to add"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 6 | $self->addSubContainer($_) foreach @containers; | |||||||||||||||||||||||||||
| 87 | 6 | $self; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 9 | ▶ | sub hasSubContainer { | ||||||||||||||||||||||||||
|
Subroutine
hasSubContainer: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 9 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 92 | 9 | ▶ | (defined($name)) || throw IOC::InsufficientArguments "You must supply a name of a sub-container"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 8 | ▶ | return (exists ${$self->{sub_containers}}{$name}) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 23 | ▶ | sub hasSubContainers { | ||||||||||||||||||||||||||
|
Subroutine
hasSubContainers: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 23 | my ($self) = @_; | |||||||||||||||||||||||||||
| 98 | 23 | ▶ | return scalar(keys(%{$self->{sub_containers}})) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 6 | ▶ | sub getSubContainerList { | ||||||||||||||||||||||||||
|
Subroutine
getSubContainerList: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||
| 103 | 6 | return keys %{$self->{sub_containers}}; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 37 | ▶ | sub getSubContainer { | ||||||||||||||||||||||||||
|
Subroutine
getSubContainer: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | 37 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 108 | 37 | ▶ | (defined($name)) || throw IOC::InsufficientArguments "You must supply a name of a sub-container"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 36 | (exists ${$self->{sub_containers}}{$name}) | |||||||||||||||||||||||||||
| 110 | 36 | ▶ | || throw IOC::ContainerNotFound "There is no subcontainer by the name '${name}' in container '" . $self->{name} . "'"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 33 | return $self->{sub_containers}->{$name}; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 7 | ▶ | sub getAllSubContainers { | ||||||||||||||||||||||||||
|
Subroutine
getAllSubContainers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 115 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||
| 116 | 7 | return values %{$self->{sub_containers}}; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 42 | ▶ | sub accept { | ||||||||||||||||||||||||||
|
Subroutine
accept: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 120 | 42 | my ($self, $visitor) = @_; | |||||||||||||||||||||||||||
| 121 | 42 | ▶ | (blessed($visitor) && $visitor->isa('IOC::Visitor')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($visitor) and $visitor->isa("IOC::Visitor")
MC/DC100%2/2
builtin::blessed($visitor) and $visitor->isa("IOC::Visitor")
builtin::blessed($visitor)
$visitor->isa("IOC::Visitor")
Truth table100%3/3
A and B
A= builtin::blessed($visitor)B= $visitor->isa("IOC::Visitor")
| |||||||||||||||||||||||||||||
| 122 | || throw IOC::InsufficientArguments "You must pass an IOC::Visitor object to the visit method"; | ||||||||||||||||||||||||||||
| 123 | 38 | return $visitor->visit($self); | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | # services | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 69 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 129 | 69 | my ($self, $service) = @_; | |||||||||||||||||||||||||||
| 130 | 69 | ▶ | (blessed($service) && $service->isa('IOC::Service')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($service) and $service->isa("IOC::Service")
MC/DC100%2/2
builtin::blessed($service) and $service->isa("IOC::Service")
builtin::blessed($service)
$service->isa("IOC::Service")
Truth table100%3/3
A and B
A= builtin::blessed($service)B= $service->isa("IOC::Service")
| |||||||||||||||||||||||||||||
| 131 | || throw IOC::InsufficientArguments "You must provide a valid IOC::Service object to register"; | ||||||||||||||||||||||||||||
| 132 | 65 | my $name = $service->name(); | |||||||||||||||||||||||||||
| 133 | 65 | ▶ | (!exists ${$self->{services}}{$name}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | || throw IOC::ServiceAlreadyExists "Duplicate Service Name '${name}'"; | ||||||||||||||||||||||||||||
| 135 | 64 | $service->setContainer($self); | |||||||||||||||||||||||||||
| 136 | 64 | $self->{services}->{$name} = $service; | |||||||||||||||||||||||||||
| 137 | 64 | $self; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 3 | ▶ | sub unregister { | ||||||||||||||||||||||||||
|
Subroutine
unregister: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 141 | 3 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 142 | 3 | ▶ | (defined($name)) || throw IOC::InsufficientArguments "You must provide a service name to unregister"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 2 | ▶ | (exists ${$self->{services}}{$name}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | || throw IOC::ServiceNotFound "Unknown Service '${name}'"; | ||||||||||||||||||||||||||||
| 145 | 1 | my $service = $self->{services}->{$name}; | |||||||||||||||||||||||||||
| 146 | 1 | $service->removeContainer(); | |||||||||||||||||||||||||||
| 147 | 1 | delete $self->{services}->{$name}; | |||||||||||||||||||||||||||
| 148 | 1 | return $service; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 1 | ▶ | sub registerWithProxy { | ||||||||||||||||||||||||||
|
Subroutine
registerWithProxy: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 152 | 1 | my ($self, $service, $proxy) = @_; | |||||||||||||||||||||||||||
| 153 | 1 | $self->register($service); | |||||||||||||||||||||||||||
| 154 | 1 | $self->addProxy($service->name(), $proxy); | |||||||||||||||||||||||||||
| 155 | 1 | $self; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 8 | ▶ | sub addProxy { | ||||||||||||||||||||||||||
|
Subroutine
addProxy: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 159 | 8 | my ($self, $name, $proxy) = @_; | |||||||||||||||||||||||||||
| 160 | 8 | ▶ | (defined($name)) || throw IOC::InsufficientArguments "You must provide a valid service name"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 7 | ▶ | (blessed($proxy) && $proxy->isa('IOC::Proxy')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($proxy) and $proxy->isa("IOC::Proxy")
MC/DC100%2/2
builtin::blessed($proxy) and $proxy->isa("IOC::Proxy")
builtin::blessed($proxy)
$proxy->isa("IOC::Proxy")
Truth table100%3/3
A and B
A= builtin::blessed($proxy)B= $proxy->isa("IOC::Proxy")
| |||||||||||||||||||||||||||||
| 162 | || throw IOC::InsufficientArguments "You must provide a valid IOC::Proxy object to register"; | ||||||||||||||||||||||||||||
| 163 | 3 | ▶ | (exists ${$self->{services}}{$name}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | || throw IOC::ServiceNotFound "Unknown Service '${name}'"; | ||||||||||||||||||||||||||||
| 165 | 2 | $self->{proxies}->{$name} = $proxy; | |||||||||||||||||||||||||||
| 166 | 2 | $self; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 84 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||
| 170 | 84 | my ($self, $name, %params) = @_; | |||||||||||||||||||||||||||
| 171 | 84 | ▶ | (defined($name)) || throw IOC::InsufficientArguments "You must provide a name of the service"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 83 | ▶ | (exists ${$self->{services}}{$name}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | || throw IOC::ServiceNotFound "Unknown Service '${name}'"; | ||||||||||||||||||||||||||||
| 174 | # a literal object can have no dependencies, | ||||||||||||||||||||||||||||
| 175 | # and therefore can have no circular refs, so | ||||||||||||||||||||||||||||
| 176 | # we can optimize their usage there as well | ||||||||||||||||||||||||||||
| 177 | return $self->{services}->{$name}->instance() | ||||||||||||||||||||||||||||
| 178 | 81 | ▶ | if $self->{services}->{$name}->isa('IOC::Service::Literal'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 67 | ▶ | if ($self->_isServiceLocked($name)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | # NOTE: | ||||||||||||||||||||||||||||
| 181 | # if the service is parameterized | ||||||||||||||||||||||||||||
| 182 | # then we cannot defer it - SL | ||||||||||||||||||||||||||||
| 183 | 7 | ▶ | ($self->{services}->{$name}->isa('IOC::Service::Parameterized')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | && throw IOC::IllegalOperation "The service '$name' is locked, cannot defer a parameterized instance"; | ||||||||||||||||||||||||||||
| 185 | # otherwise ... | ||||||||||||||||||||||||||||
| 186 | 7 | return $self->{services}->{$name}->deferred(); | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | 60 | $self->_lockService($name); | |||||||||||||||||||||||||||
| 189 | 60 | my $instance = $self->{services}->{$name}->instance(%params); | |||||||||||||||||||||||||||
| 190 | 60 | $self->_unlockService($name); | |||||||||||||||||||||||||||
| 191 | 60 | ▶ | if (blessed($instance) && ref($instance) !~ /\:\:\_\:\:Proxy$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($instance) and not ref($instance) =~ /\:\:\_\:\:Proxy$/
MC/DC100%2/2
builtin::blessed($instance) and not ref($instance) =~ /\:\:\_\:\:Proxy$/
builtin::blessed($instance)
not ref($instance) =~ /\:\:\_\:\:Proxy$/
Truth table100%3/3
A and not(B)
A= builtin::blessed($instance)B= not ref($instance) =~ /\:\:\_\:\:Proxy$/
| |||||||||||||||||||||||||||||
| 192 | 44 | ▶ | return $self->{proxies}->{$name}->wrap($instance) if exists ${$self->{proxies}}{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | 58 | return $instance; | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 25 | ▶ | sub find { | ||||||||||||||||||||||||||
|
Subroutine
find: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 198 | 25 | my ($self, $path, $extra_args) = @_; | |||||||||||||||||||||||||||
| 199 | 25 | ▶ | (defined($path)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | || throw IOC::InsufficientArguments "You must provide a path of find a service"; | ||||||||||||||||||||||||||||
| 201 | 24 | return $self->accept(IOC::Visitor::ServiceLocator->new($path, $extra_args)); | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 20 | ▶ | sub hasService { | ||||||||||||||||||||||||||
|
Subroutine
hasService: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 205 | 20 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 206 | 20 | ▶ | (defined($name)) || throw IOC::InsufficientArguments "You must provide a name of the service"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 19 | ▶ | return (exists ${$self->{services}}{$name}) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 3 | ▶ | sub getServiceList { | ||||||||||||||||||||||||||
|
Subroutine
getServiceList: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 211 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||
| 212 | 3 | return keys %{$self->{services}}; | |||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 8 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 216 | 8 | my ($self) = @_; | |||||||||||||||||||||||||||
| 217 | # this will not DESTROY all the | ||||||||||||||||||||||||||||
| 218 | # sub-containers it holds, since | ||||||||||||||||||||||||||||
| 219 | # a sub-container might be still | ||||||||||||||||||||||||||||
| 220 | # refered to elsewhere. | ||||||||||||||||||||||||||||
| 221 | 8 | $self->{sub_containers} = undef; | |||||||||||||||||||||||||||
| 222 | # and the same with the parent | ||||||||||||||||||||||||||||
| 223 | 8 | $self->{parent_container} = undef; | |||||||||||||||||||||||||||
| 224 | # this will DESTROY all the | ||||||||||||||||||||||||||||
| 225 | # services it holds, since | ||||||||||||||||||||||||||||
| 226 | # a service can only have one | ||||||||||||||||||||||||||||
| 227 | # container, then this is okay | ||||||||||||||||||||||||||||
| 228 | # to do that, otherwise we would | ||||||||||||||||||||||||||||
| 229 | # need to deal with that. | ||||||||||||||||||||||||||||
| 230 | 8 | foreach my $service (values %{$self->{services}}) { | |||||||||||||||||||||||||||
| 231 | 2 | ▶ | defined $service && $service->DESTROY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | # private methods | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 60 | ▶ | sub _lockService { | ||||||||||||||||||||||||||
|
Subroutine
_lockService: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 238 | 60 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 239 | 60 | $self->{lock_level}++; | |||||||||||||||||||||||||||
| 240 | 60 | $self->{service_locks}->{$name} = $self->{lock_level}; | |||||||||||||||||||||||||||
| 241 | # use Data::Dumper; | ||||||||||||||||||||||||||||
| 242 | # print "locking '$name' -> our locks are: " . Dumper($self->{service_locks}); | ||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 60 | ▶ | sub _unlockService { | ||||||||||||||||||||||||||
|
Subroutine
_unlockService: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 246 | 60 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 247 | 60 | $self->{lock_level}--; | |||||||||||||||||||||||||||
| 248 | 60 | delete $self->{service_locks}->{$name}; | |||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 67 | ▶ | sub _isServiceLocked { | ||||||||||||||||||||||||||
|
Subroutine
_isServiceLocked: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 252 | 67 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 253 | 67 | return (exists ${$self->{service_locks}}{$name}); | |||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 23 | 1; | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | __END__ | ||||||||||||||||||||||||||||