line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
36
|
|
|
36
|
|
103726
|
|
|
36
|
|
|
|
|
79
|
|
|
36
|
|
|
|
|
230
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2019'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Catmandu::Util qw(require_package); |
7
|
36
|
|
|
36
|
|
273
|
use Moo::Role; |
|
36
|
|
|
|
|
73
|
|
|
36
|
|
|
|
|
1500
|
|
8
|
36
|
|
|
36
|
|
182
|
use namespace::clean; |
|
36
|
|
|
|
|
155
|
|
|
36
|
|
|
|
|
205
|
|
9
|
36
|
|
|
36
|
|
12210
|
|
|
36
|
|
|
|
|
86
|
|
|
36
|
|
|
|
|
198
|
|
10
|
|
|
|
|
|
|
has serialization_format => |
11
|
|
|
|
|
|
|
(is => 'ro', builder => 'default_serialization_format',); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has serializer => ( |
14
|
|
|
|
|
|
|
is => 'ro', |
15
|
|
|
|
|
|
|
lazy => 1, |
16
|
|
|
|
|
|
|
builder => '_build_serializer', |
17
|
|
|
|
|
|
|
handles => [qw(serialize deserialize)] |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
107
|
|
|
107
|
0
|
5044
|
my ($self) = @_; |
22
|
|
|
|
|
|
|
my $pkg = require_package($self->serialization_format, |
23
|
|
|
|
|
|
|
'Catmandu::Serializer'); |
24
|
2
|
|
|
2
|
|
446
|
$pkg->new; |
25
|
2
|
|
|
|
|
17
|
} |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
|
|
14
|
# Implementer needs to be create a serializer |
28
|
|
|
|
|
|
|
# sub serialize {} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Implementers needs to be create a deserializer |
31
|
|
|
|
|
|
|
# sub deserialize {} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=pod |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 NAME |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Catmandu::Serializer - Base class for all Catmandu Serializers |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 SYNOPSIS |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
package Catmandu::Serializer::Foo; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
use Moo; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub serialize { |
49
|
|
|
|
|
|
|
my ($self,$data) = @_; |
50
|
|
|
|
|
|
|
.. transform the data to a string and return it... |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub deserialize { |
54
|
|
|
|
|
|
|
my ($self,$string) = @_; |
55
|
|
|
|
|
|
|
... transform the string into a perl hash ... |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
package MyPackage; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
use Moo; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
with 'Catmandu::Serializer'; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
package main; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $pkg = MyPackage->new; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $string = $pkg->serialize({ foo => 'bar' }); |
69
|
|
|
|
|
|
|
my $perl = $pkg->deserialize($string); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Using Catmandu::Serializer::Foo |
72
|
|
|
|
|
|
|
my $pkg = MyPackage->new( serialization_format => 'Foo' ); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $string = $pkg->serialize({ foo => 'bar' }); |
75
|
|
|
|
|
|
|
my $perl = $pkg->deserialize($string); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 DESCRIPTION |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This is a convience class to send Perl hashes easily over the wire without having to |
80
|
|
|
|
|
|
|
instantiate a L<Catmandu::Importer> and L<Catmandu::Exporter> which are more suited for |
81
|
|
|
|
|
|
|
processing IO streams. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 serialization_format |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
The name of the package that serializes data. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 serializer |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
An instance of the package that serializes. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 METHODS |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 serialize($perl) |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Serialize a perl data structure into a string. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 deserialize($bytes) |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Deserialize bytes into a perl data structure. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SEE ALSO |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
L<Catmandu::Store::DBI>, |
106
|
|
|
|
|
|
|
L<Catmandu::Serializer::json>, |
107
|
|
|
|
|
|
|
L<Catmandu::Serializer::storabe>, |
108
|
|
|
|
|
|
|
L<Catmandu::Serializer::messagepack> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |