Commit | Line | Data |
4d1850a6 |
1 | package MooseX::Storage::Engine::IO::File; |
a23e18d7 |
2 | use Moose; |
3 | |
6237d568 |
4 | use utf8 (); |
a23e18d7 |
5 | use IO::File; |
6 | |
efd4f7a5 |
7 | our $VERSION = '0.35'; |
69b45b7d |
8 | our $AUTHORITY = 'cpan:STEVAN'; |
7b428d1f |
9 | |
ec9c1923 |
10 | has 'file' => ( |
11 | is => 'ro', |
12 | isa => 'Str', |
a23e18d7 |
13 | required => 1, |
14 | ); |
15 | |
16 | sub load { |
17 | my ($self) = @_; |
06a66732 |
18 | my $fh = IO::File->new($self->file, 'r') |
19 | || confess "Unable to open file (" . $self->file . ") for loading : $!"; |
a23e18d7 |
20 | return do { local $/; <$fh>; }; |
21 | } |
22 | |
23 | sub store { |
24 | my ($self, $data) = @_; |
06a66732 |
25 | my $fh = IO::File->new($self->file, 'w') |
26 | || confess "Unable to open file (" . $self->file . ") for storing : $!"; |
6237d568 |
27 | $fh->binmode(':utf8') if utf8::is_utf8($data); |
a23e18d7 |
28 | print $fh $data; |
4d1850a6 |
29 | } |
30 | |
ec9c1923 |
31 | 1; |
32 | |
33 | __END__ |
34 | |
35 | =pod |
36 | |
37 | =head1 NAME |
38 | |
b477f392 |
39 | MooseX::Storage::Engine::IO::File - The actually file storage mechanism. |
ec9c1923 |
40 | |
41 | =head1 DESCRIPTION |
42 | |
b477f392 |
43 | This provides the actual means to store data to a file. |
44 | |
ec9c1923 |
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 | |
1f3074ea |
79 | Copyright 2007-2008 by Infinity Interactive, Inc. |
ec9c1923 |
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 |