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