Mercurial > pub > Impl
diff 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 |
line wrap: on
line diff
--- a/lib/IMPL/Config/ValueDescriptor.pm Fri Oct 02 06:56:24 2015 +0300 +++ b/lib/IMPL/Config/ValueDescriptor.pm Tue Oct 20 07:32:55 2015 +0300 @@ -0,0 +1,54 @@ +package IMPL::Config::ValueDescriptor; +use strict; + +use IMPL::lang qw(:base); +use IMPL::declare { + require => { + Descriptor => 'IMPL::Config::Descriptor' + }, + base => [ + 'IMPL::Object' => undef, + 'Descriptor' => undef + ], + props => [ + value => 'rw', + raw => 'rw' + ] +}; + +sub CTOR { + my ( $this, $value, $raw ) = @_; + + $this->value($value); + $this->raw($raw); +} + +sub Activate { + my ( $this, $context ) = @_; + + return $this->raw + ? $this->value + : $this->_ActivateValue( $this->value, $context ); +} + +sub _ActivateValue { + my ( $this, $value, $context ) = @_; + + if ( is( $value, Descriptor ) ) { + return $value->Activate($context); + } + elsif ( isarray($value) ) { + return [ map $this->_ActivateValue($_), @$value ]; + } + elsif ( ishash($value) ) { + return { + map { $_, $this->_ActivateValue( $value->{$_} ) } + keys %$value + }; + } + else { + return $value; + } +} + +1;