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