foo
[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
7b428d1f 7our $VERSION = '0.01';
8
ec9c1923 9sub pack {
a6ebb4c8 10 my ( $self, @args ) = @_;
ec9c1923 11 my $e = MooseX::Storage::Engine->new( object => $self );
a6ebb4c8 12 $e->collapse_object(@args);
ec9c1923 13}
14
15sub unpack {
a6ebb4c8 16 my ( $class, $data, @args ) = @_;
ec9c1923 17 my $e = MooseX::Storage::Engine->new( class => $class );
a6ebb4c8 18 $class->new( $e->expand_object($data, @args) );
ec9c1923 19}
20
211;
22
23__END__
24
25=pod
26
27=head1 NAME
28
1390c23d 29MooseX::Storage::Basic - The simplest level of serialization
ec9c1923 30
31=head1 SYNOPSIS
32
1390c23d 33 package Point;
34 use Moose;
35 use MooseX::Storage;
36
c1830046 37 our $VERSION = '0.01';
38
1390c23d 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
c1830046 52 $p->pack(); # { __CLASS__ => 'Point-0.01', x => 10, y => 10 }
1390c23d 53
54 # unpack the hash into a class
c1830046 55 my $p2 = Point->unpack({ __CLASS__ => 'Point-0.01', x => 10, y => 10 });
1390c23d 56
ec9c1923 57=head1 DESCRIPTION
58
1390c23d 59This is the most basic form of serialization. This is used by default
60but the exported C<Storage> function.
61
ec9c1923 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
82All complex software has bugs lurking in it, and this module is no
83exception. If you find a bug please either email me, or add the bug
84to cpan-RT.
85
86=head1 AUTHOR
87
88Chris Prather E<lt>chris.prather@iinteractive.comE<gt>
89
90Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
91
92=head1 COPYRIGHT AND LICENSE
93
94Copyright 2007 by Infinity Interactive, Inc.
95
96L<http://www.iinteractive.com>
97
98This library is free software; you can redistribute it and/or modify
99it under the same terms as Perl itself.
100
101=cut