adding support for Deferred
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage / Basic.pm
CommitLineData
ec9c1923 1
2package MooseX::Storage::Basic;
3use Moose::Role;
4
5use MooseX::Storage::Engine;
6
69b45b7d 7our $VERSION = '0.01';
8our $AUTHORITY = 'cpan:STEVAN';
7b428d1f 9
ec9c1923 10sub 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
16sub 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
221;
23
24__END__
25
26=pod
27
28=head1 NAME
29
1390c23d 30MooseX::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 60This is the most basic form of serialization. This is used by default
61but 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
83All complex software has bugs lurking in it, and this module is no
84exception. If you find a bug please either email me, or add the bug
85to cpan-RT.
86
87=head1 AUTHOR
88
89Chris Prather E<lt>chris.prather@iinteractive.comE<gt>
90
91Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
92
93=head1 COPYRIGHT AND LICENSE
94
1f3074ea 95Copyright 2007-2008 by Infinity Interactive, Inc.
ec9c1923 96
97L<http://www.iinteractive.com>
98
99This library is free software; you can redistribute it and/or modify
100it under the same terms as Perl itself.
101
102=cut