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