Commit | Line | Data |
12145c6e |
1 | |
2 | package MooseX::Storage::Engine::IO::AtomicFile; |
3 | use Moose; |
4 | |
5 | use IO::AtomicFile; |
6 | |
7 | has 'file' => ( |
8 | is => 'ro', |
9 | isa => 'Str', |
10 | required => 1, |
11 | ); |
12 | |
13 | sub load { |
14 | my ($self) = @_; |
6f0912d0 |
15 | # NOTE:sv |
12145c6e |
16 | # AtomicFile gives us no real |
17 | # benefit when reading, so why |
18 | # bother |
19 | # - SL |
20 | my $fh = IO::File->new($self->file, 'r'); |
21 | return do { local $/; <$fh>; }; |
22 | } |
23 | |
24 | sub store { |
25 | my ($self, $data) = @_; |
26 | my $fh = IO::AtomicFile->new($self->file, 'w'); |
27 | print $fh $data; |
28 | $fh->close() |
29 | || confess "Could not write atomic file (" . $self->file . ") because: $!"; |
30 | } |
31 | |
32 | 1; |
33 | |
34 | __END__ |
35 | |
36 | =pod |
37 | |
38 | =head1 NAME |
39 | |
40 | MooseX::Storage::Engine::IO::File |
41 | |
42 | =head1 SYNOPSIS |
43 | |
44 | =head1 DESCRIPTION |
45 | |
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 | |
80 | Copyright 2007 by Infinity Interactive, Inc. |
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 |