annotate lib/IMPL/Config/Reference.pm @ 419:bbc4739c4d48 ref20150831

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