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