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