annotate Lib/IMPL/Config/Activator.pm @ 104:196bf443b5e1

DOM::Schema RC0 inflators support, validation and some other things, Minor and major fixes almost for everything. A 'Source' property of the ValidationErrors generated from a NodeSet or a NodeList is subject to change in the future.
author wizard
date Tue, 11 May 2010 02:42:59 +0400
parents 0667064553ef
children 76515373dac0
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';
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')) {
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;
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 {
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;