blib/lib/Kelp/Module/Sereal.pm

filter: Statementstmt 100% 20 / 20 Branchbran n/a Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 3 / 3 totaltotal 88.2% 30 / 34 CC 3 SCAR 6.4
CC
3
Cov
92%
build
3.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
↑ Summary
1 package Kelp::Module::Sereal;
2 1 $Kelp::Module::Sereal::VERSION = '1.02';
3 1 ▶use Kelp::Base qw(Kelp::Module);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Sereal qw(get_sereal_encoder get_sereal_decoder);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 attr -encoder;
7 1 attr -decoder;
8  
9 sub encode
10 {
11 2 ▶ my $self = shift;
Subroutine encode: called CC=1 SCAR=0.0
Pod documented
12 2 $self->encoder->encode(@_);
13 }
14  
15 sub decode
16 {
17 2 ▶ my $self = shift;
Subroutine decode: called CC=1 SCAR=0.0
Pod documented
18 2 $self->decoder->decode(@_);
19 }
20  
21 sub build
22 {
23 1 ▶ my ($self, %args) = @_;
Subroutine build: called CC=3 SCAR=11.2
Pod documented
24  
25 1 ▶ my $encoder_opts = $args{encoder} // {};
Condition50%1/2
$args{"encoder"} // {}
l!l
10
MC/DC0%0/1
$args{"encoder"} // {}
$args{"encoder"}
Truth table50%1/2
A
A= $args{"encoder"}
Aresult
11
00
26 1 ▶ my $decoder_opts = $args{decoder} // {};
Condition50%1/2
$args{"decoder"} // {}
l!l
10
MC/DC0%0/1
$args{"decoder"} // {}
$args{"decoder"}
Truth table50%1/2
A
A= $args{"decoder"}
Aresult
11
00
27  
28 1 $self->{encoder} = get_sereal_encoder($encoder_opts);
29 1 $self->{decoder} = get_sereal_decoder($decoder_opts);
30  
31 1 $self->register(sereal => $self);
32 }
33  
34 1 1;
35 __END__
36  
37 =head1 NAME
38  
39 Kelp::Module::Sereal - Sereal encoder / decoder for Kelp
40  
41 =head1 SYNOPSIS
42  
43 # in config
44 modules => [qw(Sereal)],
45 modules_init => {
46 Sereal => {
47 encoder => {
48 # encoder options
49 },
50 decoder => {
51 # decoder options
52 },
53 },
54 },
55  
56 # in your application
57 my $encoded = $self->sereal->encode({
58 type => 'structure',
59 name => [qw(testing sereal)],
60 });
61  
62  
63 =head1 DESCRIPTION
64  
65 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.
66  
67 =head1 METHODS INTRODUCED TO KELP
68  
69 =head2 sereal
70  
71 my $sereal_module = $kelp->sereal;
72  
73 Returns the instance of this module. You can use this instance to invoke the methods listed below.
74  
75 =head1 METHODS
76  
77 =head2 encode
78  
79 my $encoded = $kelp->sereal->encode($data);
80  
81 A shortcut to C<< $kelp->sereal->encoder->encode >>
82  
83 =head2 encoder
84  
85 my $encoder_instance = $kelp->sereal->encoder;
86  
87 Returns the instance of L<Sereal::Encoder>
88  
89 =head2 decode
90  
91 my $decoded = $kelp->sereal->decode($sereal_string);
92  
93 A shortcut to C<< $kelp->sereal->decoder->decode >>
94  
95 =head2 decoder
96  
97 my $decoder_instance = $kelp->sereal->decoder;
98  
99 Returns the instance of L<Sereal::Decoder>
100  
101 =head1 CONFIGURATION
102  
103 =head2 encoder
104  
105 A hashref with all the arguments to L<Sereal::Encoder/new>.
106  
107 =head2 decoder
108  
109 A hashref with all the arguments to L<Sereal::Decoder/new>.
110  
111 =head1 SEE ALSO
112  
113 =over 2
114  
115 =item * L<Kelp>, the framework
116  
117 =item * L<Sereal>, the wrapper for the encoder / decoder
118  
119 =back
120  
121 =head1 AUTHOR
122  
123 Bartosz Jarzyna, E<lt>bbrtj.pro@gmail.comE<gt>
124  
125 =head1 COPYRIGHT AND LICENSE
126  
127 Copyright (C) 2021 - 2022 by Bartosz Jarzyna
128  
129 This library is free software; you can redistribute it and/or modify
130 it under the same terms as Perl itself.
131  
132 =cut
133  
↑ Summary