remove whitespace
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage / Format / Storable.pm
CommitLineData
124c2ba5 1package MooseX::Storage::Format::Storable;
2use Moose::Role;
3
4use Storable ();
5
81a523ba 6our $VERSION = '0.33';
124c2ba5 7our $AUTHORITY = 'cpan:STEVAN';
8
9requires 'pack';
10requires 'unpack';
11
12sub thaw {
13 my ( $class, $stored, @args ) = @_;
14 $class->unpack( Storable::thaw($stored), @args );
15}
16
17sub freeze {
18 my ( $self, @args ) = @_;
19 Storable::nfreeze( $self->pack(@args) );
20}
21
f82612bc 22no Moose::Role;
23
124c2ba5 241;
25
26__END__
27
28=pod
29
30=head1 NAME
31
4fa64e86 32MooseX::Storage::Format::Storable - A Storable serialization role
124c2ba5 33
34=head1 SYNOPSIS
35
36 package Point;
37 use Moose;
38 use MooseX::Storage;
ec725183 39
124c2ba5 40 with Storage('format' => 'Storable');
ec725183 41
124c2ba5 42 has 'x' => (is => 'rw', isa => 'Int');
43 has 'y' => (is => 'rw', isa => 'Int');
ec725183 44
124c2ba5 45 1;
ec725183 46
124c2ba5 47 my $p = Point->new(x => 10, y => 10);
ec725183 48
49 ## methods to freeze/thaw into
124c2ba5 50 ## a specified serialization format
ec725183 51
124c2ba5 52 # pack the class with Storable
ec725183 53 my $storable_data = $p->freeze();
54
124c2ba5 55 # unpack the storable data into the class
ec725183 56 my $p2 = Point->thaw($storable_data);
124c2ba5 57
58=head1 DESCRIPTION
59
ec725183 60This module will C<thaw> and C<freeze> Moose classes using Storable. It
61uses C<Storable::nfreeze> by default so that it can be easily used
62in IPC scenarios across machines or just locally.
124c2ba5 63
ec725183 64One important thing to note is that this module does not mix well
65with the IO modules. The structures that C<freeze> and C<thaw> deal with
66are Storable's memory representation, and (as far as I know) that
67is not easily just written onto a file. If you want file based
68serialization with Storable, the please look at the
124c2ba5 69L<MooseX::Storage::IO::StorableFile> role instead.
70
71=head1 METHODS
72
73=over 4
74
75=item B<freeze>
76
77=item B<thaw ($stored)>
78
79=back
80
81=head2 Introspection
82
83=over 4
84
85=item B<meta>
86
87=back
88
89=head1 BUGS
90
ec725183 91All complex software has bugs lurking in it, and this module is no
124c2ba5 92exception. If you find a bug please either email me, or add the bug
93to cpan-RT.
94
95=head1 AUTHOR
96
97Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
98
99=head1 COPYRIGHT AND LICENSE
100
1f3074ea 101Copyright 2007-2008 by Infinity Interactive, Inc.
124c2ba5 102
103L<http://www.iinteractive.com>
104
105This library is free software; you can redistribute it and/or modify
106it under the same terms as Perl itself.
107
108=cut
109
110