415
|
1 package IMPL::Config::ValueDescriptor;
|
|
2 use strict;
|
|
3
|
|
4 use IMPL::lang qw(:base);
|
|
5 use IMPL::declare {
|
421
|
6 require => {
|
|
7 Descriptor => 'IMPL::Config::Descriptor'
|
|
8 },
|
|
9 base => [
|
|
10 'IMPL::Object' => undef,
|
|
11 'Descriptor' => undef
|
|
12 ],
|
|
13 props => [
|
|
14 value => 'rw',
|
|
15 raw => 'rw',
|
|
16 services => 'rw'
|
|
17 ]
|
415
|
18 };
|
|
19
|
|
20 sub CTOR {
|
421
|
21 my ( $this, $value, %opts) = @_;
|
415
|
22
|
421
|
23 $this->value($value);
|
|
24 $this->raw($opts{raw}) if exists $opts{raw};
|
|
25 $this->services($opts{services}) if exists $opts{services};
|
415
|
26 }
|
|
27
|
|
28 sub Activate {
|
421
|
29 my ( $this, $context ) = @_;
|
|
30 return $this->value if $this->raw;
|
|
31
|
|
32 my $services = $this->services;
|
415
|
33
|
421
|
34 $context->EnterScope( '$value: ' . $this->value, $services ) if $services;
|
|
35 my $value = $this->_ActivateValue( $this->value, $context );
|
|
36 $context->LeaveScope() if $services;
|
|
37 return $value;
|
415
|
38 }
|
|
39
|
|
40 sub _ActivateValue {
|
421
|
41 my ( $this, $value, $context ) = @_;
|
415
|
42
|
421
|
43 if ( is( $value, Descriptor ) ) {
|
|
44 return $value->Activate($context);
|
|
45 }
|
|
46 elsif ( isarray($value) ) {
|
|
47 return [ map $this->_ActivateValue( $_, $context ), @$value ];
|
|
48 }
|
|
49 elsif ( ishash($value) ) {
|
|
50 return {
|
|
51 map { $_, $this->_ActivateValue( $value->{$_}, $context ) }
|
|
52 keys %$value
|
|
53 };
|
|
54 }
|
|
55 else {
|
|
56 return $value;
|
|
57 }
|
415
|
58 }
|
|
59
|
|
60 1;
|