2 package MooseX::Storage::Base::WithChecksum;
7 use MooseX::Storage::Engine;
11 our $DIGEST_MARKER = '__DIGEST__';
14 my ($self, @args ) = @_;
16 my $e = MooseX::Storage::Engine->new( object => $self );
18 my $collapsed = $e->collapse_object(@args);
20 $collapsed->{$DIGEST_MARKER} = $self->_digest_packed($collapsed, @args);
26 my ($class, $data, @args) = @_;
28 # check checksum on data
30 my $old_checksum = $data->{$DIGEST_MARKER};
31 delete $data->{$DIGEST_MARKER};
33 my $checksum = $class->_digest_packed($data, @args);
35 ($checksum eq $old_checksum)
36 || confess "Bad Checksum got=($checksum) expected=($old_checksum)";
38 my $e = MooseX::Storage::Engine->new(class => $class);
39 $class->new($e->expand_object($data, @args));
44 my ( $self, $collapsed, @args ) = @_;
46 my $d = $self->_digest_object(@args);
50 local $Storable::canonical = 1;
51 $d->add( Storable::nfreeze($collapsed) );
58 my ( $self, %options ) = @_;
59 my $digest_opts = $options{digest};
60 $digest_opts = [ $digest_opts ] if !ref($digest_opts) or ref($digest_opts) ne 'ARRAY';
61 my ( $d, @args ) = @$digest_opts;
64 if ( $d->can("clone") ) {
66 } elsif ( $d->can("reset") ) {
70 die "Can't clone or reset digest object: $d";
73 return Digest->new($d || "SHA1", @args);
85 MooseX::Storage::Base::WithChecksum
95 =item B<pack (?$salt)>
97 =item B<unpack ($data, ?$salt)>
111 All complex software has bugs lurking in it, and this module is no
112 exception. If you find a bug please either email me, or add the bug
117 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
119 =head1 COPYRIGHT AND LICENSE
121 Copyright 2007 by Infinity Interactive, Inc.
123 L<http://www.iinteractive.com>
125 This library is free software; you can redistribute it and/or modify
126 it under the same terms as Perl itself.