0.02
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage / Engine / IO / File.pm
1
2 package MooseX::Storage::Engine::IO::File;
3 use Moose;
4
5 use IO::File;
6
7 our $VERSION = '0.02';
8
9 has 'file' => (
10         is       => 'ro',
11         isa      => 'Str',      
12         required => 1,
13 );
14
15 sub load { 
16         my ($self) = @_;
17         my $fh = IO::File->new($self->file, 'r')
18             || confess "Unable to open file (" . $self->file . ") for loading : $!";
19         return do { local $/; <$fh>; };
20 }
21
22 sub store {
23         my ($self, $data) = @_;
24         my $fh = IO::File->new($self->file, 'w')
25                 || confess "Unable to open file (" . $self->file . ") for storing : $!";
26         print $fh $data;
27 }
28
29 1;
30
31 __END__
32
33 =pod
34
35 =head1 NAME
36
37 MooseX::Storage::Engine::IO::File - The actually file storage mechanism.
38
39 =head1 DESCRIPTION
40
41 This provides the actual means to store data to a file.
42
43 =head1 METHODS
44
45 =over 4
46
47 =item B<file>
48
49 =item B<load>
50
51 =item B<store ($data)>
52
53 =back
54
55 =head2 Introspection
56
57 =over 4
58
59 =item B<meta>
60
61 =back
62
63 =head1 BUGS
64
65 All complex software has bugs lurking in it, and this module is no 
66 exception. If you find a bug please either email me, or add the bug
67 to cpan-RT.
68
69 =head1 AUTHOR
70
71 Chris Prather E<lt>chris.prather@iinteractive.comE<gt>
72
73 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
74
75 =head1 COPYRIGHT AND LICENSE
76
77 Copyright 2007 by Infinity Interactive, Inc.
78
79 L<http://www.iinteractive.com>
80
81 This library is free software; you can redistribute it and/or modify
82 it under the same terms as Perl itself.
83
84 =cut