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