line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Storage::Format::Storable; |
2
|
|
|
|
|
|
|
# ABSTRACT: A Storable serialization role |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.52'; |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
1222
|
use Moose::Role; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
16
|
|
7
|
2
|
|
|
2
|
|
8417
|
use Storable (); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
38
|
|
8
|
2
|
|
|
2
|
|
10
|
use namespace::autoclean; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
19
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
requires 'pack'; |
11
|
|
|
|
|
|
|
requires 'unpack'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub thaw { |
14
|
2
|
|
|
2
|
1
|
13626
|
my ( $class, $stored, @args ) = @_; |
15
|
2
|
|
|
|
|
8
|
$class->unpack( Storable::thaw($stored), @args ); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub freeze { |
19
|
2
|
|
|
2
|
1
|
6502
|
my ( $self, @args ) = @_; |
20
|
2
|
|
|
|
|
16
|
Storable::nfreeze( $self->pack(@args) ); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
2
|
|
335
|
no Moose::Role; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
11
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
1; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
__END__ |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=pod |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=encoding UTF-8 |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 NAME |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
MooseX::Storage::Format::Storable - A Storable serialization role |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 VERSION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
version 0.52 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 SYNOPSIS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
package Point; |
44
|
|
|
|
|
|
|
use Moose; |
45
|
|
|
|
|
|
|
use MooseX::Storage; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
with Storage('format' => 'Storable'); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has 'x' => (is => 'rw', isa => 'Int'); |
50
|
|
|
|
|
|
|
has 'y' => (is => 'rw', isa => 'Int'); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $p = Point->new(x => 10, y => 10); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
## methods to freeze/thaw into |
57
|
|
|
|
|
|
|
## a specified serialization format |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# pack the class with Storable |
60
|
|
|
|
|
|
|
my $storable_data = $p->freeze(); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# unpack the storable data into the class |
63
|
|
|
|
|
|
|
my $p2 = Point->thaw($storable_data); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 DESCRIPTION |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=for stopwords IPC |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
This module will C<thaw> and C<freeze> Moose classes using Storable. It |
70
|
|
|
|
|
|
|
uses C<Storable::nfreeze> by default so that it can be easily used |
71
|
|
|
|
|
|
|
in IPC scenarios across machines or just locally. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=for stopwords Storable's |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
One important thing to note is that this module does not mix well |
76
|
|
|
|
|
|
|
with the IO modules. The structures that C<freeze> and C<thaw> deal with |
77
|
|
|
|
|
|
|
are Storable's memory representation, and (as far as I know) that |
78
|
|
|
|
|
|
|
is not easily just written onto a file. If you want file based |
79
|
|
|
|
|
|
|
serialization with Storable, the please look at the |
80
|
|
|
|
|
|
|
L<MooseX::Storage::IO::StorableFile> role instead. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 METHODS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=over 4 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item B<freeze> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item B<thaw ($stored)> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=back |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 SUPPORT |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Storage> |
95
|
|
|
|
|
|
|
(or L<bug-MooseX-Storage@rt.cpan.org|mailto:bug-MooseX-Storage@rt.cpan.org>). |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
There is also a mailing list available for users of this distribution, at |
98
|
|
|
|
|
|
|
L<http://lists.perl.org/list/moose.html>. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
There is also an irc channel available for users of this distribution, at |
101
|
|
|
|
|
|
|
L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 AUTHORS |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=over 4 |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item * |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Chris Prather <chris.prather@iinteractive.com> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item * |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Stevan Little <stevan.little@iinteractive.com> |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item * |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
×××× ×§××'×× (Yuval Kogman) <nothingmuch@woobling.org> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=back |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This software is copyright (c) 2007 by Infinity Interactive, Inc. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
126
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |