Commit | Line | Data |
bff7e5f7 |
1 | package MooseX::Storage::IO::File; |
a23e18d7 |
2 | use Moose::Role; |
3 | |
4d1850a6 |
4 | use MooseX::Storage::Engine::IO::File; |
5 | |
a0e1d538 |
6 | our $VERSION = '0.31'; |
69b45b7d |
7 | our $AUTHORITY = 'cpan:STEVAN'; |
7b428d1f |
8 | |
4d1850a6 |
9 | requires 'thaw'; |
10 | requires 'freeze'; |
a23e18d7 |
11 | |
12 | sub load { |
bf33d7c7 |
13 | my ( $class, $filename, @args ) = @_; |
14 | $class->thaw( MooseX::Storage::Engine::IO::File->new( file => $filename )->load(), @args ); |
bff7e5f7 |
15 | } |
16 | |
17 | sub store { |
bf33d7c7 |
18 | my ( $self, $filename, @args ) = @_; |
19 | MooseX::Storage::Engine::IO::File->new( file => $filename )->store( $self->freeze(@args) ); |
a23e18d7 |
20 | } |
21 | |
f82612bc |
22 | no Moose::Role; |
23 | |
a23e18d7 |
24 | 1; |
25 | |
26 | __END__ |
27 | |
28 | =pod |
29 | |
ec9c1923 |
30 | =head1 NAME |
31 | |
4fa64e86 |
32 | MooseX::Storage::IO::File - A basic File I/O role |
ec9c1923 |
33 | |
34 | =head1 SYNOPSIS |
35 | |
b477f392 |
36 | package Point; |
37 | use Moose; |
38 | use MooseX::Storage; |
ec725183 |
39 | |
b477f392 |
40 | with Storage('format' => 'JSON', 'io' => 'File'); |
ec725183 |
41 | |
b477f392 |
42 | has 'x' => (is => 'rw', isa => 'Int'); |
43 | has 'y' => (is => 'rw', isa => 'Int'); |
ec725183 |
44 | |
b477f392 |
45 | 1; |
ec725183 |
46 | |
b477f392 |
47 | my $p = Point->new(x => 10, y => 10); |
ec725183 |
48 | |
49 | ## methods to load/store a class |
b477f392 |
50 | ## on the file system |
ec725183 |
51 | |
b477f392 |
52 | $p->store('my_point.json'); |
ec725183 |
53 | |
b477f392 |
54 | my $p2 = Point->load('my_point.json'); |
ec9c1923 |
55 | |
56 | =head1 METHODS |
57 | |
58 | =over 4 |
59 | |
60 | =item B<load ($filename)> |
61 | |
62 | =item B<store ($filename)> |
63 | |
64 | =back |
65 | |
66 | =head2 Introspection |
67 | |
68 | =over 4 |
69 | |
70 | =item B<meta> |
71 | |
72 | =back |
73 | |
74 | =head1 BUGS |
75 | |
ec725183 |
76 | All complex software has bugs lurking in it, and this module is no |
ec9c1923 |
77 | exception. If you find a bug please either email me, or add the bug |
78 | to cpan-RT. |
79 | |
80 | =head1 AUTHOR |
81 | |
82 | Chris Prather E<lt>chris.prather@iinteractive.comE<gt> |
83 | |
84 | Stevan Little E<lt>stevan.little@iinteractive.comE<gt> |
85 | |
86 | =head1 COPYRIGHT AND LICENSE |
87 | |
1f3074ea |
88 | Copyright 2007-2008 by Infinity Interactive, Inc. |
ec9c1923 |
89 | |
90 | L<http://www.iinteractive.com> |
91 | |
92 | This library is free software; you can redistribute it and/or modify |
93 | it under the same terms as Perl itself. |
94 | |
a23e18d7 |
95 | =cut |
96 | |
ec9c1923 |
97 | |