92
|
1 package IMPL::Config::Resolve;
|
93
|
2 use strict;
|
|
3 use base qw(IMPL::Object IMPL::Object::Serializable);
|
92
|
4
|
|
5 use IMPL::Class::Property;
|
|
6 use IMPL::Exception;
|
|
7
|
|
8 BEGIN {
|
93
|
9 public property path => prop_all|prop_list;
|
92
|
10 }
|
|
11
|
|
12 __PACKAGE__->PassThroughArgs;
|
|
13
|
|
14 sub CTOR {
|
93
|
15 my $this = shift;
|
|
16
|
|
17 my $list = $this->path;
|
92
|
18
|
93
|
19 while(my $name = shift ) {
|
|
20 my $args = shift;
|
|
21 $list->Append({ method => $name, (defined $args ? (args => $args) : ()) });
|
|
22 }
|
|
23
|
|
24 die new IMPL::InvalidArgumentException("The argument is mandatory","path") unless $this->path->Count;
|
92
|
25 }
|
|
26
|
|
27 sub Invoke {
|
93
|
28 my ($this,$target,$default) = @_;
|
92
|
29
|
93
|
30 my $result = $target;
|
|
31 $result = $this->_InvokeMember($result,$_) || return $default foreach $this->path;
|
|
32
|
|
33 return $result;
|
92
|
34 }
|
|
35
|
|
36 sub _InvokeMember {
|
|
37 my ($self,$object,$member) = @_;
|
|
38
|
93
|
39 my $method = $member->{method};
|
|
40
|
92
|
41 local $@;
|
93
|
42 return eval {
|
|
43 ref $object eq 'HASH' ?
|
|
44 $object->{$method}
|
|
45 :
|
|
46 $object->$method(
|
|
47 exists $member->{args} ?
|
|
48 _as_list($member->{args})
|
|
49 :
|
|
50 ()
|
|
51 )
|
|
52 };
|
|
53 }
|
|
54
|
|
55 sub save {
|
|
56 my ($this,$ctx) = @_;
|
|
57
|
|
58 $ctx->AddVar($_->{method},$_->{args}) foreach $this->path;
|
92
|
59 }
|
|
60
|
|
61 sub _as_list {
|
|
62 ref $_[0] ?
|
|
63 (ref $_[0] eq 'HASH' ?
|
|
64 %{$_[0]}
|
|
65 :
|
|
66 (ref $_[0] eq 'ARRAY'?
|
|
67 @{$_[0]}
|
|
68 :
|
|
69 $_[0]
|
|
70 )
|
|
71 )
|
|
72 :
|
|
73 ($_[0]);
|
|
74 }
|
|
75
|
|
76 1;
|