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