changeset 92:5f676b61fb8b

IMPL::Config::Resolve alpha version
author wizard
date Tue, 27 Apr 2010 20:10:07 +0400
parents 9cb8e730fa86
children 0667064553ef
files Lib/IMPL/Config/Class.pm Lib/IMPL/Config/Resolve.pm
diffstat 2 files changed, 63 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 {
--- /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;