comparison Lib/IMPL/Config/Resolve.pm @ 93:0667064553ef

fixed _is_class in activator rewritten IMPL::Config::Resolve new features in the Abstract class
author wizard
date Wed, 28 Apr 2010 17:50:55 +0400
parents 5f676b61fb8b
children 76515373dac0
comparison
equal deleted inserted replaced
92:5f676b61fb8b 93:0667064553ef
1 package IMPL::Config::Resolve; 1 package IMPL::Config::Resolve;
2 use base qw(IMPL::Object IMPL::Object::Autofill IMPL::Object::Serializable); 2 use strict;
3 use base qw(IMPL::Object IMPL::Object::Serializable);
3 4
4 use IMPL::Class::Property; 5 use IMPL::Class::Property;
5 use IMPL::Exception; 6 use IMPL::Exception;
6 7
7 BEGIN { 8 BEGIN {
8 public property target => prop_all; 9 public property path => prop_all|prop_list;
9 public property path => prop_all;
10 public property default => prop_all
11 } 10 }
12 11
13 __PACKAGE__->PassThroughArgs; 12 __PACKAGE__->PassThroughArgs;
14 13
15 sub CTOR { 14 sub CTOR {
16 my ($this) = @_; 15 my $this = shift;
17 16
18 die new IMPL::InvalidArgumentException("The argument is mandatory","target") unless $this->target; 17 my $list = $this->path;
19 die new IMPL::InvalidArgumentException("The argument is mandatory","path") unless $this->path; 18
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;
20 } 25 }
21 26
22 sub Invoke { 27 sub Invoke {
23 my ($this) = @_; 28 my ($this,$target,$default) = @_;
24 29
25 my $path = $this->path; 30 my $result = $target;
31 $result = $this->_InvokeMember($result,$_) || return $default foreach $this->path;
26 32
27 if (ref $path eq 'ARRAY') { 33 return $result;
28 my $result = $this->target;
29 $result = $this->_InvokeMember($result,$_) || return $this->default foreach @$path;
30 return $result;
31 } elsif (not ref $path) {
32 my $result = $this->target;
33 $result = $this->_InvokeMember($result,$_) || return $this->default foreach map { name => $_},split /\./,$this->path;
34 return $result;
35 } else {
36 die new IMPL::InvalidOperationException("Unsopported path type",ref $path);
37 }
38 } 34 }
39 35
40 sub _InvokeMember { 36 sub _InvokeMember {
41 my ($self,$object,$member) = @_; 37 my ($self,$object,$member) = @_;
42 38
39 my $method = $member->{method};
40
43 local $@; 41 local $@;
44 return eval { $object->($member->{method})(exists $member->{parameters} ? _as_list($member->{parameters}) : ()) }; 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;
45 } 59 }
46 60
47 sub _as_list { 61 sub _as_list {
48 ref $_[0] ? 62 ref $_[0] ?
49 (ref $_[0] eq 'HASH' ? 63 (ref $_[0] eq 'HASH' ?