Version 0.32
[gitmo/MooseX-Storage.git] / lib / MooseX / Storage / Engine / IO / AtomicFile.pm
CommitLineData
12145c6e 1
2package MooseX::Storage::Engine::IO::AtomicFile;
3use Moose;
4
6237d568 5use utf8 ();
12145c6e 6use IO::AtomicFile;
7
e44b5f54 8our $VERSION = '0.32';
69b45b7d 9our $AUTHORITY = 'cpan:STEVAN';
7b428d1f 10
e64b7302 11extends 'MooseX::Storage::Engine::IO::File';
12145c6e 12
13sub store {
14 my ($self, $data) = @_;
06a66732 15 my $fh = IO::AtomicFile->new($self->file, 'w')
16 || confess "Unable to open file (" . $self->file . ") for storing : $!";
6237d568 17 $fh->binmode(':utf8') if utf8::is_utf8($data);
12145c6e 18 print $fh $data;
19 $fh->close()
20 || confess "Could not write atomic file (" . $self->file . ") because: $!";
21}
22
231;
24
25__END__
26
27=pod
28
29=head1 NAME
30
b477f392 31MooseX::Storage::Engine::IO::AtomicFile - The actually atomic file storage mechanism.
12145c6e 32
33=head1 DESCRIPTION
34
b477f392 35This provides the actual means to store data to a file atomically.
36
12145c6e 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
59All complex software has bugs lurking in it, and this module is no
60exception. If you find a bug please either email me, or add the bug
61to cpan-RT.
62
63=head1 AUTHOR
64
65Chris Prather E<lt>chris.prather@iinteractive.comE<gt>
66
67Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
68
69=head1 COPYRIGHT AND LICENSE
70
1f3074ea 71Copyright 2007-2008 by Infinity Interactive, Inc.
12145c6e 72
73L<http://www.iinteractive.com>
74
75This library is free software; you can redistribute it and/or modify
76it under the same terms as Perl itself.
77
78=cut