Mercurial > pub > Impl
comparison lib/IMPL/Config/ServiceDescriptor.pm @ 416:cc2cf8c0edc2 ref20150831
sync
author | cin |
---|---|
date | Thu, 29 Oct 2015 03:50:25 +0300 |
parents | 3d24b10dd0d5 |
children | 3ed0c58e9da3 |
comparison
equal
deleted
inserted
replaced
415:3d24b10dd0d5 | 416:cc2cf8c0edc2 |
---|---|
3 | 3 |
4 use IMPL::lang qw(:base); | 4 use IMPL::lang qw(:base); |
5 use IMPL::Exception(); | 5 use IMPL::Exception(); |
6 use IMPL::declare { | 6 use IMPL::declare { |
7 require => { | 7 require => { |
8 Bag => 'IMPL::Config::Bag' | 8 Bag => 'IMPL::Config::Bag', |
9 ActivationException => 'IMPL::Config::ActivationException' | |
9 }, | 10 }, |
10 base => [ | 11 base => [ |
11 'IMPL::Object' => undef, | 12 'IMPL::Object' => undef, |
12 'IMPL::Config::Descriptor' => undef | 13 'IMPL::Config::Descriptor' => undef |
13 ], | 14 ], |
39 } | 40 } |
40 | 41 |
41 sub Activate { | 42 sub Activate { |
42 my ( $this, $context ) = @_; | 43 my ( $this, $context ) = @_; |
43 | 44 |
44 $context->EnterScope( $this->_name, $this->services ); | 45 my $instance; |
46 $context->GuardScope( | |
47 $this->_name, | |
48 $this->services, | |
49 sub { | |
45 | 50 |
46 my $activation = $this->activation; | 51 my $activation = $this->activation; |
47 my $cache; | 52 my $cache; |
48 | 53 |
49 if ( $activation == IMPL::Config::Descriptor::ACTIVATE_SINGLETON ) { | 54 if ( $activation == IMPL::Config::Descriptor::ACTIVATE_SINGLETON ) { |
50 $cache = $context->container->root->instances; | 55 $cache = $context->container->root->instances; |
51 } | 56 } |
52 elsif ( $activation == IMPL::Config::Descriptor::ACTIVATE_CONTAINER ) { | 57 elsif ( |
53 $cache = $context->container->instances; | 58 $activation == IMPL::Config::Descriptor::ACTIVATE_CONTAINER ) |
54 } | 59 { |
55 elsif ( $activation == IMPL::Config::Descriptor::ACTIVATE_CONTEXT ) { | 60 $cache = $context->container->instances; |
56 $cache = $context->instances; | 61 } |
57 } | 62 elsif ( $activation == IMPL::Config::Descriptor::ACTIVATE_CONTEXT ) |
63 { | |
64 $cache = $context->instances; | |
65 } | |
58 | 66 |
59 my $instance = $cache->{ ref($this) } if $cache; | 67 $instance = $cache->{ ref($this) } if $cache; |
68 unless ($instance) { | |
69 $instance = $this->CreateInstance($context); | |
70 } | |
60 | 71 |
61 unless ($instance) { | 72 $cache->{ ref($this) } = $instance if $cache; |
62 $instance = $this->CreateInstance($context); | 73 } |
63 } | 74 ); |
64 | |
65 $cache->{ ref($this) } = $instance if $cache; | |
66 | |
67 $context->LeaveScope(); | |
68 | 75 |
69 return $instance; | 76 return $instance; |
70 } | 77 } |
71 | 78 |
72 sub CreateInstance { | 79 sub CreateInstance { |