diff 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
line wrap: on
line diff
--- a/lib/IMPL/Config/ValueDescriptor.pm	Sat Feb 25 22:35:26 2017 +0300
+++ b/lib/IMPL/Config/ValueDescriptor.pm	Sun Jul 16 22:59:39 2017 +0300
@@ -3,52 +3,58 @@
 
 use IMPL::lang qw(:base);
 use IMPL::declare {
-	require => {
-		Descriptor => 'IMPL::Config::Descriptor'
-	},
-	base => [
-		'IMPL::Object' => undef,
-		'Descriptor'   => undef
-	],
-	props => [
-		value => 'rw',
-		raw   => 'rw'
-	]
+    require => {
+        Descriptor => 'IMPL::Config::Descriptor'
+    },
+    base => [
+        'IMPL::Object' => undef,
+        'Descriptor'   => undef
+    ],
+    props => [
+        value    => 'rw',
+        raw      => 'rw',
+        services => 'rw'
+    ]
 };
 
 sub CTOR {
-	my ( $this, $value, $raw ) = @_;
+    my ( $this, $value, %opts) = @_;
 
-	$this->value($value);
-	$this->raw($raw);
+    $this->value($value);
+    $this->raw($opts{raw}) if exists $opts{raw};
+    $this->services($opts{services}) if exists $opts{services};
 }
 
 sub Activate {
-	my ( $this, $context ) = @_;
+    my ( $this, $context ) = @_;
+    return $this->value if $this->raw;
+
+    my $services = $this->services;
 
-	return $this->raw
-	  ? $this->value
-	  : $this->_ActivateValue( $this->value, $context );
+    $context->EnterScope( '$value: ' . $this->value, $services ) if $services;
+    my $value = $this->_ActivateValue( $this->value, $context );
+    $context->LeaveScope() if $services;
+    return $value;
 }
 
 sub _ActivateValue {
-	my ( $this, $value, $context ) = @_;
+    my ( $this, $value, $context ) = @_;
 
-	if ( is( $value, Descriptor ) ) {
-		return $value->Activate($context);
-	}
-	elsif ( isarray($value) ) {
-		return [ map $this->_ActivateValue($_, $context), @$value ];
-	}
-	elsif ( ishash($value) ) {
-		return {
-			map { $_, $this->_ActivateValue( $value->{$_}, $context ) }
-			  keys %$value
-		};
-	}
-	else {
-		return $value;
-	}
+    if ( is( $value, Descriptor ) ) {
+        return $value->Activate($context);
+    }
+    elsif ( isarray($value) ) {
+        return [ map $this->_ActivateValue( $_, $context ), @$value ];
+    }
+    elsif ( ishash($value) ) {
+        return {
+            map { $_, $this->_ActivateValue( $value->{$_}, $context ) }
+              keys %$value
+        };
+    }
+    else {
+        return $value;
+    }
 }
 
 1;