Mercurial > pub > Impl
diff lib/IMPL/Config/ServiceDescriptor.pm @ 417:3ed0c58e9da3 ref20150831
working on di container, tests
author | cin |
---|---|
date | Mon, 02 Nov 2015 01:56:53 +0300 |
parents | cc2cf8c0edc2 |
children | df591e3afd10 |
line wrap: on
line diff
--- a/lib/IMPL/Config/ServiceDescriptor.pm Thu Oct 29 03:50:25 2015 +0300 +++ b/lib/IMPL/Config/ServiceDescriptor.pm Mon Nov 02 01:56:53 2015 +0300 @@ -13,10 +13,11 @@ 'IMPL::Config::Descriptor' => undef ], props => [ - type => 'ro', - activation => 'ro', - args => 'ro', - services => 'ro', + type => 'r', + activation => 'r', + args => 'r', + services => 'r', + norequire => 'r', _name => 'rw', _loaded => 'rw' ] @@ -30,8 +31,9 @@ $this->activation( IMPL::Config::Descriptor::ParseActivation( $opts{activation} ) ); - $this->args( $opts{args} ) if exists $opts{args}; - $this->services( $opts{services} ) if exists $opts{services}; + $this->args( $opts{args} ) if exists $opts{args}; + $this->services( $opts{services} ) if exists $opts{services}; + $this->norequire( $opts{norequire} ) if exists $opts{norequire}; $this->_name( 'new {' . IMPL::Config::Descriptor::ActivationToString( $this->activation ) @@ -43,35 +45,29 @@ my ( $this, $context ) = @_; my $instance; - $context->GuardScope( - $this->_name, - $this->services, - sub { + $context->EnterScope( $this->_name, $this->services ); - my $activation = $this->activation; - my $cache; + my $activation = $this->activation; + my $cache; - if ( $activation == IMPL::Config::Descriptor::ACTIVATE_SINGLETON ) { - $cache = $context->container->root->instances; - } - elsif ( - $activation == IMPL::Config::Descriptor::ACTIVATE_CONTAINER ) - { - $cache = $context->container->instances; - } - elsif ( $activation == IMPL::Config::Descriptor::ACTIVATE_CONTEXT ) - { - $cache = $context->instances; - } + if ( $activation == IMPL::Config::Descriptor::ACTIVATE_SINGLETON ) { + $cache = $context->container->root->instances; + } + elsif ( $activation == IMPL::Config::Descriptor::ACTIVATE_CONTAINER ) { + $cache = $context->container->instances; + } + elsif ( $activation == IMPL::Config::Descriptor::ACTIVATE_CONTEXT ) { + $cache = $context->instances; + } - $instance = $cache->{ ref($this) } if $cache; - unless ($instance) { - $instance = $this->CreateInstance($context); - } + $instance = $cache->{ ref($this) } if $cache; + unless ($instance) { + $instance = $this->CreateInstance($context); + } - $cache->{ ref($this) } = $instance if $cache; - } - ); + $cache->{ ref($this) } = $instance if $cache; + + $context->LeaveScope(); return $instance; } @@ -79,7 +75,10 @@ sub CreateInstance { my ( $this, $context ) = @_; - my $class = $context > container->Require( $this->type ); + my $class = + $this->norequire + ? $this->type + : $context->container->Require( $this->type ); my $args = $this->args ? $this->args->Activate($context) : undef;