File Coverage

blib/lib/Kelp/Module/Sereal.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition 2 4 50.0
subroutine 5 5 100.0
pod 3 3 100.0
total 26 28 92.8


line stmt bran cond sub pod time code
1             $Kelp::Module::Sereal::VERSION = '1.02';
2             use Kelp::Base qw(Kelp::Module);
3 1     1   35249 use Sereal qw(get_sereal_encoder get_sereal_decoder);
  1         3  
  1         6  
4 1     1   171  
  1         3  
  1         251  
5             attr -encoder;
6             attr -decoder;
7              
8             {
9             my $self = shift;
10             $self->encoder->encode(@_);
11 2     2 1 1594 }
12 2         5  
13             {
14             my $self = shift;
15             $self->decoder->decode(@_);
16             }
17 2     2 1 1003  
18 2         5 {
19             my ($self, %args) = @_;
20              
21             my $encoder_opts = $args{encoder} // {};
22             my $decoder_opts = $args{decoder} // {};
23 1     1 1 66  
24             $self->{encoder} = get_sereal_encoder($encoder_opts);
25 1   50     6 $self->{decoder} = get_sereal_decoder($decoder_opts);
26 1   50     2  
27             $self->register(sereal => $self);
28 1         5 }
29 1         33  
30             1;
31 1         25  
32             =head1 NAME
33              
34             Kelp::Module::Sereal - Sereal encoder / decoder for Kelp
35              
36             =head1 SYNOPSIS
37              
38             # in config
39             modules => [qw(Sereal)],
40             modules_init => {
41             Sereal => {
42             encoder => {
43             # encoder options
44             },
45             decoder => {
46             # decoder options
47             },
48             },
49             },
50              
51             # in your application
52             my $encoded = $self->sereal->encode({
53             type => 'structure',
54             name => [qw(testing sereal)],
55             });
56              
57              
58             =head1 DESCRIPTION
59              
60             This is a very straightforward module that integrates the L<Kelp> framework with the L<Sereal> serialization protocol. See L<Sereal::Encoder> and L<Sereal::Decoder> for a full reference on the encoder and the decoder.
61              
62             =head1 METHODS INTRODUCED TO KELP
63              
64             =head2 sereal
65              
66             my $sereal_module = $kelp->sereal;
67              
68             Returns the instance of this module. You can use this instance to invoke the methods listed below.
69              
70             =head1 METHODS
71              
72             =head2 encode
73              
74             my $encoded = $kelp->sereal->encode($data);
75              
76             A shortcut to C<< $kelp->sereal->encoder->encode >>
77              
78             =head2 encoder
79              
80             my $encoder_instance = $kelp->sereal->encoder;
81              
82             Returns the instance of L<Sereal::Encoder>
83              
84             =head2 decode
85              
86             my $decoded = $kelp->sereal->decode($sereal_string);
87              
88             A shortcut to C<< $kelp->sereal->decoder->decode >>
89              
90             =head2 decoder
91              
92             my $decoder_instance = $kelp->sereal->decoder;
93              
94             Returns the instance of L<Sereal::Decoder>
95              
96             =head1 CONFIGURATION
97              
98             =head2 encoder
99              
100             A hashref with all the arguments to L<Sereal::Encoder/new>.
101              
102             =head2 decoder
103              
104             A hashref with all the arguments to L<Sereal::Decoder/new>.
105              
106             =head1 SEE ALSO
107              
108             =over 2
109              
110             =item * L<Kelp>, the framework
111              
112             =item * L<Sereal>, the wrapper for the encoder / decoder
113              
114             =back
115              
116             =head1 AUTHOR
117              
118             Bartosz Jarzyna, E<lt>bbrtj.pro@gmail.comE<gt>
119              
120             =head1 COPYRIGHT AND LICENSE
121              
122             Copyright (C) 2021 - 2022 by Bartosz Jarzyna
123              
124             This library is free software; you can redistribute it and/or modify
125             it under the same terms as Perl itself.
126              
127             =cut
128