Mercurial > pub > Impl
comparison lib/IMPL/Config/ValueDescriptor.pm @ 421:7798345304bc ref20150831
working on IMPL::Config, removed old stuff
| author | cin |
|---|---|
| date | Sun, 16 Jul 2017 22:59:39 +0300 |
| parents | 3ed0c58e9da3 |
| children | b0481c071bea |
comparison
equal
deleted
inserted
replaced
| 420:df591e3afd10 | 421:7798345304bc |
|---|---|
| 1 package IMPL::Config::ValueDescriptor; | 1 package IMPL::Config::ValueDescriptor; |
| 2 use strict; | 2 use strict; |
| 3 | 3 |
| 4 use IMPL::lang qw(:base); | 4 use IMPL::lang qw(:base); |
| 5 use IMPL::declare { | 5 use IMPL::declare { |
| 6 require => { | 6 require => { |
| 7 Descriptor => 'IMPL::Config::Descriptor' | 7 Descriptor => 'IMPL::Config::Descriptor' |
| 8 }, | 8 }, |
| 9 base => [ | 9 base => [ |
| 10 'IMPL::Object' => undef, | 10 'IMPL::Object' => undef, |
| 11 'Descriptor' => undef | 11 'Descriptor' => undef |
| 12 ], | 12 ], |
| 13 props => [ | 13 props => [ |
| 14 value => 'rw', | 14 value => 'rw', |
| 15 raw => 'rw' | 15 raw => 'rw', |
| 16 ] | 16 services => 'rw' |
| 17 ] | |
| 17 }; | 18 }; |
| 18 | 19 |
| 19 sub CTOR { | 20 sub CTOR { |
| 20 my ( $this, $value, $raw ) = @_; | 21 my ( $this, $value, %opts) = @_; |
| 21 | 22 |
| 22 $this->value($value); | 23 $this->value($value); |
| 23 $this->raw($raw); | 24 $this->raw($opts{raw}) if exists $opts{raw}; |
| 25 $this->services($opts{services}) if exists $opts{services}; | |
| 24 } | 26 } |
| 25 | 27 |
| 26 sub Activate { | 28 sub Activate { |
| 27 my ( $this, $context ) = @_; | 29 my ( $this, $context ) = @_; |
| 30 return $this->value if $this->raw; | |
| 28 | 31 |
| 29 return $this->raw | 32 my $services = $this->services; |
| 30 ? $this->value | 33 |
| 31 : $this->_ActivateValue( $this->value, $context ); | 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; | |
| 32 } | 38 } |
| 33 | 39 |
| 34 sub _ActivateValue { | 40 sub _ActivateValue { |
| 35 my ( $this, $value, $context ) = @_; | 41 my ( $this, $value, $context ) = @_; |
| 36 | 42 |
| 37 if ( is( $value, Descriptor ) ) { | 43 if ( is( $value, Descriptor ) ) { |
| 38 return $value->Activate($context); | 44 return $value->Activate($context); |
| 39 } | 45 } |
| 40 elsif ( isarray($value) ) { | 46 elsif ( isarray($value) ) { |
| 41 return [ map $this->_ActivateValue($_, $context), @$value ]; | 47 return [ map $this->_ActivateValue( $_, $context ), @$value ]; |
| 42 } | 48 } |
| 43 elsif ( ishash($value) ) { | 49 elsif ( ishash($value) ) { |
| 44 return { | 50 return { |
| 45 map { $_, $this->_ActivateValue( $value->{$_}, $context ) } | 51 map { $_, $this->_ActivateValue( $value->{$_}, $context ) } |
| 46 keys %$value | 52 keys %$value |
| 47 }; | 53 }; |
| 48 } | 54 } |
| 49 else { | 55 else { |
| 50 return $value; | 56 return $value; |
| 51 } | 57 } |
| 52 } | 58 } |
| 53 | 59 |
| 54 1; | 60 1; |
