From: Stevan Little Date: Thu, 7 Jun 2007 17:46:22 +0000 (+0000) Subject: tweaks and shit X-Git-Tag: 0_02~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=06a66732eb48842ce6bea1259cf4570cc34d99ff;p=gitmo%2FMooseX-Storage.git tweaks and shit --- diff --git a/Changes b/Changes index b791ff2..c60ca1c 100644 --- a/Changes +++ b/Changes @@ -14,6 +14,10 @@ Revision history for MooseX-Storage when they are expanded. - added docs and tests for this + * MooseX::Storage::Engine::IO::(AtomicFile, File) + - added checks to make sure the file gets opened correctly + and dies if it does not. + 0.01 Mon. April 30, 2007 This was Chris's idea originally (blame him), and we expanded on it to create what you see here :) diff --git a/lib/MooseX/Storage/Base/WithChecksum.pm b/lib/MooseX/Storage/Base/WithChecksum.pm index 496ca72..fb40bcf 100644 --- a/lib/MooseX/Storage/Base/WithChecksum.pm +++ b/lib/MooseX/Storage/Base/WithChecksum.pm @@ -2,12 +2,11 @@ package MooseX::Storage::Base::WithChecksum; use Moose::Role; -use Digest (); -#use Storable (); -use MooseX::Storage::Engine; - +use Digest (); use Data::Dumper (); +use MooseX::Storage::Engine; + our $VERSION = '0.01'; our $DIGEST_MARKER = '__DIGEST__'; @@ -46,13 +45,9 @@ sub _digest_packed { my $d = $self->_digest_object(@args); - { - local $Storable::canonical = 1; - local $Data::Dumper::Indent = 0; + local $Data::Dumper::Indent = 0; local $Data::Dumper::Sortkeys = 1; - - #Storable::nfreeze($collapsed); $d->add( Data::Dumper::Dumper($collapsed) ); } @@ -62,19 +57,25 @@ sub _digest_packed { sub _digest_object { my ( $self, %options ) = @_; my $digest_opts = $options{digest}; - $digest_opts = [ $digest_opts ] if !ref($digest_opts) or ref($digest_opts) ne 'ARRAY'; + + $digest_opts = [ $digest_opts ] + if !ref($digest_opts) or ref($digest_opts) ne 'ARRAY'; + my ( $d, @args ) = @$digest_opts; if ( ref $d ) { if ( $d->can("clone") ) { return $d->clone; - } elsif ( $d->can("reset") ) { + } + elsif ( $d->can("reset") ) { $d->reset; return $d; - } else { + } + else { die "Can't clone or reset digest object: $d"; } - } else { + } + else { return Digest->new($d || "SHA1", @args); } } @@ -121,6 +122,8 @@ to cpan-RT. Stevan Little Estevan.little@iinteractive.comE +Yuval Kogman + =head1 COPYRIGHT AND LICENSE Copyright 2007 by Infinity Interactive, Inc. diff --git a/lib/MooseX/Storage/Engine/IO/AtomicFile.pm b/lib/MooseX/Storage/Engine/IO/AtomicFile.pm index f2e1058..5f891d8 100644 --- a/lib/MooseX/Storage/Engine/IO/AtomicFile.pm +++ b/lib/MooseX/Storage/Engine/IO/AtomicFile.pm @@ -10,7 +10,8 @@ extends 'MooseX::Storage::Engine::IO::File'; sub store { my ($self, $data) = @_; - my $fh = IO::AtomicFile->new($self->file, 'w'); + my $fh = IO::AtomicFile->new($self->file, 'w') + || confess "Unable to open file (" . $self->file . ") for storing : $!"; print $fh $data; $fh->close() || confess "Could not write atomic file (" . $self->file . ") because: $!"; diff --git a/lib/MooseX/Storage/Engine/IO/File.pm b/lib/MooseX/Storage/Engine/IO/File.pm index b5ba99d..defa4c8 100644 --- a/lib/MooseX/Storage/Engine/IO/File.pm +++ b/lib/MooseX/Storage/Engine/IO/File.pm @@ -14,13 +14,15 @@ has 'file' => ( sub load { my ($self) = @_; - my $fh = IO::File->new($self->file, 'r'); + my $fh = IO::File->new($self->file, 'r') + || confess "Unable to open file (" . $self->file . ") for loading : $!"; return do { local $/; <$fh>; }; } sub store { my ($self, $data) = @_; - my $fh = IO::File->new($self->file, 'w'); + my $fh = IO::File->new($self->file, 'w') + || confess "Unable to open file (" . $self->file . ") for storing : $!"; print $fh $data; }