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_class->new( object => $self );
12 $e->collapse_object(@args);
16 my ($class, $data, %args) = @_;
17 my $e = $class->_storage_get_engine_class->new(class => $class);
19 $class->_storage_construct_instance(
20 $e->expand_object($data, %args),
25 sub _storage_get_engine_class {
26 'MooseX::Storage::Engine';
29 sub _storage_construct_instance {
30 my ($class, $args, $opts) = @_;
31 my %i = defined $opts->{'inject'} ? %{ $opts->{'inject'} } : ();
33 $class->new( %$args, %i );
44 MooseX::Storage::Basic - The simplest level of serialization
52 our $VERSION = '0.01';
56 has 'x' => (is => 'rw', isa => 'Int');
57 has 'y' => (is => 'rw', isa => 'Int');
61 my $p = Point->new(x => 10, y => 10);
63 ## methods to pack/unpack an
64 ## object in perl data structures
66 # pack the class into a hash
67 $p->pack(); # { __CLASS__ => 'Point-0.01', x => 10, y => 10 }
69 # unpack the hash into a class
70 my $p2 = Point->unpack({ __CLASS__ => 'Point-0.01', x => 10, y => 10 });
72 # unpack the hash, with insertion of paramaters
73 my $p3 = Point->unpack( $p->pack, inject => { x => 11 } );
77 This is the most basic form of serialization. This is used by default
78 but the exported C<Storage> function.
84 =item B<pack ([ disable_cycle_check => 1])>
86 Providing the C<disable_cycle_check> argument disables checks for any cyclical
87 references. The current implementation for this check is rather naive, so if
88 you know what you are doing, you can bypass this check.
90 This trait is applied on a perl-case basis. To set this flag for all objects
91 that inherit from this role, see L<MooseX::Storage::Traits::DisableCycleDetection>.
93 =item B<unpack ($data [, insert => { key => val, ... } ] )>
95 Providing the C<insert> argument let's you supply additional arguments to
96 the class' C<new> function, or override ones from the serialized data.
110 All complex software has bugs lurking in it, and this module is no
111 exception. If you find a bug please either email me, or add the bug
116 Chris Prather E<lt>chris.prather@iinteractive.comE<gt>
118 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
120 =head1 COPYRIGHT AND LICENSE
122 Copyright 2007-2008 by Infinity Interactive, Inc.
124 L<http://www.iinteractive.com>
126 This library is free software; you can redistribute it and/or modify
127 it under the same terms as Perl itself.