delay loading all optional prereqs until runtime
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage / Engine / IO / File.pm
1 package MooseX::Storage::Engine::IO::File;
2 use Moose;
3
4 has 'file' => (
5     is       => 'ro',
6     isa      => 'Str',
7     required => 1,
8 );
9
10 sub load {
11     my ($self) = @_;
12
13     require IO::File;
14     my $fh = IO::File->new($self->file, 'r')
15         || confess "Unable to open file (" . $self->file . ") for loading : $!";
16     return do { local $/; <$fh>; };
17 }
18
19 sub store {
20     my ($self, $data) = @_;
21
22     require IO::File;
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;
27 }
28
29 1;
30
31 __END__
32
33 =pod
34
35 =head1 NAME
36
37 MooseX::Storage::Engine::IO::File - The actually file storage mechanism.
38
39 =head1 DESCRIPTION
40
41 This provides the actual means to store data to a file.
42
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
65 All complex software has bugs lurking in it, and this module is no
66 exception. If you find a bug please either email me, or add the bug
67 to cpan-RT.
68
69 =head1 AUTHOR
70
71 Chris Prather E<lt>chris.prather@iinteractive.comE<gt>
72
73 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
74
75 =head1 COPYRIGHT AND LICENSE
76
77 Copyright 2007-2008 by Infinity Interactive, Inc.
78
79 L<http://www.iinteractive.com>
80
81 This library is free software; you can redistribute it and/or modify
82 it under the same terms as Perl itself.
83
84 =cut