# HG changeset patch # User wizard # Date 1272384607 -14400 # Node ID 5f676b61fb8be44e2b204946aa22adb1c6c8b777 # Parent 9cb8e730fa8602088cc0f75d82d689bdbd9d99c5 IMPL::Config::Resolve alpha version diff -r 9cb8e730fa86 -r 5f676b61fb8b Lib/IMPL/Config/Class.pm --- a/Lib/IMPL/Config/Class.pm Mon Apr 26 17:46:16 2010 +0400 +++ b/Lib/IMPL/Config/Class.pm Tue Apr 27 20:10:07 2010 +0400 @@ -20,6 +20,7 @@ die new IMPL::Exception("A Type parameter is required") unless $this->Type; + warn "IMPL::Config::Class is absolute, use IMPL::Config::Activator instead"; } sub _is_class { diff -r 9cb8e730fa86 -r 5f676b61fb8b Lib/IMPL/Config/Resolve.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/IMPL/Config/Resolve.pm Tue Apr 27 20:10:07 2010 +0400 @@ -0,0 +1,62 @@ +package IMPL::Config::Resolve; +use base qw(IMPL::Object IMPL::Object::Autofill IMPL::Object::Serializable); + +use IMPL::Class::Property; +use IMPL::Exception; + +BEGIN { + public property target => prop_all; + public property path => prop_all; + public property default => prop_all +} + +__PACKAGE__->PassThroughArgs; + +sub CTOR { + my ($this) = @_; + + die new IMPL::InvalidArgumentException("The argument is mandatory","target") unless $this->target; + die new IMPL::InvalidArgumentException("The argument is mandatory","path") unless $this->path; +} + +sub Invoke { + my ($this) = @_; + + my $path = $this->path; + + if (ref $path eq 'ARRAY') { + my $result = $this->target; + $result = $this->_InvokeMember($result,$_) || return $this->default foreach @$path; + return $result; + } elsif (not ref $path) { + my $result = $this->target; + $result = $this->_InvokeMember($result,$_) || return $this->default foreach map { name => $_},split /\./,$this->path; + return $result; + } else { + die new IMPL::InvalidOperationException("Unsopported path type",ref $path); + } +} + +sub _InvokeMember { + my ($self,$object,$member) = @_; + + local $@; + return eval { $object->($member->{method})(exists $member->{parameters} ? _as_list($member->{parameters}) : ()) }; +} + +sub _as_list { + ref $_[0] ? + (ref $_[0] eq 'HASH' ? + %{$_[0]} + : + (ref $_[0] eq 'ARRAY'? + @{$_[0]} + : + $_[0] + ) + ) + : + ($_[0]); +} + +1;