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