annotate Lib/IMPL/Serialization.pm @ 244:a02b110da931

refactoring fixed binding to CGI query parameters with multiple values
author sergey
date Mon, 22 Oct 2012 04:09:27 +0400
parents c477f24f1980
children 4ddb27ff4a0b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
1 package IMPL::Serialization;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
2 use strict;
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
3
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
4 package IMPL::Serialization::Context;
166
4267a2ac3d46 Added Class::Template,
wizard
parents: 140
diff changeset
5 use parent qw(IMPL::Object);
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
6
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
7 use IMPL::Class::Property;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
8 use IMPL::Class::Property::Direct;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
9 use IMPL::Exception;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
10 use Scalar::Util qw(refaddr);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
11
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
12 BEGIN {
196
a705e848dcc7 added IMPL::Config::Reference
cin
parents: 194
diff changeset
13 private _direct property ObjectWriter => prop_all;
a705e848dcc7 added IMPL::Config::Reference
cin
parents: 194
diff changeset
14 private _direct property Context => prop_all;
a705e848dcc7 added IMPL::Config::Reference
cin
parents: 194
diff changeset
15 private _direct property NextID => prop_all;
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
16
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
17 public _direct property Serializer => prop_all;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
18
196
a705e848dcc7 added IMPL::Config::Reference
cin
parents: 194
diff changeset
19 private _direct property State => prop_all;
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
20 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
21
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
22 sub STATE_CLOSED () { 0 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
23 sub STATE_OPENED () { 1 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
24 sub STATE_COMPLEX () { 2 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
25 sub STATE_DATA () { 3 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
26
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
27 sub CTOR {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
28 my ($this,%args) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
29
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
30 $this->{$ObjectWriter} = $args{'ObjectWriter'};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
31 $this->{$NextID} = 1;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
32 $this->{$Serializer} = ($args{'Serializer'} ? $args{'Serializer'} : \&DefaultSerializer );
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
33 $this->{$State} = STATE_CLOSED;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
34
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
35 return 1;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
36 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
37
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
38 sub AddVar {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
39 my ($this,$sName,$Var) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
40
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
41 die new Exception ('Invalid operation') if $this->{$State} == STATE_DATA;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
42
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
43 if (not ref $Var) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
44 my $prevState = $this->{$State};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
45
196
a705e848dcc7 added IMPL::Config::Reference
cin
parents: 194
diff changeset
46 $this->{$ObjectWriter}->BeginObject(name => $sName);
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
47 $this->{$State} = STATE_OPENED;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
48
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
49 $this->{$Serializer}->($this,\$Var);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
50
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
51 $this->{$ObjectWriter}->EndObject();
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
52
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
53 if ($prevState == STATE_OPENED) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
54 $this->{$State} = STATE_COMPLEX;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
55 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
56 $this->{$State} = $prevState;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
57 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
58 return 0;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
59 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
60
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
61 my $PrevState = $this->{$State};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
62
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
63 my $ObjID = $this->{$Context}->{refaddr $Var};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
64 if ($ObjID) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
65 $this->{$ObjectWriter}->BeginObject(name => $sName, refid => $ObjID);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
66 $this->{$ObjectWriter}->EndObject();
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
67 return $ObjID;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
68 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
69
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
70 $ObjID = $this->{$NextID};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
71 $this->{$NextID} = $ObjID + 1;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
72
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
73 $this->{$Context}->{refaddr $Var} = $ObjID;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
74
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
75 $this->{$ObjectWriter}->BeginObject(name => $sName, type => ref($Var), id => $ObjID);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
76
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
77 $this->{$State} = STATE_OPENED;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
78 $this->{$Serializer}->($this,$Var);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
79
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
80 $this->{$ObjectWriter}->EndObject();
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
81
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
82 if ($PrevState == STATE_OPENED) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
83 $this->{$State} = STATE_COMPLEX;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
84 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
85 $this->{$State} = $PrevState;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
86 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
87
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
88 return $ObjID;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
89 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
90
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
91 sub SetData {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
92 my ($this,$Data,$Type) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
93
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
94 die new Exception ('The object should be a scalar value') if ref $Data;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
95 die new Exception ('Invalid operation') if $this->{$State} != STATE_OPENED;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
96
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
97 $this->{$ObjectWriter}->SetData($Data,$Type);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
98
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
99 $this->{$State} = STATE_DATA;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
100
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
101 return 1;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
102 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
103
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
104 sub DefaultSerializer {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
105 my ($Context, $refObj) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
106
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
107 if (ref($refObj) eq 'SCALAR') {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
108 $Context->SetData($$refObj, 'SCALAR');
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
109 } elsif (ref($refObj) eq 'ARRAY') {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
110 $Context->AddVar('item',$_) foreach @$refObj;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
111 } elsif (ref($refObj) eq 'HASH') {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
112 while (my ($key,$value) = each %$refObj) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
113 $Context->AddVar($key,$value);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
114 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
115 } elsif (ref($refObj) eq 'REF') {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
116 $Context->AddVar('ref',$$refObj);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
117 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
118 if (ref $refObj and $refObj->UNIVARSAL::can('save')) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
119 $refObj->save($Context);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
120 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
121 die new Exception('Cant serialize the object of the type: '.ref($refObj));
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
122 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
123 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
124
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
125 return 1;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
126 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
127
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
128 package IMPL::Deserialization::Context;
166
4267a2ac3d46 Added Class::Template,
wizard
parents: 140
diff changeset
129 use parent qw(IMPL::Object);
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
130
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
131 use IMPL::Class::Property;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
132 use IMPL::Class::Property::Direct;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
133 use IMPL::Exception;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
134
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
135 BEGIN {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
136 private _direct property Context => prop_all;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
137
196
a705e848dcc7 added IMPL::Config::Reference
cin
parents: 194
diff changeset
138 # структура информации об объекте
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
139 # {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
140 # Type => 'typename',
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
141 # Name => 'object_name',
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
142 # Data => $Data,
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
143 # Id => 'object_id'
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
144 # }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
145 private _direct property CurrentObject => prop_all;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
146
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
147 private _direct property ObjectsPath => prop_all;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
148
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
149 public _direct property Root => prop_get;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
150
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
151 # пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
152 # ObjectFactory($Type,$DeserializationData,$refSurogate)
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
153 # $Type - пїЅпїЅпїЅ пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
154 # $DeserializationData - пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ,
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
155 # пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ.
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
156 # $refSurogate - пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ, пїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ.
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
157 # пїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ undef
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
158 private _direct property ObjectFactory => prop_all;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
159
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
160 # пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ.
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
161 # SurogateHelper($Type)
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
162 # $Type пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ, пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ.
115
5edc2ac5231c minor fix to the serialization mechanism
wizard
parents: 60
diff changeset
163 private _direct property SurrogateHelper => prop_all;
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
164 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
165
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
166 sub CTOR {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
167 my ($this,%args) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
168 $this->{$CurrentObject} = undef;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
169 $this->{$Root} = undef;
115
5edc2ac5231c minor fix to the serialization mechanism
wizard
parents: 60
diff changeset
170 $this->{$ObjectFactory} = $args{ObjectFactory} if $args{ObjectFactory};
5edc2ac5231c minor fix to the serialization mechanism
wizard
parents: 60
diff changeset
171 $this->{$SurrogateHelper} = $args{SurrogateHelper} if $args{SurrogateHelper};
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
172 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
173
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
174 sub OnObjectBegin {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
175 my ($this,$name,$rhProps) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
176
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
177 die new Exception("Invalid data from an ObjectReader","An object reader should pass a referense to a hash which contains attributes of an object") if (ref $rhProps ne 'HASH');
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
178 die new Exception("Trying to create second root object") if not $this->{$CurrentObject} and $this->{$Root};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
179
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
180 if ($rhProps->{'refid'}) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
181 my $refObj = $this->{$Context}->{$rhProps->{'refid'}};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
182 die new Exception("A reference to a not existing object found") if not $refObj;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
183 my $rhCurrentObj = $this->{$CurrentObject};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
184
219
sergey
parents: 207
diff changeset
185 die new Exception("The root object can't be a reference") if not $rhCurrentObj;
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
186
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
187 if ($rhCurrentObj->{'Data'}) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
188 die new Exception("Invalid serializaed data","Plain deserialization data for an object already exist") if not ref $rhCurrentObj->{'Data'};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
189 push @{$rhCurrentObj->{'Data'}}, $name,$refObj;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
190 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
191 $rhCurrentObj->{'Data'} = [$name,$refObj];
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
192 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
193
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
194 # пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ, пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ OnObjectEnd пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ, пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ. пїЅ.пїЅ. пїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅ
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
195 push @{$this->{$ObjectsPath}},$rhCurrentObj;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
196 $this->{$CurrentObject} = undef;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
197
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
198 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
199 push @{$this->{$ObjectsPath}},$this->{$CurrentObject} if $this->{$CurrentObject};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
200
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
201 $this->{$CurrentObject} = {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
202 Name => $name,
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
203 Type => $rhProps->{'type'} || 'SCALAR',
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
204 Id => $rhProps->{'id'},
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
205 refId => $rhProps->{'refid'}
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
206 };
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 49
diff changeset
207
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
208 if (defined $rhProps->{'id'}) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
209 die new IMPL::Exception("Trying to create a simple object instead of a reference, type is missing.",$name,$rhProps->{id}) unless $rhProps->{'type'} ;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
210 $this->{$Context}->{$rhProps->{'id'}} = $this->{$SurrogateHelper} ? $this->{$SurrogateHelper}->($rhProps->{'type'}) : DefaultSurrogateHelper($rhProps->{'type'});
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
211 }
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
212 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
213
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
214 return 1;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
215 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
216
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
217 sub OnObjectData {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
218 my ($this,$data) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
219
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
220 my $rhObject = $this->{$CurrentObject};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
221
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
222 die new Exception("Trying to set data for an object which not exists") if not $rhObject;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
223
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
224 die new Exception("Deserialization data already exists for a current object", "ObjectName= $rhObject->{'Name'}") if $rhObject->{'Data'};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
225
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
226 $rhObject->{'Data'} = $data;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
227
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
228 return 1;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
229 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
230 {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
231 my $AutoId = 0;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
232 sub OnObjectEnd {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
233 my ($this,$name) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
234
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
235 my $rhObject = $this->{$CurrentObject};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
236 my $rhPrevObject = pop @{$this->{$ObjectsPath}};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
237
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
238 # пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ, пїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ - пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ, пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ - пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
239 # пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
240 if ((not defined($rhObject)) && $rhPrevObject) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
241 $this->{$CurrentObject} = $rhPrevObject;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
242 return 1;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
243 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
244
202
5146e17a7b76 IMPL::Web::Application::RestResource fixes, documentation
sergey
parents: 199
diff changeset
245 my $refObj = $this->{$ObjectFactory} ?$this->{$ObjectFactory}->($rhObject->{'Type'},$rhObject->{'Data'},$rhObject->{'Id'} ? $this->{$Context}->{$rhObject->{'Id'}} : undef) : DefaultFactory($rhObject->{'Type'},$rhObject->{'Data'},$rhObject->{'Id'} ? $this->{$Context}->{$rhObject->{'Id'}} : undef);
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
246
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
247 die new Exception("Trying to close a non existing oject") if not $rhObject;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
248
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
249 my $Data;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
250
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
251 if ($rhObject->{'Id'}) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
252 $this->{$Context}->{$rhObject->{'Id'}} = $refObj;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
253 $Data = $refObj;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
254 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
255 if (ref $refObj ne 'SCALAR') {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
256 $rhObject->{Id} = "auto$AutoId";
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
257 $AutoId ++;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
258 $this->{$Context}->{$rhObject->{'Id'}} = $refObj;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
259 $Data = $refObj;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
260 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
261 $Data = ${$refObj};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
262 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
263 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
264
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
265 if (not $rhPrevObject) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
266 $this->{$Root} = $Data;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
267 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
268 if ($rhPrevObject->{'Data'}) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
269 die new Exception("Trying append a reference to an object to the plain data") if not ref $rhPrevObject->{'Data'};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
270 push @{$rhPrevObject->{'Data'}},$rhObject->{'Name'},$Data;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
271 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
272 $rhPrevObject->{'Data'} = [$rhObject->{'Name'},$Data];
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
273 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
274 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
275
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
276 $this->{$CurrentObject} = $rhPrevObject;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
277
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
278 return 1;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
279 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
280 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
281
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 196
diff changeset
282 {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 196
diff changeset
283 my %classes;
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 196
diff changeset
284 sub _load_class {
199
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents: 198
diff changeset
285 return if $classes{$_[0]};
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents: 198
diff changeset
286
207
f534a60d5b01 minor changes
sergey
parents: 202
diff changeset
287 die new IMPL::Exception("Invalid class name",$_[0]) unless $_[0] =~ m/^(\w+(?:\:\:\w+)*)$/;
199
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents: 198
diff changeset
288
207
f534a60d5b01 minor changes
sergey
parents: 202
diff changeset
289 eval "require $1";
199
e743a8481327 Added REST support for forms (with only get and post methods)
sergey
parents: 198
diff changeset
290 $classes{$_[0]} = 1;
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 196
diff changeset
291 }
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 196
diff changeset
292 }
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 196
diff changeset
293
115
5edc2ac5231c minor fix to the serialization mechanism
wizard
parents: 60
diff changeset
294 sub DefaultSurrogateHelper {
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
295 my ($Type) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
296
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
297 if ($Type eq 'SCALAR' or $Type eq 'REF') {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
298 my $var;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
299 return \$var;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
300 } elsif ($Type eq 'ARRAY') {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
301 return [];
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
302 } elsif ($Type eq 'HASH') {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
303 return {};
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 49
diff changeset
304 } elsif ($Type) {
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 196
diff changeset
305 _load_class($Type);
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 49
diff changeset
306 if (UNIVERSAL::can($Type,'surrogate')) {
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
307 return $Type->surrogate();
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
308 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
309 return bless {}, $Type;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
310 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
311 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
312 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
313
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
314 # deserialization context:
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
315 # [
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
316 # 'var_name',value,
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
317 # ....
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
318 # ]
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
319
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
320 sub DefaultFactory {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
321 my ($Type,$Data,$refSurogate) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
322
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
323 if ($Type eq 'SCALAR') {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
324 die new Exception("SCALAR needs a plain data for a deserialization") if ref $Data;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
325 if ($refSurogate) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
326 $$refSurogate = $Data;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
327 return $refSurogate;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
328 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
329 return \$Data;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
330 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
331 } elsif ($Type eq 'ARRAY') {
202
5146e17a7b76 IMPL::Web::Application::RestResource fixes, documentation
sergey
parents: 199
diff changeset
332 $Data ||= [];
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
333 die new Exception("Invalid a deserialization context when deserializing ARRAY") if not ref $Data and defined $Data;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
334 if (not ref $refSurogate) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
335 my @Array;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
336 $refSurogate = \@Array;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
337 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
338 for (my $i = 0; $i < scalar(@{$Data})/2; $i++) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
339 push @$refSurogate,$Data->[$i*2+1];
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
340 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
341 return $refSurogate;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
342 } elsif ($Type eq 'HASH') {
202
5146e17a7b76 IMPL::Web::Application::RestResource fixes, documentation
sergey
parents: 199
diff changeset
343 $Data ||= [];
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
344 die new Exception("Invalid a deserialization context when deserializing HASH") if not ref $Data and defined $Data;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
345 if (not ref $refSurogate) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
346 $refSurogate = {};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
347 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
348 for (my $i = 0; $i< @$Data; $i+= 2) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
349 $refSurogate->{$Data->[$i]} = $Data->[$i+1];
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
350 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
351 return $refSurogate;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
352 } elsif ($Type eq 'REF') {
202
5146e17a7b76 IMPL::Web::Application::RestResource fixes, documentation
sergey
parents: 199
diff changeset
353 $Data ||= [];
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
354 die new Exception("Invalid a deserialization context when deserializing REF") if not ref $Data and defined $Data;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
355 if (not ref $refSurogate) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
356 my $ref = $Data->[1];
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
357 return \$ref;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
358 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
359 $$refSurogate = $Data->[1];
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
360 return $refSurogate;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
361 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
362 } else {
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 196
diff changeset
363 _load_class($Type);
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
364 if ( $Type->UNIVERSAL::can('restore') ) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
365 return $Type->restore($Data,$refSurogate);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
366 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
367 die new Exception("Don't know how to deserialize $Type");
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
368 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
369 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
370 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
371
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
372 package IMPL::Serializer;
166
4267a2ac3d46 Added Class::Template,
wizard
parents: 140
diff changeset
373 use parent qw(IMPL::Object);
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
374
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
375 use IMPL::Class::Property;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
376 use IMPL::Class::Property::Direct;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
377 use IMPL::Exception;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
378
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
379 BEGIN {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
380 private _direct property Formatter => prop_all;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
381 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
382
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
383 sub CTOR {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
384 my ($this,%args) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
385 $this->Formatter($args{'Formatter'}) or die new Exception("Omitted mandatory parameter 'Formatter'");
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
386 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
387
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
388 sub Serialize {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
389 my $this = shift;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
390 my ($hStream,$Object) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
391 my $ObjWriter = $this->Formatter()->CreateWriter($hStream);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
392 my $Context = new IMPL::Serialization::Context(ObjectWriter => $ObjWriter);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
393 $Context->AddVar('root',$Object);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
394 return 1;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
395 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
396
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
397 sub Deserialize {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
398 my $this = shift;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
399 my ($hStream) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
400 my $Context = new IMPL::Deserialization::Context();
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
401 my $ObjReader = $this->Formatter()->CreateReader($hStream,$Context);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
402 $ObjReader->Parse();
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
403 return $Context->Root();
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
404 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
405
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
406 1;