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