2 package MooseX::Storage::Base::WithChecksum;
7 use MooseX::Storage::Engine;
12 my ($self, @args ) = @_;
14 my $e = MooseX::Storage::Engine->new( object => $self );
16 my $collapsed = $e->collapse_object;
18 $collapsed->{__DIGEST__} = $self->_digest_packed($collapsed, @args);
24 my ($class, $data, @args) = @_;
26 # check checksum on data
28 my $old_checksum = $data->{__DIGEST__};
29 delete $data->{__DIGEST__};
31 my $checksum = $class->_digest_packed($data, @args);
33 ($checksum eq $old_checksum)
34 || confess "Bad Checksum got=($checksum) expected=($old_checksum)";
36 my $e = MooseX::Storage::Engine->new(class => $class);
37 $class->new($e->expand_object($data));
42 my ( $self, $collapsed, @args ) = @_;
47 if ( $d->can("clone") ) {
49 } elsif ( $d->can("reset") ) {
52 die "Can't clone or reset digest object: $d";
55 $d = Digest->new($d || "SHA1", @args);
59 local $Storable::canonical = 1;
60 $d->add( Storable::nfreeze($collapsed) );
75 MooseX::Storage::Base::WithChecksum
85 =item B<pack (?$salt)>
87 =item B<unpack ($data, ?$salt)>
101 All complex software has bugs lurking in it, and this module is no
102 exception. If you find a bug please either email me, or add the bug
107 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
109 =head1 COPYRIGHT AND LICENSE
111 Copyright 2007 by Infinity Interactive, Inc.
113 L<http://www.iinteractive.com>
115 This library is free software; you can redistribute it and/or modify
116 it under the same terms as Perl itself.