| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Kelp::Module::Sereal; |
|
2
|
|
|
|
|
|
|
$Kelp::Module::Sereal::VERSION = '2.10'; |
|
3
|
2
|
|
|
2
|
|
783065
|
use Kelp::Base qw(Kelp::Module::Encoder); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
14
|
|
|
4
|
2
|
|
|
2
|
|
4027
|
use Sereal qw(get_sereal_encoder get_sereal_decoder); |
|
|
2
|
|
|
|
|
1278
|
|
|
|
2
|
|
|
|
|
564
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
0
|
319
|
sub encoder_name { 'sereal' } |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub build_encoder |
|
9
|
|
|
|
|
|
|
{ |
|
10
|
3
|
|
|
3
|
0
|
168
|
my ($self, $args) = @_; |
|
11
|
|
|
|
|
|
|
|
|
12
|
3
|
|
50
|
|
|
10
|
my $encoder_opts = $args->{encoder} // {}; |
|
13
|
3
|
|
50
|
|
|
10
|
my $decoder_opts = $args->{decoder} // {}; |
|
14
|
|
|
|
|
|
|
|
|
15
|
3
|
|
|
|
|
12
|
return Kelp::Module::Sereal::Facade->new( |
|
16
|
|
|
|
|
|
|
encoder => get_sereal_encoder($encoder_opts), |
|
17
|
|
|
|
|
|
|
decoder => get_sereal_decoder($decoder_opts), |
|
18
|
|
|
|
|
|
|
); |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub build |
|
22
|
|
|
|
|
|
|
{ |
|
23
|
2
|
|
|
2
|
1
|
223
|
my ($self, %args) = @_; |
|
24
|
2
|
|
|
|
|
12
|
$self->SUPER::build(%args); |
|
25
|
|
|
|
|
|
|
|
|
26
|
2
|
|
|
|
|
15
|
$self->register(sereal => $self->get_encoder); |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
package Kelp::Module::Sereal::Facade { |
|
30
|
2
|
|
|
2
|
|
15
|
use Kelp::Base; |
|
|
2
|
|
|
|
|
10
|
|
|
|
2
|
|
|
|
|
29
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
attr -encoder; |
|
33
|
|
|
|
|
|
|
attr -decoder; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub encode |
|
36
|
|
|
|
|
|
|
{ |
|
37
|
2
|
|
|
2
|
|
1726
|
my $self = shift; |
|
38
|
2
|
|
|
|
|
6
|
$self->encoder->encode(@_); |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub decode |
|
42
|
|
|
|
|
|
|
{ |
|
43
|
2
|
|
|
2
|
|
938
|
my $self = shift; |
|
44
|
2
|
|
|
|
|
6
|
$self->decoder->decode(@_); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
$Kelp::Module::Sereal::Facade::VERSION = '2.10'; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
|
50
|
|
|
|
|
|
|
__END__ |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 NAME |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Kelp::Module::Sereal - Sereal encoder / decoder for Kelp |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# in config |
|
59
|
|
|
|
|
|
|
modules => [qw(Sereal)], |
|
60
|
|
|
|
|
|
|
modules_init => { |
|
61
|
|
|
|
|
|
|
Sereal => { |
|
62
|
|
|
|
|
|
|
encoder => { |
|
63
|
|
|
|
|
|
|
# encoder options |
|
64
|
|
|
|
|
|
|
}, |
|
65
|
|
|
|
|
|
|
decoder => { |
|
66
|
|
|
|
|
|
|
# decoder options |
|
67
|
|
|
|
|
|
|
}, |
|
68
|
|
|
|
|
|
|
}, |
|
69
|
|
|
|
|
|
|
}, |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# in your application |
|
72
|
|
|
|
|
|
|
my $encoded = $self->sereal->encode({ |
|
73
|
|
|
|
|
|
|
type => 'structure', |
|
74
|
|
|
|
|
|
|
name => [qw(testing sereal)], |
|
75
|
|
|
|
|
|
|
}); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Kelp 2.10 encoder factory |
|
78
|
|
|
|
|
|
|
my $new_sereal = $self->get_encoder(sereal => 'name'); |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This is a very straightforward module that integrates the L<Kelp> framework |
|
84
|
|
|
|
|
|
|
with the L<Sereal> serialization protocol. See L<Sereal::Encoder> and |
|
85
|
|
|
|
|
|
|
L<Sereal::Decoder> for a full reference on the encoder and the decoder. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This module is compatible with Kelp 2.10 encoders feature, so you can use it as |
|
88
|
|
|
|
|
|
|
a factory for Sereal encoders by calling C<get_encoder> on the Kelp app object. |
|
89
|
|
|
|
|
|
|
It registers itself under the name B<sereal>. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 METHODS INTRODUCED TO KELP |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 sereal |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $sereal_module = $kelp->sereal; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Returns the instance of an encoder facade. You can use this instance to invoke |
|
98
|
|
|
|
|
|
|
the methods listed below. |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 METHODS |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 encode |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my $encoded = $kelp->sereal->encode($data); |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
A shortcut to C<< $kelp->sereal->encoder->encode >> |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 encoder |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $encoder_instance = $kelp->sereal->encoder; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Returns the instance of L<Sereal::Encoder> |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 decode |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $decoded = $kelp->sereal->decode($sereal_string); |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
A shortcut to C<< $kelp->sereal->decoder->decode >> |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 decoder |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
my $decoder_instance = $kelp->sereal->decoder; |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Returns the instance of L<Sereal::Decoder> |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 encoder |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
A hashref with all the arguments to L<Sereal::Encoder/new>. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 decoder |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
A hashref with all the arguments to L<Sereal::Decoder/new>. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=over |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * L<Kelp>, the framework |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item * L<Sereal>, the wrapper for the encoder / decoder |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=back |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 AUTHOR |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Bartosz Jarzyna, E<lt>bbrtj.pro@gmail.comE<gt> |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Copyright (C) 2021 - 2024 by Bartosz Jarzyna |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
155
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |
|
158
|
|
|
|
|
|
|
|