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