annotate lib/IMPL/Config/ValueDescriptor.pm @ 417:3ed0c58e9da3 ref20150831

working on di container, tests
author cin
date Mon, 02 Nov 2015 01:56:53 +0300
parents 3d24b10dd0d5
children 7798345304bc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
1 package IMPL::Config::ValueDescriptor;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
2 use strict;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
3
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
4 use IMPL::lang qw(:base);
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
5 use IMPL::declare {
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
6 require => {
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
7 Descriptor => 'IMPL::Config::Descriptor'
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
8 },
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
9 base => [
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
10 'IMPL::Object' => undef,
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
11 'Descriptor' => undef
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
12 ],
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
13 props => [
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
14 value => 'rw',
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
15 raw => 'rw'
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
16 ]
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
17 };
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
18
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
19 sub CTOR {
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
20 my ( $this, $value, $raw ) = @_;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
21
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
22 $this->value($value);
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
23 $this->raw($raw);
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
24 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
25
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
26 sub Activate {
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
27 my ( $this, $context ) = @_;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
28
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
29 return $this->raw
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
30 ? $this->value
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
31 : $this->_ActivateValue( $this->value, $context );
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
32 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
33
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
34 sub _ActivateValue {
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
35 my ( $this, $value, $context ) = @_;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
36
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
37 if ( is( $value, Descriptor ) ) {
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
38 return $value->Activate($context);
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
39 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
40 elsif ( isarray($value) ) {
417
3ed0c58e9da3 working on di container, tests
cin
parents: 415
diff changeset
41 return [ map $this->_ActivateValue($_, $context), @$value ];
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
42 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
43 elsif ( ishash($value) ) {
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
44 return {
417
3ed0c58e9da3 working on di container, tests
cin
parents: 415
diff changeset
45 map { $_, $this->_ActivateValue( $value->{$_}, $context ) }
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
46 keys %$value
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
47 };
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
48 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
49 else {
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
50 return $value;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
51 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
52 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
53
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
54 1;