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