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