File Coverage

blib/lib/MooseX/Storage/IO/StorableFile.pm
Criterion Covered Total %
statement 17 17 100.0
branch 4 4 100.0
condition n/a
subroutine 6 6 100.0
pod 2 2 100.0
total 29 29 100.0


line stmt bran cond sub pod time code
1             package MooseX::Storage::IO::StorableFile;
2             # ABSTRACT: An Storable File I/O role
3              
4             our $VERSION = '0.52';
5              
6 2     2   1099 use Moose::Role;
  2         3  
  2         12  
7 2     2   7563 use Storable ();
  2         2470  
  2         41  
8 2     2   9 use namespace::autoclean;
  2         2  
  2         17  
9              
10             requires 'pack';
11             requires 'unpack';
12              
13             sub load {
14 2     2 1 13828 my ( $class, $filename, @args ) = @_;
15             # try thawing
16 2 100       18 return $class->thaw( Storable::retrieve($filename), @args )
17             if $class->can('thaw');
18             # otherwise just unpack
19 1         4 $class->unpack( Storable::retrieve($filename), @args );
20             }
21              
22             sub store {
23 2     2 1 13908 my ( $self, $filename, @args ) = @_;
24 2 100       33 Storable::nstore(
25             # try freezing, otherwise just pack
26             ($self->can('freeze') ? $self->freeze(@args) : $self->pack(@args)),
27             $filename
28             );
29             }
30              
31 2     2   347 no Moose::Role;
  2         3  
  2         10  
32              
33             1;
34              
35             __END__
36              
37             =pod
38              
39             =encoding UTF-8
40              
41             =head1 NAME
42              
43             MooseX::Storage::IO::StorableFile - An Storable File I/O role
44              
45             =head1 VERSION
46              
47             version 0.52
48              
49             =head1 SYNOPSIS
50              
51             package Point;
52             use Moose;
53             use MooseX::Storage;
54              
55             with Storage('io' => 'StorableFile');
56              
57             has 'x' => (is => 'rw', isa => 'Int');
58             has 'y' => (is => 'rw', isa => 'Int');
59              
60             1;
61              
62             my $p = Point->new(x => 10, y => 10);
63              
64             ## methods to load/store a class
65             ## on the file system
66              
67             $p->store('my_point');
68              
69             my $p2 = Point->load('my_point');
70              
71             =head1 DESCRIPTION
72              
73             This module will C<load> and C<store> Moose classes using Storable. It
74             uses C<Storable::nstore> by default so that it can be easily used
75             across machines or just locally.
76              
77             One important thing to note is that this module does not mix well
78             with the other Format modules. Since Storable serialized perl data
79             structures in it's own format, those roles are largely unnecessary.
80              
81             However, there is always the possibility that having a set of
82             C<freeze/thaw> hooks can be useful, so because of that this module
83             will attempt to use C<freeze> or C<thaw> if that method is available.
84             Of course, you should be careful when doing this as it could lead to
85             all sorts of hairy issues. But you have been warned.
86              
87             =head1 METHODS
88              
89             =over 4
90              
91             =item B<load ($filename)>
92              
93             =item B<store ($filename)>
94              
95             =back
96              
97             =head1 SUPPORT
98              
99             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Storage>
100             (or L<bug-MooseX-Storage@rt.cpan.org|mailto:bug-MooseX-Storage@rt.cpan.org>).
101              
102             There is also a mailing list available for users of this distribution, at
103             L<http://lists.perl.org/list/moose.html>.
104              
105             There is also an irc channel available for users of this distribution, at
106             L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>.
107              
108             =head1 AUTHORS
109              
110             =over 4
111              
112             =item *
113              
114             Chris Prather <chris.prather@iinteractive.com>
115              
116             =item *
117              
118             Stevan Little <stevan.little@iinteractive.com>
119              
120             =item *
121              
122             יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
123              
124             =back
125              
126             =head1 COPYRIGHT AND LICENSE
127              
128             This software is copyright (c) 2007 by Infinity Interactive, Inc.
129              
130             This is free software; you can redistribute it and/or modify it under
131             the same terms as the Perl 5 programming language system itself.
132              
133             =cut