annotate lib/IMPL/Config/ReferenceDescriptor.pm @ 427:09e0086a82a7 ref20150831 tip

Merge
author cin
date Tue, 15 May 2018 00:51:33 +0300
parents b0481c071bea
children
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 {
422
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
6 base => [
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
7 'IMPL::Object' => undef,
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
8 'IMPL::Config::Descriptor' => undef
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
9 ],
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
10 props => [
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
11 reference => 'ro',
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
12 services => 'ro',
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
13 lazy => 'ro',
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
14 optional => 'ro',
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
15 default => 'ro',
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
16 _name => 'rw'
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
17 ]
415
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 {
422
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
21 my ( $this, $ref, %opts ) = @_;
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
22
422
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
23 $this->reference($ref)
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
24 or die IMPL::InvalidArgumentException->new('ref');
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
25
422
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
26 $this->lazy( $opts{lazy} ) if $opts{lazy};
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
27 $this->optional( $opts{optional} ) if $opts{optional};
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
28 $this->default( $opts{default} )
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
29 if $opts{optional} and exists $opts{default};
416
cin
parents: 415
diff changeset
30
422
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
31 $this->_name( 'ref ' . $ref );
415
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 {
422
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
35 my ( $this, $context ) = @_;
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
36
422
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
37 my $ref = $this->reference;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
38 my %opts;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
39 my $inst;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
40 if ( $this->optional ) {
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
41 $opts{optional} = 1;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
42 $opts{default} = $this->default;
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
43 }
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
44
422
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
45 if ( $this->lazy ) {
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
46 my $clone = $context->Clone();
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
47 return sub {
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
48 $clone->Resolve( $ref, %opts );
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
49 };
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
50 }
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
51 else {
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
52 return $context->Resolve( $ref, %opts );
b0481c071bea IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents: 421
diff changeset
53 }
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
54 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
55
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
56 1;
416
cin
parents: 415
diff changeset
57
cin
parents: 415
diff changeset
58 __END__
cin
parents: 415
diff changeset
59
cin
parents: 415
diff changeset
60 =pod
cin
parents: 415
diff changeset
61
cin
parents: 415
diff changeset
62 =head1 NAME
cin
parents: 415
diff changeset
63
cin
parents: 415
diff changeset
64 C<IMPL::Config::ReferenceDescriptor> - A descriptor which is points to the other service
cin
parents: 415
diff changeset
65
cin
parents: 415
diff changeset
66 =head1 MEMBERS
cin
parents: 415
diff changeset
67
cin
parents: 415
diff changeset
68 =head2 PROPS
cin
parents: 415
diff changeset
69
cin
parents: 415
diff changeset
70 =head3 reference
cin
parents: 415
diff changeset
71
cin
parents: 415
diff changeset
72 =head3 lazy
cin
parents: 415
diff changeset
73
cin
parents: 415
diff changeset
74 =head3 optional
cin
parents: 415
diff changeset
75
cin
parents: 415
diff changeset
76 =head3 default
cin
parents: 415
diff changeset
77
cin
parents: 415
diff changeset
78 =head2 METHODS
cin
parents: 415
diff changeset
79
cin
parents: 415
diff changeset
80 =head3 CTOR($ref, %opts)
cin
parents: 415
diff changeset
81
cin
parents: 415
diff changeset
82 =head3 Activate($context)
cin
parents: 415
diff changeset
83
cin
parents: 415
diff changeset
84 Returns a result of the activation of the service specified by the C<reference> property.
cin
parents: 415
diff changeset
85
cin
parents: 415
diff changeset
86 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
87 =cut