| 
415
 | 
     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;
 |