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