File Coverage

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