annotate Lib/IMPL/Config/Resolve.pm @ 92:5f676b61fb8b

IMPL::Config::Resolve alpha version
author wizard
date Tue, 27 Apr 2010 20:10:07 +0400
parents
children 0667064553ef
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;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
2 use base qw(IMPL::Object IMPL::Object::Autofill IMPL::Object::Serializable);
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
3
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
4 use IMPL::Class::Property;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
5 use IMPL::Exception;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
6
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
7 BEGIN {
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
8 public property target => prop_all;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
9 public property path => prop_all;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
10 public property default => prop_all
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
11 }
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
12
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
13 __PACKAGE__->PassThroughArgs;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
14
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
15 sub CTOR {
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
16 my ($this) = @_;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
17
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
18 die new IMPL::InvalidArgumentException("The argument is mandatory","target") unless $this->target;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
19 die new IMPL::InvalidArgumentException("The argument is mandatory","path") unless $this->path;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
20 }
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
21
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
22 sub Invoke {
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
23 my ($this) = @_;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
24
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
25 my $path = $this->path;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
26
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
27 if (ref $path eq 'ARRAY') {
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
28 my $result = $this->target;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
29 $result = $this->_InvokeMember($result,$_) || return $this->default foreach @$path;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
30 return $result;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
31 } elsif (not ref $path) {
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
32 my $result = $this->target;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
33 $result = $this->_InvokeMember($result,$_) || return $this->default foreach map { name => $_},split /\./,$this->path;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
34 return $result;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
35 } else {
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
36 die new IMPL::InvalidOperationException("Unsopported path type",ref $path);
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
37 }
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
38 }
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
39
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
40 sub _InvokeMember {
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
41 my ($self,$object,$member) = @_;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
42
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
43 local $@;
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
44 return eval { $object->($member->{method})(exists $member->{parameters} ? _as_list($member->{parameters}) : ()) };
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
45 }
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
46
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
47 sub _as_list {
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
48 ref $_[0] ?
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
49 (ref $_[0] eq 'HASH' ?
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
50 %{$_[0]}
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
51 :
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
52 (ref $_[0] eq 'ARRAY'?
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
53 @{$_[0]}
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
54 :
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
55 $_[0]
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
56 )
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
57 )
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
58 :
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
59 ($_[0]);
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
60 }
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
61
5f676b61fb8b IMPL::Config::Resolve alpha version
wizard
parents:
diff changeset
62 1;