comparison Lib/IMPL/Serialization.pm @ 196:a705e848dcc7

added IMPL::Config::Reference
author cin
date Mon, 16 Apr 2012 17:42:54 +0400
parents 4d0e1962161c
children 2ffe6f661605
comparison
equal deleted inserted replaced
195:7a920771fd8e 196:a705e848dcc7
1 package IMPL::Serialization; 1 package IMPL::Serialization;
2 use strict; 2 use strict;
3
4 # 20060222
5 # пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ
6 # (пїЅ) Sourcer, cin.sourcer@gmail.com
7 # revision 3 (20090517)
8
9 3
10 package IMPL::Serialization::Context; 4 package IMPL::Serialization::Context;
11 use parent qw(IMPL::Object); 5 use parent qw(IMPL::Object);
12 6
13 use IMPL::Class::Property; 7 use IMPL::Class::Property;
14 use IMPL::Class::Property::Direct; 8 use IMPL::Class::Property::Direct;
15 use IMPL::Exception; 9 use IMPL::Exception;
16 use Scalar::Util qw(refaddr); 10 use Scalar::Util qw(refaddr);
17 11
18 BEGIN { 12 BEGIN {
19 private _direct property ObjectWriter => prop_all; # пїЅпїЅпїЅпїЅпїЅпїЅ, пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅ пїЅпїЅпїЅпїЅпїЅ 13 private _direct property ObjectWriter => prop_all;
20 private _direct property Context => prop_all; # пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ (пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ, пїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ) 14 private _direct property Context => prop_all;
21 private _direct property NextID => prop_all;# пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ 15 private _direct property NextID => prop_all;
22 16
23 # пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ, пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ, пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅ. пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ
24 # пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅ IMPL::Serialization::Context, пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ
25 public _direct property Serializer => prop_all; 17 public _direct property Serializer => prop_all;
26 18
27 private _direct property State => prop_all; # пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ 19 private _direct property State => prop_all;
28 } 20 }
29 21
30 # пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ, пїЅ.пїЅ. пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅпїЅ
31 sub STATE_CLOSED () { 0 } 22 sub STATE_CLOSED () { 0 }
32 # пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ, пїЅ.пїЅ. пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ, пїЅпїЅ пїЅ пїЅпїЅпїЅ пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅпїЅ
33 sub STATE_OPENED () { 1 } 23 sub STATE_OPENED () { 1 }
34 # пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅ пїЅ пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ
35 sub STATE_COMPLEX () { 2 } 24 sub STATE_COMPLEX () { 2 }
36 # пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅ пїЅ пїЅпїЅпїЅпїЅ пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ, пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ
37 sub STATE_DATA () { 3 } 25 sub STATE_DATA () { 3 }
38 26
39 sub CTOR { 27 sub CTOR {
40 my ($this,%args) = @_; 28 my ($this,%args) = @_;
41 29
42 $this->{$ObjectWriter} = $args{'ObjectWriter'}; 30 $this->{$ObjectWriter} = $args{'ObjectWriter'};
43 #$this->{$Context} = {};
44 $this->{$NextID} = 1; 31 $this->{$NextID} = 1;
45 $this->{$Serializer} = ($args{'Serializer'} ? $args{'Serializer'} : \&DefaultSerializer ); 32 $this->{$Serializer} = ($args{'Serializer'} ? $args{'Serializer'} : \&DefaultSerializer );
46 $this->{$State} = STATE_CLOSED; 33 $this->{$State} = STATE_CLOSED;
47 34
48 return 1; 35 return 1;
52 my ($this,$sName,$Var) = @_; 39 my ($this,$sName,$Var) = @_;
53 40
54 die new Exception ('Invalid operation') if $this->{$State} == STATE_DATA; 41 die new Exception ('Invalid operation') if $this->{$State} == STATE_DATA;
55 42
56 if (not ref $Var) { 43 if (not ref $Var) {
57 # пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅ, пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ, пїЅпїЅ пїЅпїЅпїЅ пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅ, пїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ, пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅ
58 # пїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ, пїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ, пїЅпїЅ пїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅпїЅ
59 my $prevState = $this->{$State}; 44 my $prevState = $this->{$State};
60 45
61 $this->{$ObjectWriter}->BeginObject(name => $sName);#, type => 'SCALAR'); 46 $this->{$ObjectWriter}->BeginObject(name => $sName);
62 $this->{$State} = STATE_OPENED; 47 $this->{$State} = STATE_OPENED;
63 48
64 $this->{$Serializer}->($this,\$Var); 49 $this->{$Serializer}->($this,\$Var);
65 50
66 $this->{$ObjectWriter}->EndObject(); 51 $this->{$ObjectWriter}->EndObject();
146 use IMPL::Class::Property; 131 use IMPL::Class::Property;
147 use IMPL::Class::Property::Direct; 132 use IMPL::Class::Property::Direct;
148 use IMPL::Exception; 133 use IMPL::Exception;
149 134
150 BEGIN { 135 BEGIN {
151 # пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ, пїЅпїЅпїЅ, пїЅпїЅпїЅпїЅ - пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ, пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ - пїЅпїЅпїЅпїЅпїЅпїЅ.
152 private _direct property Context => prop_all; 136 private _direct property Context => prop_all;
153 137
154 # пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ. пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ 138 # структура информации об объекте
155 # { 139 # {
156 # Type => 'typename', 140 # Type => 'typename',
157 # Name => 'object_name', 141 # Name => 'object_name',
158 # Data => $Data, 142 # Data => $Data,
159 # Id => 'object_id' 143 # Id => 'object_id'
160 # } 144 # }
161 private _direct property CurrentObject => prop_all; 145 private _direct property CurrentObject => prop_all;
162 146
163 # пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ. пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ.
164 private _direct property ObjectsPath => prop_all; 147 private _direct property ObjectsPath => prop_all;
165 148
166 # пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ
167 public _direct property Root => prop_get; 149 public _direct property Root => prop_get;
168 150
169 # пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ 151 # пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ пїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅ пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ
170 # ObjectFactory($Type,$DeserializationData,$refSurogate) 152 # ObjectFactory($Type,$DeserializationData,$refSurogate)
171 # $Type - пїЅпїЅпїЅ пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ 153 # $Type - пїЅпїЅпїЅ пїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ