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