1 package MooseX::Storage::Deferred;
5 our $AUTHORITY = 'cpan:STEVAN';
7 with 'MooseX::Storage::Basic';
10 my ( $class, $packed, $type, @args ) = @_;
12 (exists $type->{format})
13 || confess "You must specify a format type to thaw from";
15 my $class_to_load = 'MooseX::Storage::Format::' . $type->{format};
16 Class::MOP::load_class($class_to_load);
18 my $method_to_call = $class_to_load . '::thaw';
20 $class->$method_to_call($packed, @args);
24 my ( $self, $type, @args ) = @_;
26 (exists $type->{format})
27 || confess "You must specify a format type to freeze into";
29 my $class_to_load = 'MooseX::Storage::Format::' . $type->{format};
30 Class::MOP::load_class($class_to_load);
32 my $method_to_call = $class_to_load . '::freeze';
34 $self->$method_to_call(@args);
45 MooseX::Storage::Deferred - A role for undecisive programmers
53 our $VERSION = '0.01';
55 with 'MooseX::Storage::Deferred';
57 has 'x' => (is => 'rw', isa => 'Int');
58 has 'y' => (is => 'rw', isa => 'Int');
62 my $p = Point->new(x => 10, y => 10);
64 ## methods to freeze/thaw into
65 ## a specified serialization format
66 ## (in this case JSON)
68 # pack the class into a JSON string
69 $p->freeze({ format => 'JSON' }); # { "__CLASS__" : "Point", "x" : 10, "y" : 10 }
71 # unpack the JSON string into a class
73 '{ "__CLASS__" : "Point", "x" : 10, "y" : 10 }',
79 This role is designed for those times when you need to
80 serialize into many different formats or I/O options.
81 It basically allows you to choose the format and IO
82 options only when you actually use them (see the
83 SYNOPSIS for more info)
89 =item B<freeze ($type_desc)>
91 =item B<thaw ($data, $type_desc)>
105 All complex software has bugs lurking in it, and this module is no
106 exception. If you find a bug please either email me, or add the bug
111 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
113 =head1 COPYRIGHT AND LICENSE
115 Copyright 2007-2008 by Infinity Interactive, Inc.
117 L<http://www.iinteractive.com>
119 This library is free software; you can redistribute it and/or modify
120 it under the same terms as Perl itself.