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