move to github
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage / IO / File.pm
1 package MooseX::Storage::IO::File;
2 use Moose::Role;
3
4 use MooseX::Storage::Engine::IO::File;
5
6 requires 'thaw';
7 requires 'freeze';
8
9 sub load {
10     my ( $class, $filename, @args ) = @_;
11     $class->thaw( MooseX::Storage::Engine::IO::File->new( file => $filename )->load(), @args );
12 }
13
14 sub store {
15     my ( $self, $filename, @args ) = @_;
16     MooseX::Storage::Engine::IO::File->new( file => $filename )->store( $self->freeze(@args) );
17 }
18
19 no Moose::Role;
20
21 1;
22
23 __END__
24
25 =pod
26
27 =head1 NAME
28
29 MooseX::Storage::IO::File - A basic File I/O role
30
31 =head1 SYNOPSIS
32
33   package Point;
34   use Moose;
35   use MooseX::Storage;
36
37   with Storage('format' => 'JSON', 'io' => 'File');
38
39   has 'x' => (is => 'rw', isa => 'Int');
40   has 'y' => (is => 'rw', isa => 'Int');
41
42   1;
43
44   my $p = Point->new(x => 10, y => 10);
45
46   ## methods to load/store a class
47   ## on the file system
48
49   $p->store('my_point.json');
50
51   my $p2 = Point->load('my_point.json');
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
73 All complex software has bugs lurking in it, and this module is no
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
85 Copyright 2007-2008 by Infinity Interactive, Inc.
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
92 =cut
93
94