line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Storage::Basic; |
2
|
|
|
|
|
|
|
# ABSTRACT: The simplest level of serialization |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.50'; |
5
|
|
|
|
|
|
|
|
6
|
29
|
|
|
29
|
|
18602
|
use Moose::Role; |
|
29
|
|
|
|
|
57
|
|
|
29
|
|
|
|
|
411
|
|
7
|
29
|
|
|
29
|
|
172591
|
use MooseX::Storage::Engine; |
|
29
|
|
|
|
|
100
|
|
|
29
|
|
|
|
|
1278
|
|
8
|
29
|
|
|
29
|
|
268
|
use String::RewritePrefix; |
|
29
|
|
|
|
|
59
|
|
|
29
|
|
|
|
|
330
|
|
9
|
29
|
|
|
29
|
|
6079
|
use namespace::autoclean; |
|
29
|
|
|
|
|
62
|
|
|
29
|
|
|
|
|
232
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub pack { |
12
|
100
|
|
|
100
|
1
|
191365
|
my ( $self, %args ) = @_; |
13
|
100
|
|
|
|
|
389
|
my $e = $self->_storage_get_engine_class(%args)->new( object => $self ); |
14
|
100
|
|
|
|
|
59823
|
$e->collapse_object(%args); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub unpack { |
18
|
84
|
|
|
84
|
1
|
232745
|
my ($class, $data, %args) = @_; |
19
|
84
|
|
|
|
|
379
|
my $e = $class->_storage_get_engine_class(%args)->new(class => $class); |
20
|
|
|
|
|
|
|
|
21
|
84
|
|
|
|
|
49155
|
$class->_storage_construct_instance( |
22
|
|
|
|
|
|
|
$e->expand_object($data, %args), |
23
|
|
|
|
|
|
|
\%args |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _storage_get_engine_class { |
28
|
184
|
|
|
184
|
|
390
|
my ($self, %args) = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
return 'MooseX::Storage::Engine' |
31
|
|
|
|
|
|
|
unless ( |
32
|
|
|
|
|
|
|
exists $args{engine_traits} |
33
|
|
|
|
|
|
|
&& ref($args{engine_traits}) eq 'ARRAY' |
34
|
184
|
50
|
66
|
|
|
1684
|
&& scalar(@{$args{engine_traits}}) |
|
4
|
|
100
|
|
|
14
|
|
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my @roles = String::RewritePrefix->rewrite( |
38
|
|
|
|
|
|
|
{ |
39
|
|
|
|
|
|
|
'' => 'MooseX::Storage::Engine::Trait::', |
40
|
|
|
|
|
|
|
'+' => '', |
41
|
|
|
|
|
|
|
}, |
42
|
4
|
|
|
|
|
16
|
@{$args{engine_traits}} |
|
4
|
|
|
|
|
34
|
|
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
4
|
|
|
|
|
268
|
Moose::Meta::Class->create_anon_class( |
46
|
|
|
|
|
|
|
superclasses => ['MooseX::Storage::Engine'], |
47
|
|
|
|
|
|
|
roles => [ @roles ], |
48
|
|
|
|
|
|
|
cache => 1, |
49
|
|
|
|
|
|
|
)->name; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _storage_construct_instance { |
53
|
81
|
|
|
81
|
|
177
|
my ($class, $args, $opts) = @_; |
54
|
81
|
100
|
|
|
|
306
|
my %i = defined $opts->{'inject'} ? %{ $opts->{'inject'} } : (); |
|
1
|
|
|
|
|
5
|
|
55
|
|
|
|
|
|
|
|
56
|
81
|
|
|
|
|
456
|
$class->new( %$args, %i ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
29
|
|
|
29
|
|
10091
|
no Moose::Role; |
|
29
|
|
|
|
|
65
|
|
|
29
|
|
|
|
|
195
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=pod |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=encoding UTF-8 |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 NAME |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
MooseX::Storage::Basic - The simplest level of serialization |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 VERSION |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
version 0.50 |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 SYNOPSIS |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
package Point; |
80
|
|
|
|
|
|
|
use Moose; |
81
|
|
|
|
|
|
|
use MooseX::Storage; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
with Storage; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
has 'x' => (is => 'rw', isa => 'Int'); |
86
|
|
|
|
|
|
|
has 'y' => (is => 'rw', isa => 'Int'); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $p = Point->new(x => 10, y => 10); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
## methods to pack/unpack an |
93
|
|
|
|
|
|
|
## object in perl data structures |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# pack the class into a hash |
96
|
|
|
|
|
|
|
$p->pack(); # { __CLASS__ => 'Point-0.01', x => 10, y => 10 } |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# unpack the hash into a class |
99
|
|
|
|
|
|
|
my $p2 = Point->unpack({ __CLASS__ => 'Point-0.01', x => 10, y => 10 }); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# unpack the hash, with injection of additional paramaters |
102
|
|
|
|
|
|
|
my $p3 = Point->unpack( $p->pack, inject => { x => 11 } ); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 DESCRIPTION |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This is the most basic form of serialization. This is used by default |
107
|
|
|
|
|
|
|
but the exported C<Storage> function. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 METHODS |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=over 4 |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item B<pack ([ disable_cycle_check => 1])> |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Providing the C<disable_cycle_check> argument disables checks for any cyclical |
116
|
|
|
|
|
|
|
references. The current implementation for this check is rather naive, so if |
117
|
|
|
|
|
|
|
you know what you are doing, you can bypass this check. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This trait is applied on a perl-case basis. To set this flag for all objects |
120
|
|
|
|
|
|
|
that inherit from this role, see L<MooseX::Storage::Traits::DisableCycleDetection>. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item B<unpack ($data [, inject => { key => val, ... } ] )> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Providing the C<inject> argument lets you supply additional arguments to |
125
|
|
|
|
|
|
|
the class' C<new> function, or override ones from the serialized data. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=back |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 Introspection |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=over 4 |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item B<meta> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=back |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 BUGS |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
All complex software has bugs lurking in it, and this module is no |
140
|
|
|
|
|
|
|
exception. If you find a bug please or add the bug to cpan-RT |
141
|
|
|
|
|
|
|
at L<https://rt.cpan.org/Dist/Display.html?Queue=MooseX-Storage>. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 AUTHORS |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=over 4 |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item * |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Chris Prather <chris.prather@iinteractive.com> |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item * |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Stevan Little <stevan.little@iinteractive.com> |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item * |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
×××× ×§××'×× (Yuval Kogman) <nothingmuch@woobling.org> |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=back |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
This software is copyright (c) 2007 by Infinity Interactive, Inc.. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
166
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |