1 package MooseX::Storage::IO::StorableFile;
10 my ( $class, $filename, @args ) = @_;
12 return $class->thaw( Storable::retrieve($filename), @args )
13 if $class->can('thaw');
14 # otherwise just unpack
15 $class->unpack( Storable::retrieve($filename), @args );
19 my ( $self, $filename, @args ) = @_;
21 # try freezing, otherwise just pack
22 ($self->can('freeze') ? $self->freeze(@args) : $self->pack(@args)),
37 MooseX::Storage::IO::StorableFile - An Storable File I/O role
45 with Storage('io' => 'StorableFile');
47 has 'x' => (is => 'rw', isa => 'Int');
48 has 'y' => (is => 'rw', isa => 'Int');
52 my $p = Point->new(x => 10, y => 10);
54 ## methods to load/store a class
57 $p->store('my_point');
59 my $p2 = Point->load('my_point');
63 This module will C<load> and C<store> Moose classes using Storable. It
64 uses C<Storable::nstore> by default so that it can be easily used
65 across machines or just locally.
67 One important thing to note is that this module does not mix well
68 with the other Format modules. Since Storable serialized perl data
69 structures in it's own format, those roles are largely unnecessary.
71 However, there is always the possibility that having a set of
72 C<freeze/thaw> hooks can be useful, so because of that this module
73 will attempt to use C<freeze> or C<thaw> if that method is available.
74 Of course, you should be careful when doing this as it could lead to
75 all sorts of hairy issues. But you have been warned.
81 =item B<load ($filename)>
83 =item B<store ($filename)>
97 All complex software has bugs lurking in it, and this module is no
98 exception. If you find a bug please either email me, or add the bug
103 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
105 =head1 COPYRIGHT AND LICENSE
107 Copyright 2007-2008 by Infinity Interactive, Inc.
109 L<http://www.iinteractive.com>
111 This library is free software; you can redistribute it and/or modify
112 it under the same terms as Perl itself.