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