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