Version 0.32
[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 utf8 ();
6 use IO::AtomicFile;
7
8 our $VERSION   = '0.32';
9 our $AUTHORITY = 'cpan:STEVAN';
10
11 extends 'MooseX::Storage::Engine::IO::File';
12
13 sub store {
14         my ($self, $data) = @_;
15         my $fh = IO::AtomicFile->new($self->file, 'w')
16             || confess "Unable to open file (" . $self->file . ") for storing : $!";
17         $fh->binmode(':utf8') if utf8::is_utf8($data);      
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
31 MooseX::Storage::Engine::IO::AtomicFile - The actually atomic file storage mechanism.
32
33 =head1 DESCRIPTION
34
35 This provides the actual means to store data to a file atomically.
36
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
71 Copyright 2007-2008 by Infinity Interactive, Inc.
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