Mercurial > pub > Impl
diff lib/IMPL/Config/ServiceDescriptor.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/ServiceDescriptor.pm Sun Jul 16 22:59:39 2017 +0300 +++ b/lib/IMPL/Config/ServiceDescriptor.pm Sun Aug 20 00:20:41 2017 +0300 @@ -18,7 +18,6 @@ args => 'r', services => 'r', norequire => 'r', - owner => 'r', _name => 'rw', _loaded => 'rw' ] @@ -29,8 +28,6 @@ $this->type( $opts{type} ) or die IMPL::InvalidArgumentException->new('type'); - $this->owner( $opts{owner} ) - or die IMPL::InvalidArgumentException->new('owner'); $this->activation( SELF->ParseActivation( $opts{activation} ) ); $this->args( $opts{args} ) if exists $opts{args}; @@ -43,11 +40,9 @@ } sub Activate { - my ( $this, $context ) = @_; + my ( $this, $context) = @_; my $instance; - $context->EnterScope( $this->_name, $this->services ); - my $activation = $this->activation; my $cache; @@ -55,10 +50,10 @@ $cache = $context->container->root->instances; } elsif ( $activation == SELF->ACTIVATE_CONTAINER ) { - $cache = $this->owner->instances; + $cache = $context->container->instances; } elsif ( $activation == SELF->ACTIVATE_HIERARCHY ) { - $cache = $context->container->instances; + $cache = $context->owner->instances; } elsif ( $activation == SELF->ACTIVATE_CONTEXT ) { $cache = $context->instances; @@ -70,35 +65,39 @@ $cache->{ ref($this) } = $instance if $cache; } - $context->LeaveScope(); - return $instance; } sub CreateInstance { - my ( $this, $context ) = @_; + my ( $this, $context) = @_; my $class = $this->norequire ? $this->type : $context->container->Require( $this->type ); - - my $args = $this->args ? $this->args->Activate($context) : undef; - - if ( defined $args ) { - if ( isarray($args) ) { - return $class->new(@$args); + + + # determine how to pass arguments + if (isarray($this->args)) { + # if args is an array ref, pass it as list + return $class->new(map $context->Activate($_), @{$this->args}); + } elsif (ishash($this->args)) { + # if args is a hash ref, pass it as list + my %args; + while(my ($k,$v) = each %{$this->args}) { + $args{$k} = $context->Activate($v); } - elsif ( ishash($args) ) { - return $class->new(%$args); - } - else { - return $class->new($args); - } - } - else { + return $class->new(%args); + } elsif(defined $this->args) { + # otherwise pass it as a single argument + return $class->new($context->Activate($this->args)); + } else { return $class->new(); } } +sub GetName { + shift->_name; +} + 1;