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