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 :)
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__';
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) );
}
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);
}
}
Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
+Yuval Kogman
+
=head1 COPYRIGHT AND LICENSE
Copyright 2007 by Infinity Interactive, Inc.
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: $!";
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;
}