Commit | Line | Data |
124c2ba5 |
1 | package MooseX::Storage::Format::Storable; |
2 | use Moose::Role; |
3 | |
4 | use Storable (); |
5 | |
81a523ba |
6 | our $VERSION = '0.33'; |
124c2ba5 |
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 | |
f82612bc |
22 | no Moose::Role; |
23 | |
124c2ba5 |
24 | 1; |
25 | |
26 | __END__ |
27 | |
28 | =pod |
29 | |
30 | =head1 NAME |
31 | |
4fa64e86 |
32 | MooseX::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 |
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. |
124c2ba5 |
63 | |
ec725183 |
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 |
124c2ba5 |
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 | |
ec725183 |
91 | All complex software has bugs lurking in it, and this module is no |
124c2ba5 |
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 | |
1f3074ea |
101 | Copyright 2007-2008 by Infinity Interactive, Inc. |
124c2ba5 |
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 | |