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