File Coverage

blib/lib/Scalar/Accessors/LikeHash/Sereal.pm
Criterion Covered Total %
statement 19 19 100.0
branch n/a
condition 4 6 66.6
subroutine 7 7 100.0
pod n/a
total 30 32 93.7


line stmt bran cond sub pod time code
1             package Scalar::Accessors::LikeHash::Sereal;
2              
3 1     1   10572 use 5.008;
  1         5  
  1         52  
4 1     1   7 use strict;
  1         2  
  1         47  
5 1     1   8 use warnings;
  1         2  
  1         82  
6              
7             our $AUTHORITY = 'cpan:TOBYINK';
8             our $VERSION = '0.002';
9              
10 1     1   16 use Sereal;
  1         2  
  1         62  
11              
12 1     1   995 use Role::Tiny::With;
  1         6589  
  1         210  
13             with 'Scalar::Accessors::LikeHash';
14              
15             my ($e, $d);
16              
17             sub _to_hash
18             {
19 15     15   23 my ($ref) = @_;
20 15   66     161 ($d ||= Sereal::Decoder::->new)->decode($$ref);
21             }
22              
23             sub _from_hash
24             {
25 8     8   13 my ($ref, $hash) = @_;
26 8   66     148 $$ref = ($e ||= Sereal::Encoder::->new)->encode($hash);
27             }
28              
29             1;
30              
31             __END__
32              
33             =head1 NAME
34              
35             Scalar::Accessors::LikeHash::Sereal - access a Sereal scalar string in a hash-like manner
36              
37             =head1 SYNOPSIS
38              
39             my $object = Scalar::Accessors::LikeHash::Sereal->new;
40            
41             $object->store(some_key => 42) unless $object->exists('some_key');
42             $object->fetch('some_key');
43             $object->delete('some_key');
44            
45             # The object is internally a blessed scalarref containing Sereal
46             print $$object;
47              
48             =head1 DESCRIPTION
49              
50             This is a concrete implementation of L<Scalar::Accessors::LikeHash>.
51              
52             This module requires L<Sereal> to be installed.
53              
54             =head1 BUGS
55              
56             Please report any bugs to
57             L<http://rt.cpan.org/Dist/Display.html?Queue=Scalar-Accessors-LikeHash>.
58              
59             =head1 SEE ALSO
60              
61             L<Scalar::Accessors::LikeHash>, L<Sereal>.
62              
63             =head1 AUTHOR
64              
65             Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
66              
67             =head1 COPYRIGHT AND LICENCE
68              
69             This software is copyright (c) 2013 by Toby Inkster.
70              
71             This is free software; you can redistribute it and/or modify it under
72             the same terms as the Perl 5 programming language system itself.
73              
74             =head1 DISCLAIMER OF WARRANTIES
75              
76             THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
77             WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
78             MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
79