annotate Lib/IMPL/Config/Activator.pm @ 238:b8c724f6de36

DOM model refactoring TT view refactoring, controls are no longer derived from DOM nodes bugfixes
author sergey
date Tue, 16 Oct 2012 01:33:06 +0400
parents c8fe3f84feba
children 15d87ef41764
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
165
76515373dac0 Added Class::Template,
wizard
parents: 93
diff changeset
4 use parent 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 {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
8 public property factory => prop_all;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
9 public property parameters => prop_all;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
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
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 194
diff changeset
18 die new IMPL::Exception("A factory 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';
93
0667064553ef fixed _is_class in activator
wizard
parents: 89
diff changeset
24 UNIVERSAL::can($_[0],'new') ? 1 : 0;
59
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')) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
35 while ( my ($key,$value) = each %$params ) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
36 push @args,$key, UNIVERSAL::isa($value,'IMPL::Config::Activator') ? $value->activate : $value;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
37 }
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
38 } elsif (UNIVERSAL::isa($params,'ARRAY')) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
39 push @args, map UNIVERSAL::isa($_,'IMPL::Config::Activator') ? $_->activate : $_, @$params;
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 59
diff changeset
40 } else {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
41 push @args, UNIVERSAL::isa($params,'IMPL::Config::Activator') ? $params->activate : $params;
60
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;
93
0667064553ef fixed _is_class in activator
wizard
parents: 89
diff changeset
47 eval "require $factory; 1;" unless (ref $factory or _is_class($factory));
60
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 {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
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
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 165
diff changeset
55 1;