annotate Lib/IMPL/Config/Reference.pm @ 196:a705e848dcc7

added IMPL::Config::Reference
author cin
date Mon, 16 Apr 2012 17:42:54 +0400
parents
children 2ffe6f661605
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
196
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
1 package IMPL::Config::Reference;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
2 use strict;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
3
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
4 use IMPL::Exception;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
5
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
6 __PACKAGE__->PassThroughArgs;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
7
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
8 sub restore {
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
9 my ($self,$data,$surrogate) = @_;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
10
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
11 my @path;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
12
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
13 my ($tagTarget,$target) = splice @$data, 0, 2;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
14
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
15 die new IMPL::Exception('A traget tag must be the first tag in the reference specification') unless $tagTarget eq 'target';
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
16
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
17 while(my ($method,$args) = splice @$data, 0, 2 ) {
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
18 $target = $self->_Invoke({ method => $method, args => $args});
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
19 }
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
20 return $target;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
21 }
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
22
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
23 sub _InvokeMember {
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
24 my ($self,$object,$member) = @_;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
25
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
26 my $method = $member->{method};
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
27
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
28 local $@;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
29 return eval {
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
30 ref $object eq 'HASH' ?
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
31 $object->{$method}
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
32 :
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
33 $object->$method(
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
34 exists $member->{args} ?
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
35 _as_list($member->{args})
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
36 :
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
37 ()
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
38 )
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
39 };
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
40 }
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
41
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
42 sub _as_list {
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
43 ref $_[0] ?
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
44 (ref $_[0] eq 'HASH' ?
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
45 %{$_[0]}
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
46 :
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
47 (ref $_[0] eq 'ARRAY'?
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
48 @{$_[0]}
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
49 :
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
50 $_[0]
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
51 )
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
52 )
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
53 :
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
54 ($_[0]);
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
55 }
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
56
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
57 1;
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
58
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
59 __END__
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
60
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
61 =pod
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
62
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
63 =head1 NAME
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
64
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
65 C<IMPL::Config::Reference> - ссылка на внешний объект, вычисляемый на этапе десериализации данных.
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
66
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
67 =head1 SYNOPSIS
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
68
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
69 =begin code xml
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
70
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
71 <Application>
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
72 <processingStack type="IMPL::Config::Reference">
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
73 <target>IMPL::Config</target>
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
74 <LoadXMLFile>stdprocessing.xml</LoadXMLFile>
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
75 </processingStack>
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
76 </Application>
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
77
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
78 =end code xml
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
79
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
80 =head1 DESCRIPTION
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
81
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
82 Позволяет на указвать ссылки на вычисляемые объекты, например, загружаемые из файлов. Ссылки такого рода
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
83 будут вычислены на этапе десериализации еще до того, как будет создан объект верхнего уровня, поэтому
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
84 следует избегать таких ссылок на сам (его свойства и методы) десериализуемый объект.
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
85
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
86 =head1 MEMBERS
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
87
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
88 =head2 C<restore($class,$data,$surrogate)>
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
89
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
90 Использует данные переданные в параметре дата C<$data> для вычисления свойства. Данный метод - стандартный
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
91 метод для десериализации объекта, а параметр C<$data> содержит пары значений C<(имя_узла,значение_узла)>,
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
92 первая пара обязательно является узлом C<target>, а его значение - целевой объект, который будет
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
93 использован для вычисления конечного значения.
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
94
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
95 =back
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
96
a705e848dcc7 added IMPL::Config::Reference
cin
parents:
diff changeset
97 =cut