X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FStorage%2FBase%2FWithChecksum.pm;h=22c55931cfd3915413f97f1d9093bf18d6a23cfc;hb=004bf3ea04d7818116a94bb4b387d8ae1dd10f9a;hp=285e3e02ac5cf61c931edd2155656f9dd97297f1;hpb=298cda9863d1e75bd897cef144c86046aa16c430;p=gitmo%2FMooseX-Storage.git diff --git a/lib/MooseX/Storage/Base/WithChecksum.pm b/lib/MooseX/Storage/Base/WithChecksum.pm index 285e3e0..22c5593 100644 --- a/lib/MooseX/Storage/Base/WithChecksum.pm +++ b/lib/MooseX/Storage/Base/WithChecksum.pm @@ -6,7 +6,7 @@ with 'MooseX::Storage::Basic'; use Digest (); use Data::Dumper (); -our $VERSION = '0.18'; +our $VERSION = '0.28'; our $AUTHORITY = 'cpan:STEVAN'; our $DIGEST_MARKER = '__DIGEST__'; @@ -19,7 +19,7 @@ around pack => sub { my $collapsed = $self->$orig( @args ); $collapsed->{$DIGEST_MARKER} = $self->_digest_packed($collapsed, @args); - + return $collapsed; }; @@ -28,11 +28,11 @@ around unpack => sub { # check checksum on data my $old_checksum = delete $data->{$DIGEST_MARKER}; - + my $checksum = $class->_digest_packed($data, @args); ($checksum eq $old_checksum) - || confess "Bad Checksum got=($checksum) expected=($old_checksum)"; + || confess "Bad Checksum got=($checksum) expected=($old_checksum)"; $class->$orig( $data, @args ); }; @@ -51,12 +51,12 @@ sub _digest_packed { local $Data::Dumper::Deparse = 0; # FIXME? my $str = Data::Dumper::Dumper($collapsed); # NOTE: - # Canonicalize numbers to strings even if it - # mangles numbers inside strings. It really + # Canonicalize numbers to strings even if it + # mangles numbers inside strings. It really # does not matter since its just the checksum # anyway. # - YK/SL - $str =~ s/(?add( $str ); } @@ -66,29 +66,31 @@ sub _digest_packed { sub _digest_object { my ( $self, %options ) = @_; my $digest_opts = $options{digest}; - - $digest_opts = [ $digest_opts ] + + $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") ) { $d->reset; return $d; - } + } else { die "Can't clone or reset digest object: $d"; } - } + } else { return Digest->new($d || "SHA1", @args); } } +no Moose::Role; + 1; __END__ @@ -101,11 +103,11 @@ MooseX::Storage::Base::WithChecksum - A more secure serialization role =head1 DESCRIPTION -This is an early implementation of a more secure Storage role, -which does integrity checks on the data. It is still being -developed so I recommend using it with caution. +This is an early implementation of a more secure Storage role, +which does integrity checks on the data. It is still being +developed so I recommend using it with caution. -Any thoughts, ideas or suggestions on improving our technique +Any thoughts, ideas or suggestions on improving our technique are very welcome. =head1 METHODS @@ -128,7 +130,7 @@ are very welcome. =head1 BUGS -All complex software has bugs lurking in it, and this module is no +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.