comparison lib/IMPL/Config/ServiceDescriptor.pm @ 420:df591e3afd10 ref20150831

sync
author cin
date Sat, 25 Feb 2017 22:35:26 +0300
parents 3ed0c58e9da3
children 7798345304bc
comparison
equal deleted inserted replaced
419:bbc4739c4d48 420:df591e3afd10
16 type => 'r', 16 type => 'r',
17 activation => 'r', 17 activation => 'r',
18 args => 'r', 18 args => 'r',
19 services => 'r', 19 services => 'r',
20 norequire => 'r', 20 norequire => 'r',
21 owner => 'r',
21 _name => 'rw', 22 _name => 'rw',
22 _loaded => 'rw' 23 _loaded => 'rw'
23 ] 24 ]
24 }; 25 };
25 26
26 sub CTOR { 27 sub CTOR {
27 my ( $this, %opts ) = @_; 28 my ( $this, %opts ) = @_;
28 29
29 $this->type( $opts{type} ) 30 $this->type( $opts{type} )
30 or die IMPL::InvalidArgumentException->new('type'); 31 or die IMPL::InvalidArgumentException->new('type');
32 $this->owner( $opts{owner} )
33 or die IMPL::InvalidArgumentException->new('owner');
31 34
32 $this->activation( 35 $this->activation( SELF->ParseActivation( $opts{activation} ) );
33 IMPL::Config::Descriptor::ParseActivation( $opts{activation} ) );
34 $this->args( $opts{args} ) if exists $opts{args}; 36 $this->args( $opts{args} ) if exists $opts{args};
35 $this->services( $opts{services} ) if exists $opts{services}; 37 $this->services( $opts{services} ) if exists $opts{services};
36 $this->norequire( $opts{norequire} ) if exists $opts{norequire}; 38 $this->norequire( $opts{norequire} ) if exists $opts{norequire};
37 39
38 $this->_name( 'new {' 40 $this->_name( 'new {'
39 . IMPL::Config::Descriptor::ActivationToString( $this->activation ) 41 . SELF->ActivationToString( $this->activation )
40 . '} ' 42 . '} '
41 . $this->type ); 43 . $this->type );
42 } 44 }
43 45
44 sub Activate { 46 sub Activate {
48 $context->EnterScope( $this->_name, $this->services ); 50 $context->EnterScope( $this->_name, $this->services );
49 51
50 my $activation = $this->activation; 52 my $activation = $this->activation;
51 my $cache; 53 my $cache;
52 54
53 if ( $activation == IMPL::Config::Descriptor::ACTIVATE_SINGLETON ) { 55 if ( $activation == SELF->ACTIVATE_SINGLETON ) {
54 $cache = $context->container->root->instances; 56 $cache = $context->container->root->instances;
55 } 57 }
56 elsif ( $activation == IMPL::Config::Descriptor::ACTIVATE_CONTAINER ) { 58 elsif ( $activation == SELF->ACTIVATE_CONTAINER ) {
59 $cache = $this->owner->instances;
60 }
61 elsif ( $activation == SELF->ACTIVATE_HIERARCHY ) {
57 $cache = $context->container->instances; 62 $cache = $context->container->instances;
58 } 63 }
59 elsif ( $activation == IMPL::Config::Descriptor::ACTIVATE_CONTEXT ) { 64 elsif ( $activation == SELF->ACTIVATE_CONTEXT ) {
60 $cache = $context->instances; 65 $cache = $context->instances;
61 } 66 }
62 67
63 $instance = $cache->{ ref($this) } if $cache; 68 $instance = $cache->{ ref($this) } if $cache;
64 unless ($instance) { 69 unless ($instance) {