annotate 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
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 {
421
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
6 require => {
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
7 Descriptor => 'IMPL::Config::Descriptor'
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
8 },
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
9 base => [
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
10 'IMPL::Object' => undef,
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
11 'Descriptor' => undef
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
12 ],
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
13 props => [
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
14 value => 'rw',
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
15 raw => 'rw',
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
16 services => 'rw'
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
17 ]
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
18 };
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
19
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
20 sub CTOR {
421
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
21 my ( $this, $value, %opts) = @_;
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
22
421
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
23 $this->value($value);
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
24 $this->raw($opts{raw}) if exists $opts{raw};
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
25 $this->services($opts{services}) if exists $opts{services};
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
26 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
27
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
28 sub Activate {
421
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
29 my ( $this, $context ) = @_;
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
30 return $this->value if $this->raw;
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
31
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
32 my $services = $this->services;
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
33
421
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
34 $context->EnterScope( '$value: ' . $this->value, $services ) if $services;
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
35 my $value = $this->_ActivateValue( $this->value, $context );
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
36 $context->LeaveScope() if $services;
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
37 return $value;
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
38 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
39
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
40 sub _ActivateValue {
421
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
41 my ( $this, $value, $context ) = @_;
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
42
421
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
43 if ( is( $value, Descriptor ) ) {
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
44 return $value->Activate($context);
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
45 }
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
46 elsif ( isarray($value) ) {
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
47 return [ map $this->_ActivateValue( $_, $context ), @$value ];
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
48 }
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
49 elsif ( ishash($value) ) {
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
50 return {
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
51 map { $_, $this->_ActivateValue( $value->{$_}, $context ) }
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
52 keys %$value
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
53 };
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
54 }
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
55 else {
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
56 return $value;
7798345304bc working on IMPL::Config, removed old stuff
cin
parents: 417
diff changeset
57 }
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
58 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
59
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 407
diff changeset
60 1;