Mercurial > pub > Impl
comparison lib/IMPL/Config/ReferenceDescriptor.pm @ 415:3d24b10dd0d5 ref20150831
working on IMPL::Config::Container
author | cin |
---|---|
date | Tue, 20 Oct 2015 07:32:55 +0300 |
parents | c6e90e02dd17 |
children | cc2cf8c0edc2 |
comparison
equal
deleted
inserted
replaced
414:ec6f2d389d1e | 415:3d24b10dd0d5 |
---|---|
1 package IMPL::Config::ReferenceDescriptor; | |
2 use strict; | |
3 | |
4 use IMPL::Exception(); | |
5 use IMPL::declare { | |
6 base => [ | |
7 'IMPL::Object' => undef, | |
8 'IMPL::Config::Descriptor' => undef | |
9 ], | |
10 props => [ | |
11 reference => 'ro', | |
12 services => 'ro', | |
13 lazy => 'ro', | |
14 optional => 'ro', | |
15 default => 'ro', | |
16 _name => 'rw' | |
17 ] | |
18 }; | |
19 | |
20 sub CTOR { | |
21 my ( $this, $ref, %opts ) = @_; | |
22 | |
23 $this->reference($ref) | |
24 or die IMPL::InvalidArgumentException->new('ref'); | |
25 | |
26 $this->_name( 'ref ' . $ref ); | |
27 } | |
28 | |
29 sub Activate { | |
30 my ( $this, $context ) = @_; | |
31 | |
32 $this->EnterScope( $this->_name, $this->services ); | |
33 | |
34 my $ref = $this->reference; | |
35 my %opts; | |
36 $opts{default} = $this->default | |
37 if $this->optional; | |
38 | |
39 if ( $this->lazy ) { | |
40 my $clone = $context->Clone(); | |
41 return sub { | |
42 $clone->Resolve( $ref, %opts ); | |
43 }; | |
44 } | |
45 else { | |
46 return $context->Resolve( $ref, %opts ); | |
47 } | |
48 | |
49 $this->LeaveScope(); | |
50 } | |
51 | |
52 1; |