From: Stevan Little Date: Fri, 30 Mar 2007 20:13:20 +0000 (+0000) Subject: adding atomic file X-Git-Tag: 0_02~30 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=12145c6eb1fafe979d96846a4df4607928918b8c;p=gitmo%2FMooseX-Storage.git adding atomic file --- diff --git a/lib/MooseX/Storage/Engine/IO/AtomicFile.pm b/lib/MooseX/Storage/Engine/IO/AtomicFile.pm new file mode 100644 index 0000000..89fc8cf --- /dev/null +++ b/lib/MooseX/Storage/Engine/IO/AtomicFile.pm @@ -0,0 +1,87 @@ + +package MooseX::Storage::Engine::IO::AtomicFile; +use Moose; + +use IO::AtomicFile; + +has 'file' => ( + is => 'ro', + isa => 'Str', + required => 1, +); + +sub load { + my ($self) = @_; + # NOTE: + # AtomicFile gives us no real + # benefit when reading, so why + # bother + # - SL + my $fh = IO::File->new($self->file, 'r'); + return do { local $/; <$fh>; }; +} + +sub store { + my ($self, $data) = @_; + my $fh = IO::AtomicFile->new($self->file, 'w'); + print $fh $data; + $fh->close() + || confess "Could not write atomic file (" . $self->file . ") because: $!"; +} + +1; + +__END__ + +=pod + +=head1 NAME + +MooseX::Storage::Engine::IO::File + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +=head1 METHODS + +=over 4 + +=item B + +=item B + +=item B + +=back + +=head2 Introspection + +=over 4 + +=item B + +=back + +=head1 BUGS + +All complex software has bugs lurking in it, and this module is no +exception. If you find a bug please either email me, or add the bug +to cpan-RT. + +=head1 AUTHOR + +Chris Prather Echris.prather@iinteractive.comE + +Stevan Little Estevan.little@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2007 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut