annotate 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
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
293
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
4 use Scalar::Util qw(reftype);
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
5 use IMPL::lang;
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
6 use IMPL::Const qw(:prop);
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
7 use IMPL::declare {
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
8 require => [
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
9 Loader => 'IMPL::Code::Loader',
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
10 Exception => 'IMPL::Exception'
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
11 ],
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
12 base => [
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
13 'IMPL::Object' => undef,
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
14 'IMPL::Object::Autofill' => '@_',
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
15 'IMPL::Object::PublicSerializable' => undef
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
16 ],
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
17 props => [
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
18 factory => PROP_RW,
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
19 parameters => PROP_RW,
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
20 object => PROP_RO
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
21 ]
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
22 };
59
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
23
293
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
24 use constant {
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
25 SELF_CLASS => __PACKAGE__
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
26 };
59
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
27
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
28 sub CTOR {
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
29 my $this = shift;
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
30
293
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
31 die Exception->new("A factory parameter is required") unless $this->factory;
59
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
32
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
33 }
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
34
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
35
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
36 sub activate {
59
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
37 my $this = shift;
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
38
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
39 unless ($this->object) {
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
40 my @args;
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
41
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
42 my $params = $this->parameters;
293
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
43 if (reftype($params) eq 'HASH') {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
44 while ( my ($key,$value) = each %$params ) {
293
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
45 push @args,$key, is($value,SELF_CLASS) ? $value->activate : $value;
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
46 }
293
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
47 } elsif (reftype($params) eq 'ARRAY') {
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
48 push @args, map is($_,SELF_CLASS) ? $_->activate : $_, @$params;
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
49 } else {
293
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
50 push @args, is($params,SELF_CLASS) ? $params->activate : $params;
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
51 }
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
52
293
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
53 push @args, map is($_,SELF_CLASS) ? $_->activate : $_, @_ if @_;
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
54
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
55 my $factory = $this->factory;
293
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
56 Loader->Require($factory) unless ref $factory;
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
57
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
58 return $this->object($factory->new(@args));
59
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
59 } else {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
60 return $this->object;
59
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
61 }
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
62 }
0f3e369553bd Rewritten property implementation (probably become slower but more flexible)
wizard
parents:
diff changeset
63
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
64 1;
293
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
65
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
66 __END__
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
67
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
68 =pod
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
69
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
70 =head1 NAME
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
71
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
72 C<>
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
73
15d87ef41764 *IMPL::Config::Activator: refactoring
sergey
parents: 206
diff changeset
74 =cut