File Coverage

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