Mercurial > pub > Impl
annotate lib/IMPL/Config/ValueDescriptor.pm @ 422:b0481c071bea ref20150831
IMPL::Config::Container tests, YAMLConfiguration now works and tested
author | cin |
---|---|
date | Sun, 20 Aug 2017 00:20:41 +0300 |
parents | 7798345304bc |
children |
rev | line source |
---|---|
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 | |
422
b0481c071bea
IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
421
diff
changeset
|
32 return $this->_ActivateValue( $this->value, $context ); |
415 | 33 } |
34 | |
35 sub _ActivateValue { | |
421 | 36 my ( $this, $value, $context ) = @_; |
415 | 37 |
421 | 38 if ( is( $value, Descriptor ) ) { |
39 return $value->Activate($context); | |
40 } | |
41 elsif ( isarray($value) ) { | |
42 return [ map $this->_ActivateValue( $_, $context ), @$value ]; | |
43 } | |
44 elsif ( ishash($value) ) { | |
45 return { | |
46 map { $_, $this->_ActivateValue( $value->{$_}, $context ) } | |
47 keys %$value | |
48 }; | |
49 } | |
50 else { | |
51 return $value; | |
52 } | |
415 | 53 } |
54 | |
422
b0481c071bea
IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
421
diff
changeset
|
55 sub GetName { |
b0481c071bea
IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
421
diff
changeset
|
56 return '$value: ' . shift->value; |
b0481c071bea
IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
421
diff
changeset
|
57 } |
b0481c071bea
IMPL::Config::Container tests, YAMLConfiguration now works and tested
cin
parents:
421
diff
changeset
|
58 |
415 | 59 1; |