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