Mercurial > pub > Impl
annotate Lib/IMPL/Config/Resolve.pm @ 205:891c04080658
IMPL::Web::View fixed template selection, release candidate
author | sergey |
---|---|
date | Thu, 03 May 2012 01:00:02 +0400 |
parents | e743a8481327 |
children | c8fe3f84feba |
rev | line source |
---|---|
92 | 1 package IMPL::Config::Resolve; |
93 | 2 use strict; |
165 | 3 use parent qw(IMPL::Object IMPL::Object::Serializable); |
92 | 4 |
5 use IMPL::Class::Property; | |
6 use IMPL::Exception; | |
7 | |
8 BEGIN { | |
194 | 9 public property path => prop_all|prop_list; |
92 | 10 } |
11 | |
12 __PACKAGE__->PassThroughArgs; | |
13 | |
14 sub CTOR { | |
194 | 15 my $this = shift; |
16 | |
17 my $list = $this->path; | |
18 | |
19 while(my $name = shift ) { | |
20 my $args = shift; | |
21 $list->Append({ method => $name, (defined $args ? (args => $args) : ()) }); | |
22 } | |
23 | |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
194
diff
changeset
|
24 #die new IMPL::InvalidArgumentException("The argument is mandatory","path") unless $this->path->Count; |
92 | 25 } |
26 | |
27 sub Invoke { | |
194 | 28 my ($this,$target,$default) = @_; |
29 | |
30 my $result = $target; | |
31 $result = $this->_InvokeMember($result,$_) || return $default foreach $this->path; | |
32 | |
33 return $result; | |
92 | 34 } |
35 | |
36 sub _InvokeMember { | |
194 | 37 my ($self,$object,$member) = @_; |
38 | |
39 my $method = $member->{method}; | |
40 | |
41 local $@; | |
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 }; | |
93 | 53 } |
54 | |
55 sub save { | |
194 | 56 my ($this,$ctx) = @_; |
57 | |
58 $ctx->AddVar($_->{method},$_->{args}) foreach $this->path; | |
92 | 59 } |
60 | |
61 sub _as_list { | |
194 | 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]); | |
92 | 74 } |
75 | |
76 1; |