diff Lib/IMPL/Config/Activator.pm @ 59:0f3e369553bd

Rewritten property implementation (probably become slower but more flexible) Configuration infrastructure in progress (in the aspect of the lazy activation) Initial concept for the code generator
author wizard
date Tue, 09 Mar 2010 02:50:45 +0300
parents
children b0c068da93ac
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/IMPL/Config/Activator.pm	Tue Mar 09 02:50:45 2010 +0300
@@ -0,0 +1,43 @@
+package IMPL::Config::Activator;
+use strict;
+
+use base qw(IMPL::Object IMPL::Object::Autofill);
+use IMPL::Class::Property;
+
+BEGIN {
+	public property factory => prop_all;
+	public property args => prop_all;
+	private property _object => prop_all;
+}
+
+__PACKAGE__->PassThroughArgs;
+
+sub CTOR {
+    my $this = shift;
+    
+    die new IMPL::Exception("A Type parameter is required") unless $this->Type;
+    
+}
+
+sub _is_class {
+    no strict 'refs';
+    scalar keys %{"$_[0]::"} ? 1 : 0;
+}
+
+sub instance {
+    my $this = shift;
+    
+    my $factory = $this->fatory;
+    
+    if (my $obj = $this->_object) {
+        return $obj;
+    } else {
+        my %args = (%{$this->args || {}},@_);
+        eval "require $factory" unless not ref $factory and _is_class($factory);
+        my $inst = $factory->new(%args);
+        $this->_object($inst);
+        return $inst;
+    }
+}
+
+1;
\ No newline at end of file