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