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