annotate Lib/IMPL/Config/Activator.pm @ 70:2dfb0b0ad12f

More docs
author wizard
date Wed, 24 Mar 2010 17:42:04 +0300
parents 8d0ae27d15c1
children 3d1f584aea60
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
59
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
1 package IMPL::Config::Activator;
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
2 use strict;
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
3
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
4 use base qw(IMPL::Object IMPL::Object::Autofill IMPL::Object::PublicSerializable);
59
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
5 use IMPL::Class::Property;
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
6
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
7 BEGIN {
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
8 public property factory => prop_all;
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
9 public property parameters => prop_all;
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
10 public property object => prop_get | owner_set;
59
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
11 }
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
12
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
13 __PACKAGE__->PassThroughArgs;
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
14
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
15 sub CTOR {
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
16 my $this = shift;
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
17
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
18 die new IMPL::Exception("A Type parameter is required") unless $this->factory;
59
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
19
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
20 }
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
21
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
22 sub _is_class {
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
23 no strict 'refs';
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
24 scalar keys %{"$_[0]::"} ? 1 : 0;
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
25 }
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
26
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
27 sub activate {
59
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
28 my $this = shift;
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
29
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
30 unless ($this->object) {
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
31 my @args;
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
32
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
33 my $params = $this->parameters;
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
34 if (UNIVERSAL::isa($params,'HASH')) {
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
35 while ( my ($key,$value) = each %$params ) {
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
36 push @args,$key, UNIVERSAL::isa($value,'IMPL::Config::Activator') ? $value->activate : $value;
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
37 }
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
38 } elsif (UNIVERSAL::isa($params,'ARRAY')) {
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
39 push @args, map UNIVERSAL::isa($_,'IMPL::Config::Activator') ? $_->activate : $_, @$params;
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
40 } else {
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
41 push @args, UNIVERSAL::isa($params,'IMPL::Config::Activator') ? $params->activate : $params;
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
42 }
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
43
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
44 push @args, map UNIVERSAL::isa($_,'IMPL::Config::Activator') ? $_->activate : $_, @_ if @_;
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
45
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
46 my $factory = $this->factory;
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
47 eval "require $factory; 1;" unless not ref $factory and _is_class($factory);
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
48
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
49 return $this->object($factory->new(@args));
59
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
50 } else {
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
51 return $this->object;
59
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
52 }
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
53 }
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
54
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
55 1;