diff Lib/IMPL/Config/Activator.pm @ 293:15d87ef41764

*IMPL::Config::Activator: refactoring
author sergey
date Wed, 27 Feb 2013 17:37:28 +0400
parents c8fe3f84feba
children 8088779e539d
line wrap: on
line diff
--- a/Lib/IMPL/Config/Activator.pm	Tue Feb 26 02:21:03 2013 +0400
+++ b/Lib/IMPL/Config/Activator.pm	Wed Feb 27 17:37:28 2013 +0400
@@ -1,28 +1,37 @@
 package IMPL::Config::Activator;
 use strict;
 
-use parent qw(IMPL::Object IMPL::Object::Autofill IMPL::Object::PublicSerializable);
-use IMPL::Class::Property;
+use Scalar::Util qw(reftype);
+use IMPL::lang;
+use IMPL::Const qw(:prop);
+use IMPL::declare {
+	require => [
+	   Loader => 'IMPL::Code::Loader',
+	   Exception => 'IMPL::Exception'
+	],
+	base => [
+	   'IMPL::Object' => undef,
+	   'IMPL::Object::Autofill' => '@_',
+	   'IMPL::Object::PublicSerializable' => undef
+	],
+	props => [
+	   factory => PROP_RW,
+	   parameters => PROP_RW,
+	   object => PROP_RO
+	]
+};
 
-BEGIN {
-    public property factory => prop_all;
-    public property parameters => prop_all;
-    public property object => prop_get | owner_set;
-}
-
-__PACKAGE__->PassThroughArgs;
+use constant {
+	SELF_CLASS => __PACKAGE__
+};
 
 sub CTOR {
     my $this = shift;
 
-    die new IMPL::Exception("A factory parameter is required") unless $this->factory;
+    die Exception->new("A factory parameter is required") unless $this->factory;
     
 }
 
-sub _is_class {
-    no strict 'refs';
-    UNIVERSAL::can($_[0],'new') ? 1 : 0;
-}
 
 sub activate {
     my $this = shift;
@@ -31,20 +40,20 @@
         my @args;
         
         my $params = $this->parameters;
-        if (UNIVERSAL::isa($params,'HASH')) {
+        if (reftype($params) eq 'HASH') {
             while ( my ($key,$value) = each %$params ) {
-                push @args,$key, UNIVERSAL::isa($value,'IMPL::Config::Activator') ? $value->activate : $value;
+                push @args,$key, is($value,SELF_CLASS) ? $value->activate : $value;
             }
-        } elsif (UNIVERSAL::isa($params,'ARRAY')) {
-            push @args, map UNIVERSAL::isa($_,'IMPL::Config::Activator') ? $_->activate : $_, @$params;
+        } elsif (reftype($params) eq 'ARRAY') {
+            push @args, map is($_,SELF_CLASS) ? $_->activate : $_, @$params;
         } else {
-            push @args, UNIVERSAL::isa($params,'IMPL::Config::Activator') ? $params->activate : $params;
+            push @args, is($params,SELF_CLASS) ? $params->activate : $params;
         }
         
-        push @args,  map UNIVERSAL::isa($_,'IMPL::Config::Activator') ? $_->activate : $_, @_ if @_;
+        push @args,  map is($_,SELF_CLASS) ? $_->activate : $_, @_ if @_;
         
         my $factory = $this->factory;
-        eval "require $factory; 1;" unless (ref $factory or _is_class($factory));
+        Loader->Require($factory) unless ref $factory;
         
         return $this->object($factory->new(@args));
     } else {
@@ -53,3 +62,13 @@
 }
 
 1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+C<>
+
+=cut