0bf379f694b0693971fc07f4c0d6721a530bc27e
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage / IO / File.pm
1
2 package MooseX::Storage::IO::File;
3 use Moose::Role;
4
5 use MooseX::Storage::Engine::IO::File;
6
7 our $VERSION   = '0.01';
8 our $AUTHORITY = 'cpan:STEVAN';
9
10 requires 'thaw';
11 requires 'freeze';
12
13 sub load {
14     my ( $class, $filename, @args ) = @_;
15     $class->thaw( MooseX::Storage::Engine::IO::File->new( file => $filename )->load(), @args );
16 }
17
18 sub store {
19     my ( $self, $filename, @args ) = @_;
20     MooseX::Storage::Engine::IO::File->new( file => $filename )->store( $self->freeze(@args) );
21 }
22
23 1;
24
25 __END__
26
27 =pod
28
29 =head1 NAME
30
31 MooseX::Storage::IO::File
32
33 =head1 SYNOPSIS
34
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');
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
87 Copyright 2007-2008 by Infinity Interactive, Inc.
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
94 =cut
95
96