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