File Coverage

blib/lib/MooseX/Storage/Format/Storable.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 2 2 100.0
total 24 24 100.0


line stmt bran cond sub pod time code
1             package MooseX::Storage::Format::Storable;
2             # ABSTRACT: A Storable serialization role
3              
4             our $VERSION = '0.50';
5              
6 2     2   1660 use Moose::Role;
  2         3  
  2         19  
7 2     2   9678 use Storable ();
  2         5  
  2         36  
8 2     2   10 use namespace::autoclean;
  2         4  
  2         18  
9              
10             requires 'pack';
11             requires 'unpack';
12              
13             sub thaw {
14 2     2 1 18825 my ( $class, $stored, @args ) = @_;
15 2         10 $class->unpack( Storable::thaw($stored), @args );
16             }
17              
18             sub freeze {
19 2     2 1 6276 my ( $self, @args ) = @_;
20 2         19 Storable::nfreeze( $self->pack(@args) );
21             }
22              
23 2     2   309 no Moose::Role;
  2         4  
  2         9  
24              
25             1;
26              
27             __END__
28              
29             =pod
30              
31             =encoding UTF-8
32              
33             =head1 NAME
34              
35             MooseX::Storage::Format::Storable - A Storable serialization role
36              
37             =head1 VERSION
38              
39             version 0.50
40              
41             =head1 SYNOPSIS
42              
43             package Point;
44             use Moose;
45             use MooseX::Storage;
46              
47             with Storage('format' => 'Storable');
48              
49             has 'x' => (is => 'rw', isa => 'Int');
50             has 'y' => (is => 'rw', isa => 'Int');
51              
52             1;
53              
54             my $p = Point->new(x => 10, y => 10);
55              
56             ## methods to freeze/thaw into
57             ## a specified serialization format
58              
59             # pack the class with Storable
60             my $storable_data = $p->freeze();
61              
62             # unpack the storable data into the class
63             my $p2 = Point->thaw($storable_data);
64              
65             =head1 DESCRIPTION
66              
67             =for stopwords IPC
68              
69             This module will C<thaw> and C<freeze> Moose classes using Storable. It
70             uses C<Storable::nfreeze> by default so that it can be easily used
71             in IPC scenarios across machines or just locally.
72              
73             =for stopwords Storable's
74              
75             One important thing to note is that this module does not mix well
76             with the IO modules. The structures that C<freeze> and C<thaw> deal with
77             are Storable's memory representation, and (as far as I know) that
78             is not easily just written onto a file. If you want file based
79             serialization with Storable, the please look at the
80             L<MooseX::Storage::IO::StorableFile> role instead.
81              
82             =head1 METHODS
83              
84             =over 4
85              
86             =item B<freeze>
87              
88             =item B<thaw ($stored)>
89              
90             =back
91              
92             =head2 Introspection
93              
94             =over 4
95              
96             =item B<meta>
97              
98             =back
99              
100             =head1 BUGS
101              
102             All complex software has bugs lurking in it, and this module is no
103             exception. If you find a bug please or add the bug to cpan-RT
104             at L<https://rt.cpan.org/Dist/Display.html?Queue=MooseX-Storage>.
105              
106             =head1 AUTHORS
107              
108             =over 4
109              
110             =item *
111              
112             Chris Prather <chris.prather@iinteractive.com>
113              
114             =item *
115              
116             Stevan Little <stevan.little@iinteractive.com>
117              
118             =item *
119              
120             יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
121              
122             =back
123              
124             =head1 COPYRIGHT AND LICENSE
125              
126             This software is copyright (c) 2007 by Infinity Interactive, Inc..
127              
128             This is free software; you can redistribute it and/or modify it under
129             the same terms as the Perl 5 programming language system itself.
130              
131             =cut