move to github
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage / Engine / IO / File.pm
CommitLineData
4d1850a6 1package MooseX::Storage::Engine::IO::File;
a23e18d7 2use Moose;
3
4use IO::File;
5
ec9c1923 6has 'file' => (
8b2ba857 7 is => 'ro',
8 isa => 'Str',
9 required => 1,
a23e18d7 10);
11
8b2ba857 12sub 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>; };
a23e18d7 17}
18
19sub store {
8b2ba857 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;
4d1850a6 25}
26
ec9c1923 271;
28
29__END__
30
31=pod
32
33=head1 NAME
34
b477f392 35MooseX::Storage::Engine::IO::File - The actually file storage mechanism.
ec9c1923 36
37=head1 DESCRIPTION
38
b477f392 39This provides the actual means to store data to a file.
40
ec9c1923 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
8b2ba857 63All complex software has bugs lurking in it, and this module is no
ec9c1923 64exception. If you find a bug please either email me, or add the bug
65to cpan-RT.
66
67=head1 AUTHOR
68
69Chris Prather E<lt>chris.prather@iinteractive.comE<gt>
70
71Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
72
73=head1 COPYRIGHT AND LICENSE
74
1f3074ea 75Copyright 2007-2008 by Infinity Interactive, Inc.
ec9c1923 76
77L<http://www.iinteractive.com>
78
79This library is free software; you can redistribute it and/or modify
80it under the same terms as Perl itself.
81
82=cut