# HG changeset patch # User cin # Date 1441005822 -10800 # Node ID cd6c6e61d442319e775e4dff39172c4e0af420b9 # Parent 9ef75f2029be41832e24fe2bd18ca21842996171 Working on DI container diff -r 9ef75f2029be -r cd6c6e61d442 Lib/IMPL/Config/ActivationContext.pm --- a/Lib/IMPL/Config/ActivationContext.pm Fri Aug 28 19:54:53 2015 +0300 +++ b/Lib/IMPL/Config/ActivationContext.pm Mon Aug 31 10:23:42 2015 +0300 @@ -1,5 +1,51 @@ package IMPL::Config::ActivationContext; +use IMPL::Const qw(:prop); +use IMPL::Exception(); +use IMPL::declare { + require => { + PropertyBag => 'IMPL::Config::ServicesBag' + }, + base => { + 'IMPL::Object' => '@_' + }, + props => { + _services => PROP_RW, + _cache => PROP_RW, + _stack => PROP_RW + } +}; + +sub GetService { + my ($this,$serviceId) = @_; + + $this->_services-> +} + +sub EnterScope { + my ($this, $name, $localize) = @_; + + my $info = { name => $name }; + + if ($localize) { + $info->{services} = $this->_services; + + $this->_services(PropertyBag->new($this->_services)); + } + + $this->_stack->Push($info); +} + +sub LeaveScope { + my ($this) = @_; + + my $info = $this->_stack->Pop() + or die IMPL::InvalidOperationException(); + + if ($info->{services}) + $this->_services($info->{services}); +} + 1; __END__ diff -r 9ef75f2029be -r cd6c6e61d442 Lib/IMPL/Config/ServicesBag.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/IMPL/Config/ServicesBag.pm Mon Aug 31 10:23:42 2015 +0300 @@ -0,0 +1,79 @@ +package IMPL::Config::ServicesBag; + +use IMPL::Const qw(:prop); +use IMPL::declare { + base => { + 'IMPL::Object' => undef + }, + props => { + _prototype => PROP_RW, + _nameMap => PROP_RW, + _typeMap => PROP_RW, + _props => PROP_RW, + } +}; + +sub GetDescriptorByName { + my ($this, $name) = @_; + + my $d = $this->_namedMap->{$name}; + if ($d && $d->{valid}) + return $d; + + my $parent = $this->_prototype; + if ($parent && $d = $parent->GetDescriptorByName($name)) + return $this->_namedMap->{$name} = $d; + + return undef; +} + +sub GetDescriptorByType { + my ($this, $type) = @_; + + my $d = $this->_typeMap->{$name}; + if ($d && $d->{valid}) + return $d; + + my $parent = $this->_prototype; + if ($parent && $d = $parent->GetDescriptorByType($name)) + return $this->_typeMap->{$name} = $d; + + return undef; +} + +sub Register + +1; + +__END__ + +=pod + +=head1 NAME + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +Коллекция сервисов построена на прототиптровании экземпляров, т.е. при создании +новой коллекции может указваться базовая коллекция в которой будет происходить +поиск сервисов в случае их отсутсвия в основной. Для оптимизации данного процесса +сервисы кешируются, чтобы избежать можестрвенных операций поиска по иерархии +коллекций, для этого каждый сервис описывается дескриптором: + +=over + +=item * name название под которым сервис зарегистрирован + +=item * type тип сервиса + +=item * service фабрика сервиса + +=item * valid признак того, что дескриптор действителен + +=back + +Если запрашиваемый десриптор не найден это является ошибкой, поэтому негативные +ответы не кешируются + +=cut \ No newline at end of file diff -r 9ef75f2029be -r cd6c6e61d442 Lib/IMPL/Object/List.pm --- a/Lib/IMPL/Object/List.pm Fri Aug 28 19:54:53 2015 +0300 +++ b/Lib/IMPL/Object/List.pm Mon Aug 31 10:23:42 2015 +0300 @@ -2,6 +2,7 @@ use strict; use warnings; +use Carp qw(confess); use parent qw(IMPL::Object::ArrayObject); require IMPL::Exception; @@ -19,10 +20,16 @@ } sub Append { + confess "Appen method is obsolete use Push instead"; push @{$_[0]}, @_[1 .. $#_]; } +sub Push { + push @{$_[0]}, @_[1 .. $#_]; +} + sub AddLast { + confess "Appen method is obsolete use Push instead"; push @{$_[0]}, @_[1 .. $#_]; }