comparison 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
comparison
equal deleted inserted replaced
58:a35b60b16a99 59:0f3e369553bd
1 package IMPL::Config::Activator;
2 use strict;
3
4 use base qw(IMPL::Object IMPL::Object::Autofill);
5 use IMPL::Class::Property;
6
7 BEGIN {
8 public property factory => prop_all;
9 public property args => prop_all;
10 private property _object => prop_all;
11 }
12
13 __PACKAGE__->PassThroughArgs;
14
15 sub CTOR {
16 my $this = shift;
17
18 die new IMPL::Exception("A Type parameter is required") unless $this->Type;
19
20 }
21
22 sub _is_class {
23 no strict 'refs';
24 scalar keys %{"$_[0]::"} ? 1 : 0;
25 }
26
27 sub instance {
28 my $this = shift;
29
30 my $factory = $this->fatory;
31
32 if (my $obj = $this->_object) {
33 return $obj;
34 } else {
35 my %args = (%{$this->args || {}},@_);
36 eval "require $factory" unless not ref $factory and _is_class($factory);
37 my $inst = $factory->new(%args);
38 $this->_object($inst);
39 return $inst;
40 }
41 }
42
43 1;