Mercurial > pub > Impl
comparison lib/IMPL/Config/Container.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 |
comparison
equal
deleted
inserted
replaced
421:7798345304bc | 422:b0481c071bea |
---|---|
1 package IMPL::Config::Container; | 1 package IMPL::Config::Container; |
2 use strict; | 2 use strict; |
3 | 3 use mro; |
4 use Scalar::Util qw(blessed); | 4 use Scalar::Util qw(blessed); |
5 use IMPL::Exception(); | 5 use IMPL::Exception(); |
6 use IMPL::lang qw(:base); | 6 use IMPL::lang qw(:base); |
7 use IMPL::declare { | 7 use IMPL::declare { |
8 require => { | 8 require => { |
15 base => [ | 15 base => [ |
16 'IMPL::Object' => undef, | 16 'IMPL::Object' => undef, |
17 'IMPL::Object::Disposable' => undef | 17 'IMPL::Object::Disposable' => undef |
18 ], | 18 ], |
19 props => [ | 19 props => [ |
20 roles => 'r', | 20 roles => 'r', |
21 services => 'r', | 21 services => 'r', |
22 instances => 'r', | 22 serviceCache => 'r', |
23 parent => 'r', | 23 instances => 'r', |
24 root => 'r', | 24 parent => 'r', |
25 loader => 'r' | 25 root => 'r', |
26 loader => 'r' | |
26 ] | 27 ] |
27 }; | 28 }; |
28 | 29 |
29 my $nextRoleId = 1; | 30 my $nextRoleId = 1; |
30 | 31 |
44 else { | 45 else { |
45 $this->roles( Hierarchy->new() ); | 46 $this->roles( Hierarchy->new() ); |
46 $this->services( Bag->new() ); | 47 $this->services( Bag->new() ); |
47 $this->root($this); | 48 $this->root($this); |
48 } | 49 } |
50 | |
51 $this->services->tag($this); | |
49 } | 52 } |
50 | 53 |
51 sub Dispose { | 54 sub Dispose { |
52 my ($this) = @_; | 55 my ($this) = @_; |
53 | 56 |
55 foreach my $v ( values %{ $this->instances } ) { | 58 foreach my $v ( values %{ $this->instances } ) { |
56 if ( $d = blessed($v) && $v->can('Dispose') ) { | 59 if ( $d = blessed($v) && $v->can('Dispose') ) { |
57 &$d($v); | 60 &$d($v); |
58 } | 61 } |
59 } | 62 } |
63 | |
64 $this->next::method(); | |
60 } | 65 } |
61 | 66 |
62 sub Require { | 67 sub Require { |
63 my ( $this, $class ) = @_; | 68 my ( $this, $class ) = @_; |
64 | 69 |
88 | 93 |
89 $this->roles->GetLinearRoleHash($role); | 94 $this->roles->GetLinearRoleHash($role); |
90 } | 95 } |
91 | 96 |
92 sub Resolve { | 97 sub Resolve { |
93 my ( $this, $role, %opts ) = @_; | 98 my ( $this, $role ) = @_; |
94 | 99 |
95 my $descriptor = $this->services->Resolve($role); | 100 my $descriptor = $this->services->Resolve($role); |
96 | 101 |
97 return $descriptor->Activate( ActivationContext->new($this) ) | 102 return ActivationContext->new($this)->Activate($descriptor) |
98 if $descriptor; | 103 if $descriptor; |
99 | |
100 return $opts{default} if exists $opts{default}; | |
101 } | 104 } |
102 | 105 |
103 sub ResolveAll { | 106 sub ResolveAll { |
104 my ( $this, $role, %opts ) = @_; | 107 my ( $this, $role, %opts ) = @_; |
105 | 108 |
111 | 114 |
112 foreach my $service (@$all) { | 115 foreach my $service (@$all) { |
113 $context = ActivationContext->new($this) | 116 $context = ActivationContext->new($this) |
114 unless $context && $opts{shared}; | 117 unless $context && $opts{shared}; |
115 | 118 |
116 push @result, $service->Activate($context); | 119 push @result, $context->Activate($service); |
117 } | 120 } |
118 | 121 |
119 return \@result; | 122 return \@result; |
120 } | 123 } |
121 | 124 |