annotate 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
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
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
4 use base qw(IMPL::Object IMPL::Object::Autofill);
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;
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
9 public property args => prop_all;
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
10 private property _object => prop_all;
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;
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
17
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
18 die new IMPL::Exception("A Type parameter is required") unless $this->Type;
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
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
27 sub instance {
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
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
30 my $factory = $this->fatory;
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
31
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
32 if (my $obj = $this->_object) {
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
33 return $obj;
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
34 } else {
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
35 my %args = (%{$this->args || {}},@_);
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
36 eval "require $factory" unless not ref $factory and _is_class($factory);
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
37 my $inst = $factory->new(%args);
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
38 $this->_object($inst);
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
39 return $inst;
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
40 }
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
41 }
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
42
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
43 1;