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