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