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