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