adding support for Deferred
[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 our $AUTHORITY = 'cpan:STEVAN';
9
10 sub pack {
11     my ( $self, @args ) = @_;
12     my $e = MooseX::Storage::Engine->new( object => $self );
13     $e->collapse_object(@args);
14 }
15
16 sub unpack {
17     my ( $class, $data, @args ) = @_;
18     my $e = MooseX::Storage::Engine->new( class => $class );
19     $class->new( $e->expand_object($data, @args) );
20 }
21
22 1;
23
24 __END__
25
26 =pod
27
28 =head1 NAME
29
30 MooseX::Storage::Basic - The simplest level of serialization
31
32 =head1 SYNOPSIS
33
34   package Point;
35   use Moose;
36   use MooseX::Storage;
37   
38   our $VERSION = '0.01';
39   
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
53   $p->pack(); # { __CLASS__ => 'Point-0.01', x => 10, y => 10 }
54   
55   # unpack the hash into a class
56   my $p2 = Point->unpack({ __CLASS__ => 'Point-0.01', x => 10, y => 10 });
57
58 =head1 DESCRIPTION
59
60 This is the most basic form of serialization. This is used by default 
61 but the exported C<Storage> function.
62
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-2008 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