Mercurial > pub > Impl
diff lib/IMPL/Config/ReferenceDescriptor.pm @ 422:b0481c071bea ref20150831
IMPL::Config::Container tests, YAMLConfiguration now works and tested
author | cin |
---|---|
date | Sun, 20 Aug 2017 00:20:41 +0300 |
parents | 7798345304bc |
children |
line wrap: on
line diff
--- a/lib/IMPL/Config/ReferenceDescriptor.pm Sun Jul 16 22:59:39 2017 +0300 +++ b/lib/IMPL/Config/ReferenceDescriptor.pm Sun Aug 20 00:20:41 2017 +0300 @@ -3,57 +3,54 @@ use IMPL::Exception(); use IMPL::declare { - base => [ - 'IMPL::Object' => undef, - 'IMPL::Config::Descriptor' => undef - ], - props => [ - reference => 'ro', - services => 'ro', - lazy => 'ro', - optional => 'ro', - default => 'ro', - _name => 'rw' - ] + base => [ + 'IMPL::Object' => undef, + 'IMPL::Config::Descriptor' => undef + ], + props => [ + reference => 'ro', + services => 'ro', + lazy => 'ro', + optional => 'ro', + default => 'ro', + _name => 'rw' + ] }; sub CTOR { - my ( $this, $ref, %opts ) = @_; + my ( $this, $ref, %opts ) = @_; - $this->reference($ref) - or die IMPL::InvalidArgumentException->new('ref'); + $this->reference($ref) + or die IMPL::InvalidArgumentException->new('ref'); - $this->lazy( $opts{lazy} ) if $opts{lazy}; - $this->optional( $opts{optional} ) if $opts{optional}; - $this->default( $opts{default} ) - if $opts{optional} and exists $opts{default}; + $this->lazy( $opts{lazy} ) if $opts{lazy}; + $this->optional( $opts{optional} ) if $opts{optional}; + $this->default( $opts{default} ) + if $opts{optional} and exists $opts{default}; - $this->_name( 'ref ' . $ref ); + $this->_name( 'ref ' . $ref ); } sub Activate { - my ( $this, $context ) = @_; - - $context->EnterScope( $this->_name, $this->services ); + my ( $this, $context ) = @_; - my $ref = $this->reference; - my %opts; - my $inst; - $opts{default} = $this->default - if $this->optional; + my $ref = $this->reference; + my %opts; + my $inst; + if ( $this->optional ) { + $opts{optional} = 1; + $opts{default} = $this->default; + } - if ( $this->lazy ) { - my $clone = $context->Clone(); - $inst = sub { - $clone->Resolve( $ref, %opts ); - }; - } - else { - $inst = $context->Resolve( $ref, %opts ); - } - - $context->LeaveScope(); - return $inst; + if ( $this->lazy ) { + my $clone = $context->Clone(); + return sub { + $clone->Resolve( $ref, %opts ); + }; + } + else { + return $context->Resolve( $ref, %opts ); + } } 1;