annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
1 package IMPL::Config::ReferenceDescriptor;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
2 use strict;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
3
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
4 use IMPL::Exception();
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
5 use IMPL::declare {
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
6 base => [
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
7 'IMPL::Object' => undef,
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
8 'IMPL::Config::Descriptor' => undef
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
9 ],
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
10 props => [
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
11 reference => 'ro',
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
12 services => 'ro',
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
13 lazy => 'ro',
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
14 optional => 'ro',
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
15 default => 'ro',
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
16 _name => 'rw'
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
17 ]
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
18 };
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
19
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
20 sub CTOR {
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
21 my ( $this, $ref, %opts ) = @_;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
22
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
23 $this->reference($ref)
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
24 or die IMPL::InvalidArgumentException->new('ref');
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
25
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
26 $this->_name( 'ref ' . $ref );
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
27 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
28
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
29 sub Activate {
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
30 my ( $this, $context ) = @_;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
31
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
32 $this->EnterScope( $this->_name, $this->services );
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
33
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
34 my $ref = $this->reference;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
35 my %opts;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
36 $opts{default} = $this->default
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
37 if $this->optional;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
38
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
39 if ( $this->lazy ) {
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
40 my $clone = $context->Clone();
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
41 return sub {
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
42 $clone->Resolve( $ref, %opts );
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
43 };
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
44 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
45 else {
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
46 return $context->Resolve( $ref, %opts );
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
47 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
48
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
49 $this->LeaveScope();
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
50 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
51
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
52 1;