1 package MooseX::Storage::Basic;
4 use MooseX::Storage::Engine;
7 our $AUTHORITY = 'cpan:STEVAN';
10 my ( $self, @args ) = @_;
11 my $e = $self->_storage_get_engine( object => $self );
12 $e->collapse_object(@args);
16 my ($class, $data, %args) = @_;
17 my $e = $class->_storage_get_engine(class => $class);
19 $class->_storage_construct_instance(
20 [ $e->expand_object($data, %args) ],
25 sub _storage_get_engine {
27 MooseX::Storage::Engine->new( @_ );
30 sub _storage_construct_instance {
31 my ($class, $args, $opts) = @_;
33 my @i = defined $opts->{'inject'} ? @{ $opts->{'inject'} } : ();
35 $class->new( @$args, @i );
49 MooseX::Storage::Basic - The simplest level of serialization
57 our $VERSION = '0.01';
61 has 'x' => (is => 'rw', isa => 'Int');
62 has 'y' => (is => 'rw', isa => 'Int');
66 my $p = Point->new(x => 10, y => 10);
68 ## methods to pack/unpack an
69 ## object in perl data structures
71 # pack the class into a hash
72 $p->pack(); # { __CLASS__ => 'Point-0.01', x => 10, y => 10 }
74 # unpack the hash into a class
75 my $p2 = Point->unpack({ __CLASS__ => 'Point-0.01', x => 10, y => 10 });
79 This is the most basic form of serialization. This is used by default
80 but the exported C<Storage> function.
88 =item B<unpack ($data)>
102 All complex software has bugs lurking in it, and this module is no
103 exception. If you find a bug please either email me, or add the bug
108 Chris Prather E<lt>chris.prather@iinteractive.comE<gt>
110 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
112 =head1 COPYRIGHT AND LICENSE
114 Copyright 2007-2008 by Infinity Interactive, Inc.
116 L<http://www.iinteractive.com>
118 This library is free software; you can redistribute it and/or modify
119 it under the same terms as Perl itself.