Mercurial > pub > Impl
comparison Lib/IMPL/Serialization.pm @ 198:2ffe6f661605
Implemented IMPL::Web::Handler::RestController
fixes in IMPL::Serialization
completed IMPL::Web::Application::RestResource
added IMPL::Web::Handler::JSONView
added IMPL::Web::RestContract
author | cin |
---|---|
date | Fri, 20 Apr 2012 16:06:36 +0400 |
parents | a705e848dcc7 |
children | e743a8481327 |
comparison
equal
deleted
inserted
replaced
197:6b1dda998839 | 198:2ffe6f661605 |
---|---|
240 if ((not defined($rhObject)) && $rhPrevObject) { | 240 if ((not defined($rhObject)) && $rhPrevObject) { |
241 $this->{$CurrentObject} = $rhPrevObject; | 241 $this->{$CurrentObject} = $rhPrevObject; |
242 return 1; | 242 return 1; |
243 } | 243 } |
244 | 244 |
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); | 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); |
246 | 246 |
247 die new Exception("Trying to close a non existing oject") if not $rhObject; | 247 die new Exception("Trying to close a non existing oject") if not $rhObject; |
248 | 248 |
249 my $Data; | 249 my $Data; |
250 | 250 |
282 sub _is_class { | 282 sub _is_class { |
283 no strict 'refs'; | 283 no strict 'refs'; |
284 scalar keys %{"$_[0]::"} ? 1 : 0; | 284 scalar keys %{"$_[0]::"} ? 1 : 0; |
285 } | 285 } |
286 | 286 |
287 { | |
288 my %classes; | |
289 sub _load_class { | |
290 my $class = shift; | |
291 $classes{$class} = 1; | |
292 eval "require $class"; | |
293 } | |
294 } | |
295 | |
287 sub DefaultSurrogateHelper { | 296 sub DefaultSurrogateHelper { |
288 my ($Type) = @_; | 297 my ($Type) = @_; |
289 | 298 |
290 if ($Type eq 'SCALAR' or $Type eq 'REF') { | 299 if ($Type eq 'SCALAR' or $Type eq 'REF') { |
291 my $var; | 300 my $var; |
293 } elsif ($Type eq 'ARRAY') { | 302 } elsif ($Type eq 'ARRAY') { |
294 return []; | 303 return []; |
295 } elsif ($Type eq 'HASH') { | 304 } elsif ($Type eq 'HASH') { |
296 return {}; | 305 return {}; |
297 } elsif ($Type) { | 306 } elsif ($Type) { |
298 eval "require $Type" unless _is_class($Type); | 307 _load_class($Type); |
299 if (UNIVERSAL::can($Type,'surrogate')) { | 308 if (UNIVERSAL::can($Type,'surrogate')) { |
300 return $Type->surrogate(); | 309 return $Type->surrogate(); |
301 } else { | 310 } else { |
302 return bless {}, $Type; | 311 return bless {}, $Type; |
303 } | 312 } |
348 } else { | 357 } else { |
349 $$refSurogate = $Data->[1]; | 358 $$refSurogate = $Data->[1]; |
350 return $refSurogate; | 359 return $refSurogate; |
351 } | 360 } |
352 } else { | 361 } else { |
353 eval "require $Type; 1;" or warn $@ unless _is_class($Type); | 362 _load_class($Type); |
354 if ( $Type->UNIVERSAL::can('restore') ) { | 363 if ( $Type->UNIVERSAL::can('restore') ) { |
355 return $Type->restore($Data,$refSurogate); | 364 return $Type->restore($Data,$refSurogate); |
356 } else { | 365 } else { |
357 die new Exception("Don't know how to deserialize $Type"); | 366 die new Exception("Don't know how to deserialize $Type"); |
358 } | 367 } |