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