comparison lib/IMPL/Config/ValueDescriptor.pm @ 415:3d24b10dd0d5 ref20150831

working on IMPL::Config::Container
author cin
date Tue, 20 Oct 2015 07:32:55 +0300
parents c6e90e02dd17
children 3ed0c58e9da3
comparison
equal deleted inserted replaced
414:ec6f2d389d1e 415:3d24b10dd0d5
1 package IMPL::Config::ValueDescriptor;
2 use strict;
3
4 use IMPL::lang qw(:base);
5 use IMPL::declare {
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 ]
17 };
18
19 sub CTOR {
20 my ( $this, $value, $raw ) = @_;
21
22 $this->value($value);
23 $this->raw($raw);
24 }
25
26 sub Activate {
27 my ( $this, $context ) = @_;
28
29 return $this->raw
30 ? $this->value
31 : $this->_ActivateValue( $this->value, $context );
32 }
33
34 sub _ActivateValue {
35 my ( $this, $value, $context ) = @_;
36
37 if ( is( $value, Descriptor ) ) {
38 return $value->Activate($context);
39 }
40 elsif ( isarray($value) ) {
41 return [ map $this->_ActivateValue($_), @$value ];
42 }
43 elsif ( ishash($value) ) {
44 return {
45 map { $_, $this->_ActivateValue( $value->{$_} ) }
46 keys %$value
47 };
48 }
49 else {
50 return $value;
51 }
52 }
53
54 1;