annotate lib/IMPL/Config/ReferenceDescriptor.pm @ 421:7798345304bc ref20150831

working on IMPL::Config, removed old stuff
author cin
date Sun, 16 Jul 2017 22:59:39 +0300
parents 3ed0c58e9da3
children b0481c071bea
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
416
cin
parents: 415
diff changeset
26 $this->lazy( $opts{lazy} ) if $opts{lazy};
cin
parents: 415
diff changeset
27 $this->optional( $opts{optional} ) if $opts{optional};
cin
parents: 415
diff changeset
28 $this->default( $opts{default} )
cin
parents: 415
diff changeset
29 if $opts{optional} and exists $opts{default};
cin
parents: 415
diff changeset
30
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
31 $this->_name( 'ref ' . $ref );
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
32 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
33
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
34 sub Activate {
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
35 my ( $this, $context ) = @_;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
36
417
3ed0c58e9da3 working on di container, tests
cin
parents: 416
diff changeset
37 $context->EnterScope( $this->_name, $this->services );
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
38
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
39 my $ref = $this->reference;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
40 my %opts;
421
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
41 my $inst;
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
42 $opts{default} = $this->default
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
43 if $this->optional;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
44
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
45 if ( $this->lazy ) {
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
46 my $clone = $context->Clone();
421
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
47 $inst = sub {
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
48 $clone->Resolve( $ref, %opts );
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
49 };
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
50 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
51 else {
421
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
52 $inst = $context->Resolve( $ref, %opts );
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
53 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
54
417
3ed0c58e9da3 working on di container, tests
cin
parents: 416
diff changeset
55 $context->LeaveScope();
421
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
56 return $inst;
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
57 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
58
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
59 1;
416
cin
parents: 415
diff changeset
60
cin
parents: 415
diff changeset
61 __END__
cin
parents: 415
diff changeset
62
cin
parents: 415
diff changeset
63 =pod
cin
parents: 415
diff changeset
64
cin
parents: 415
diff changeset
65 =head1 NAME
cin
parents: 415
diff changeset
66
cin
parents: 415
diff changeset
67 C<IMPL::Config::ReferenceDescriptor> - A descriptor which is points to the other service
cin
parents: 415
diff changeset
68
cin
parents: 415
diff changeset
69 =head1 MEMBERS
cin
parents: 415
diff changeset
70
cin
parents: 415
diff changeset
71 =head2 PROPS
cin
parents: 415
diff changeset
72
cin
parents: 415
diff changeset
73 =head3 reference
cin
parents: 415
diff changeset
74
cin
parents: 415
diff changeset
75 =head3 lazy
cin
parents: 415
diff changeset
76
cin
parents: 415
diff changeset
77 =head3 optional
cin
parents: 415
diff changeset
78
cin
parents: 415
diff changeset
79 =head3 default
cin
parents: 415
diff changeset
80
cin
parents: 415
diff changeset
81 =head2 METHODS
cin
parents: 415
diff changeset
82
cin
parents: 415
diff changeset
83 =head3 CTOR($ref, %opts)
cin
parents: 415
diff changeset
84
cin
parents: 415
diff changeset
85 =head3 Activate($context)
cin
parents: 415
diff changeset
86
cin
parents: 415
diff changeset
87 Returns a result of the activation of the service specified by the C<reference> property.
cin
parents: 415
diff changeset
88
cin
parents: 415
diff changeset
89 If the reference is lazy the method returns a closure.The C<$context> will be cloned and the clone will be used to create the closure.
cin
parents: 415
diff changeset
90 =cut