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