File Coverage

blib/lib/Dancer2/Session/DBIC/Serializer/YAML.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition n/a
subroutine 9 9 100.0
pod 2 2 100.0
total 32 32 100.0


line stmt bran cond sub pod time code
1             package Dancer2::Session::DBIC::Serializer::YAML;
2              
3             =head1 NAME
4              
5             Dancer2::Session::DBIC::Serializer::YAML
6              
7             =head1 DESCRIPTION
8              
9             Use YAML serialization for session storage.
10              
11             B<NOTE:> you must install L<YAML> version >= 1.15 to use this serializer.
12              
13             =cut
14              
15 2     2   41672 use YAML 1.15 ();
  2         34  
  2         43  
16 2     2   769 use YAML::Dumper;
  2         16160  
  2         54  
17 2     2   817 use YAML::Loader;
  2         11732  
  2         41  
18 2     2   439 use Moo;
  2         8589  
  2         11  
19             with 'Dancer2::Session::DBIC::Role::Serializer';
20 2     2   1612 use namespace::clean;
  2         6502  
  2         12  
21              
22             =head1 ATTRIBUTES
23              
24             See L<Dancer2::Session::DBIC::Role::Serializer> for inherited attributes.
25              
26             =head2 serialize_options
27              
28             Override default with the following options:
29              
30             =over
31              
32             =item indent_width => 1
33              
34             =back
35              
36             =cut
37              
38             has '+serialize_options' => (
39             default => sub {
40             { indent_width => 1 };
41             },
42             );
43              
44             =head1 METHODS
45              
46             =head2 serialize $perl_objects
47              
48             Serialize C<$perl_objects> to YAML using L<YAML::Dumper>.
49              
50             =cut
51              
52             sub serialize {
53 7     7 1 3740 shift->serializer->dump(shift);
54             }
55              
56             sub _build_serializer {
57 3     3   562 YAML::Dumper->new( %{ shift->serialize_options } );
  3         60  
58             }
59              
60             =head2 deserialize $yaml
61              
62             Deserialize C<$yaml> to Perl objects using L<YAML::Loader>.
63              
64             =cut
65              
66             sub deserialize {
67 11     11 1 1599 shift->deserializer->load(shift);
68             }
69              
70             sub _build_deserializer {
71 2     2   523 YAML::Loader->new( %{ shift->deserialize_options } );
  2         30  
72             }
73              
74             1;