Mercurial > pub > Impl
annotate Lib/IMPL/Config/Resolve.pm @ 206:c8fe3f84feba
+IMPL::Web::Handlers::ViewSelector
+IMPL::Web::Handlers::ErrorHandler
*IMPL::Web::Handlers::RestController moved types mappings to ViewSelector
author | sergey |
---|---|
date | Thu, 03 May 2012 16:48:39 +0400 |
parents | e743a8481327 |
children | f534a60d5b01 |
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; | |
206 | 7 use Carp qw(carp); |
92 | 8 |
9 BEGIN { | |
194 | 10 public property path => prop_all|prop_list; |
206 | 11 carp "deprecated"; |
92 | 12 } |
13 | |
14 __PACKAGE__->PassThroughArgs; | |
15 | |
16 sub CTOR { | |
194 | 17 my $this = shift; |
18 | |
19 my $list = $this->path; | |
20 | |
21 while(my $name = shift ) { | |
22 my $args = shift; | |
23 $list->Append({ method => $name, (defined $args ? (args => $args) : ()) }); | |
24 } | |
25 | |
199
e743a8481327
Added REST support for forms (with only get and post methods)
sergey
parents:
194
diff
changeset
|
26 #die new IMPL::InvalidArgumentException("The argument is mandatory","path") unless $this->path->Count; |
92 | 27 } |
28 | |
29 sub Invoke { | |
194 | 30 my ($this,$target,$default) = @_; |
31 | |
32 my $result = $target; | |
33 $result = $this->_InvokeMember($result,$_) || return $default foreach $this->path; | |
34 | |
35 return $result; | |
92 | 36 } |
37 | |
38 sub _InvokeMember { | |
194 | 39 my ($self,$object,$member) = @_; |
40 | |
41 my $method = $member->{method}; | |
42 | |
43 local $@; | |
44 return eval { | |
45 ref $object eq 'HASH' ? | |
46 $object->{$method} | |
47 : | |
48 $object->$method( | |
49 exists $member->{args} ? | |
50 _as_list($member->{args}) | |
51 : | |
52 () | |
53 ) | |
54 }; | |
93 | 55 } |
56 | |
57 sub save { | |
194 | 58 my ($this,$ctx) = @_; |
59 | |
60 $ctx->AddVar($_->{method},$_->{args}) foreach $this->path; | |
92 | 61 } |
62 | |
63 sub _as_list { | |
194 | 64 ref $_[0] ? |
65 (ref $_[0] eq 'HASH' ? | |
66 %{$_[0]} | |
67 : | |
68 (ref $_[0] eq 'ARRAY'? | |
69 @{$_[0]} | |
70 : | |
71 $_[0] | |
72 ) | |
73 ) | |
74 : | |
75 ($_[0]); | |
92 | 76 } |
77 | |
78 1; |