view 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
line wrap: on
line source

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',
        services => 'rw'
    ]
};

sub CTOR {
    my ( $this, $value, %opts) = @_;

    $this->value($value);
    $this->raw($opts{raw}) if exists $opts{raw};
    $this->services($opts{services}) if exists $opts{services};
}

sub Activate {
    my ( $this, $context ) = @_;
    return $this->value if $this->raw;

    return $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( $_, $context ), @$value ];
    }
    elsif ( ishash($value) ) {
        return {
            map { $_, $this->_ActivateValue( $value->{$_}, $context ) }
              keys %$value
        };
    }
    else {
        return $value;
    }
}

sub GetName {
    return '$value: ' . shift->value;
}

1;