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