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