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;
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));
44 my ( $self, $collapsed, @args ) = @_;
49 if ( $d->can("clone") ) {
51 } elsif ( $d->can("reset") ) {
54 die "Can't clone or reset digest object: $d";
57 $d = Digest->new($d || "SHA1", @args);
61 local $Storable::canonical = 1;
62 $d->add( Storable::nfreeze($collapsed) );
77 MooseX::Storage::Base::WithChecksum
87 =item B<pack (?$salt)>
89 =item B<unpack ($data, ?$salt)>
103 All complex software has bugs lurking in it, and this module is no
104 exception. If you find a bug please either email me, or add the bug
109 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
111 =head1 COPYRIGHT AND LICENSE
113 Copyright 2007 by Infinity Interactive, Inc.
115 L<http://www.iinteractive.com>
117 This library is free software; you can redistribute it and/or modify
118 it under the same terms as Perl itself.