Mercurial > pub > Impl
comparison Lib/IMPL/Config/Resolve.pm @ 194:4d0e1962161c
Replaced tabs with spaces
IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author | cin |
---|---|
date | Tue, 10 Apr 2012 20:08:29 +0400 |
parents | 76515373dac0 |
children | e743a8481327 |
comparison
equal
deleted
inserted
replaced
193:8e8401c0aea4 | 194:4d0e1962161c |
---|---|
4 | 4 |
5 use IMPL::Class::Property; | 5 use IMPL::Class::Property; |
6 use IMPL::Exception; | 6 use IMPL::Exception; |
7 | 7 |
8 BEGIN { | 8 BEGIN { |
9 public property path => prop_all|prop_list; | 9 public property path => prop_all|prop_list; |
10 } | 10 } |
11 | 11 |
12 __PACKAGE__->PassThroughArgs; | 12 __PACKAGE__->PassThroughArgs; |
13 | 13 |
14 sub CTOR { | 14 sub CTOR { |
15 my $this = shift; | 15 my $this = shift; |
16 | 16 |
17 my $list = $this->path; | 17 my $list = $this->path; |
18 | 18 |
19 while(my $name = shift ) { | 19 while(my $name = shift ) { |
20 my $args = shift; | 20 my $args = shift; |
21 $list->Append({ method => $name, (defined $args ? (args => $args) : ()) }); | 21 $list->Append({ method => $name, (defined $args ? (args => $args) : ()) }); |
22 } | 22 } |
23 | 23 |
24 die new IMPL::InvalidArgumentException("The argument is mandatory","path") unless $this->path->Count; | 24 die new IMPL::InvalidArgumentException("The argument is mandatory","path") unless $this->path->Count; |
25 } | 25 } |
26 | 26 |
27 sub Invoke { | 27 sub Invoke { |
28 my ($this,$target,$default) = @_; | 28 my ($this,$target,$default) = @_; |
29 | 29 |
30 my $result = $target; | 30 my $result = $target; |
31 $result = $this->_InvokeMember($result,$_) || return $default foreach $this->path; | 31 $result = $this->_InvokeMember($result,$_) || return $default foreach $this->path; |
32 | 32 |
33 return $result; | 33 return $result; |
34 } | 34 } |
35 | 35 |
36 sub _InvokeMember { | 36 sub _InvokeMember { |
37 my ($self,$object,$member) = @_; | 37 my ($self,$object,$member) = @_; |
38 | 38 |
39 my $method = $member->{method}; | 39 my $method = $member->{method}; |
40 | 40 |
41 local $@; | 41 local $@; |
42 return eval { | 42 return eval { |
43 ref $object eq 'HASH' ? | 43 ref $object eq 'HASH' ? |
44 $object->{$method} | 44 $object->{$method} |
45 : | 45 : |
46 $object->$method( | 46 $object->$method( |
47 exists $member->{args} ? | 47 exists $member->{args} ? |
48 _as_list($member->{args}) | 48 _as_list($member->{args}) |
49 : | 49 : |
50 () | 50 () |
51 ) | 51 ) |
52 }; | 52 }; |
53 } | 53 } |
54 | 54 |
55 sub save { | 55 sub save { |
56 my ($this,$ctx) = @_; | 56 my ($this,$ctx) = @_; |
57 | 57 |
58 $ctx->AddVar($_->{method},$_->{args}) foreach $this->path; | 58 $ctx->AddVar($_->{method},$_->{args}) foreach $this->path; |
59 } | 59 } |
60 | 60 |
61 sub _as_list { | 61 sub _as_list { |
62 ref $_[0] ? | 62 ref $_[0] ? |
63 (ref $_[0] eq 'HASH' ? | 63 (ref $_[0] eq 'HASH' ? |
64 %{$_[0]} | 64 %{$_[0]} |
65 : | 65 : |
66 (ref $_[0] eq 'ARRAY'? | 66 (ref $_[0] eq 'ARRAY'? |
67 @{$_[0]} | 67 @{$_[0]} |
68 : | 68 : |
69 $_[0] | 69 $_[0] |
70 ) | 70 ) |
71 ) | 71 ) |
72 : | 72 : |
73 ($_[0]); | 73 ($_[0]); |
74 } | 74 } |
75 | 75 |
76 1; | 76 1; |