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