line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
############################################################################# |
3
|
|
|
|
|
|
|
## $Id: Perl.pm 11294 2008-05-20 03:53:53Z spadkins $ |
4
|
|
|
|
|
|
|
############################################################################# |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package App::Serializer::Perl; |
7
|
|
|
|
|
|
|
$VERSION = (q$Revision: 11294 $ =~ /(\d[\d\.]*)/)[0]; # VERSION numbers generated by svn |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use App; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
10
|
1
|
|
|
1
|
|
7
|
use App::Serializer; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
11
|
|
|
|
|
|
|
@ISA = ( "App::Serializer" ); |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
App::Serializer::Perl - Interface for serialization and deserialization |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use App; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$context = App->context(); |
24
|
|
|
|
|
|
|
$serializer = $context->service("Serializer"); # or ... |
25
|
|
|
|
|
|
|
$serializer = $context->serializer(); |
26
|
|
|
|
|
|
|
$data = { |
27
|
|
|
|
|
|
|
an => 'arbitrary', |
28
|
|
|
|
|
|
|
collection => [ 'of', 'data', ], |
29
|
|
|
|
|
|
|
of => { |
30
|
|
|
|
|
|
|
arbitrary => 'depth', |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
$perl = $serializer->serialize($data); |
34
|
|
|
|
|
|
|
$data = $serializer->deserialize($perl); |
35
|
|
|
|
|
|
|
print $serializer->dump($data), "\n"; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
A Serializer allows you to serialize a structure of data |
40
|
|
|
|
|
|
|
of arbitrary depth to a scalar and deserialize it back to the |
41
|
|
|
|
|
|
|
structure. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
The Perl serializer uses perl data structure syntax as the serialized |
44
|
|
|
|
|
|
|
form of the data. It uses the Data::Dumper module from CPAN to perform |
45
|
|
|
|
|
|
|
the deserialization and serialization. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
1
|
|
7
|
use Data::Dumper; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
353
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub serialize { |
52
|
2
|
|
|
2
|
1
|
9192
|
my ($self, $data) = @_; |
53
|
2
|
|
|
|
|
5
|
my ($d, $perl); |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
24
|
$d = Data::Dumper->new([ $data ], [ "data" ]); |
56
|
2
|
|
|
|
|
223
|
my $indent = $self->{indent}; |
57
|
2
|
50
|
|
|
|
11
|
$indent = 1 if (!defined $indent); |
58
|
2
|
|
|
|
|
13
|
$d->Indent($indent); |
59
|
2
|
|
|
|
|
39
|
$perl = $d->Dump(); |
60
|
|
|
|
|
|
|
|
61
|
2
|
|
|
|
|
443
|
return $perl; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub deserialize { |
65
|
3
|
|
|
3
|
1
|
882
|
my ($self, $perl) = @_; |
66
|
3
|
|
|
|
|
6
|
my ($data); |
67
|
3
|
|
|
|
|
32
|
$perl =~ s/^\$([_a-zA-Z][_a-zA-Z0-9]*) *=/\$data =/; |
68
|
3
|
|
|
|
|
689
|
eval $perl; |
69
|
3
|
50
|
|
|
|
16
|
$data = $@ if ($@); |
70
|
3
|
|
|
|
|
13
|
return($data); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub serialized_content_type { |
74
|
0
|
|
|
0
|
1
|
|
'text/plain'; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|