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