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