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