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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
92
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
1 package IMPL::Config::Resolve;
93
0667064553ef fixed _is_class in activator
wizard
parents: 92
diff changeset
2 use strict;
165
76515373dac0 Added Class::Template,
wizard
parents: 93
diff changeset
3 use parent qw(IMPL::Object IMPL::Object::Serializable);
92
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
4
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
5 use IMPL::Class::Property;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
6 use IMPL::Exception;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
7
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
8 BEGIN {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
9 public property path => prop_all|prop_list;
92
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
10 }
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
11
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
12 __PACKAGE__->PassThroughArgs;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
13
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
14 sub CTOR {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
15 my $this = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
16
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
17 my $list = $this->path;
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
18
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
19 while(my $name = shift ) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
20 my $args = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
21 $list->Append({ method => $name, (defined $args ? (args => $args) : ()) });
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
22 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
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
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
25 }
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
26
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
27 sub Invoke {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
28 my ($this,$target,$default) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
29
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
30 my $result = $target;
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
31 $result = $this->_InvokeMember($result,$_) || return $default foreach $this->path;
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
32
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
33 return $result;
92
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
34 }
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
35
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
36 sub _InvokeMember {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
37 my ($self,$object,$member) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
38
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
39 my $method = $member->{method};
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
40
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
41 local $@;
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
42 return eval {
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
43 ref $object eq 'HASH' ?
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
44 $object->{$method}
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
45 :
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
46 $object->$method(
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
47 exists $member->{args} ?
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
48 _as_list($member->{args})
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
49 :
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
50 ()
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
51 )
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
52 };
93
0667064553ef fixed _is_class in activator
wizard
parents: 92
diff changeset
53 }
0667064553ef fixed _is_class in activator
wizard
parents: 92
diff changeset
54
0667064553ef fixed _is_class in activator
wizard
parents: 92
diff changeset
55 sub save {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
56 my ($this,$ctx) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
57
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
58 $ctx->AddVar($_->{method},$_->{args}) foreach $this->path;
92
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
59 }
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
60
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
61 sub _as_list {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
62 ref $_[0] ?
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
63 (ref $_[0] eq 'HASH' ?
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
64 %{$_[0]}
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
65 :
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
66 (ref $_[0] eq 'ARRAY'?
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
67 @{$_[0]}
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
68 :
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
69 $_[0]
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
70 )
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
71 )
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
72 :
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
73 ($_[0]);
92
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
74 }
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
75
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
76 1;