Commit | Line | Data |
ec9c1923 |
1 | |
2 | package MooseX::Storage::Basic; |
3 | use Moose::Role; |
4 | |
5 | use MooseX::Storage::Engine; |
6 | |
7 | sub pack { |
8 | my $self = shift; |
9 | my $e = MooseX::Storage::Engine->new( object => $self ); |
10 | $e->collapse_object; |
11 | } |
12 | |
13 | sub unpack { |
14 | my ( $class, $data ) = @_; |
15 | my $e = MooseX::Storage::Engine->new( class => $class ); |
16 | $class->new( $e->expand_object($data) ); |
17 | } |
18 | |
19 | 1; |
20 | |
21 | __END__ |
22 | |
23 | =pod |
24 | |
25 | =head1 NAME |
26 | |
1390c23d |
27 | MooseX::Storage::Basic - The simplest level of serialization |
ec9c1923 |
28 | |
29 | =head1 SYNOPSIS |
30 | |
1390c23d |
31 | package Point; |
32 | use Moose; |
33 | use MooseX::Storage; |
34 | |
35 | with Storage; |
36 | |
37 | has 'x' => (is => 'rw', isa => 'Int'); |
38 | has 'y' => (is => 'rw', isa => 'Int'); |
39 | |
40 | 1; |
41 | |
42 | my $p = Point->new(x => 10, y => 10); |
43 | |
44 | ## methods to pack/unpack an |
45 | ## object in perl data structures |
46 | |
47 | # pack the class into a hash |
48 | $p->pack(); # { __CLASS__ => 'Point', x => 10, y => 10 } |
49 | |
50 | # unpack the hash into a class |
51 | my $p2 = Point->unpack({ __CLASS__ => 'Point', x => 10, y => 10 }); |
52 | |
ec9c1923 |
53 | =head1 DESCRIPTION |
54 | |
1390c23d |
55 | This is the most basic form of serialization. This is used by default |
56 | but the exported C<Storage> function. |
57 | |
ec9c1923 |
58 | =head1 METHODS |
59 | |
60 | =over 4 |
61 | |
62 | =item B<pack> |
63 | |
64 | =item B<unpack ($data)> |
65 | |
66 | =back |
67 | |
68 | =head2 Introspection |
69 | |
70 | =over 4 |
71 | |
72 | =item B<meta> |
73 | |
74 | =back |
75 | |
76 | =head1 BUGS |
77 | |
78 | All complex software has bugs lurking in it, and this module is no |
79 | exception. If you find a bug please either email me, or add the bug |
80 | to cpan-RT. |
81 | |
82 | =head1 AUTHOR |
83 | |
84 | Chris Prather E<lt>chris.prather@iinteractive.comE<gt> |
85 | |
86 | Stevan Little E<lt>stevan.little@iinteractive.comE<gt> |
87 | |
88 | =head1 COPYRIGHT AND LICENSE |
89 | |
90 | Copyright 2007 by Infinity Interactive, Inc. |
91 | |
92 | L<http://www.iinteractive.com> |
93 | |
94 | This library is free software; you can redistribute it and/or modify |
95 | it under the same terms as Perl itself. |
96 | |
97 | =cut |