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