2 package MooseX::Storage::Base::WithChecksum;
7 use MooseX::Storage::Engine;
11 our $VERSION = '0.01';
13 our $DIGEST_MARKER = '__DIGEST__';
16 my ($self, @args ) = @_;
18 my $e = MooseX::Storage::Engine->new( object => $self );
20 my $collapsed = $e->collapse_object(@args);
22 $collapsed->{$DIGEST_MARKER} = $self->_digest_packed($collapsed, @args);
28 my ($class, $data, @args) = @_;
30 # check checksum on data
32 my $old_checksum = delete $data->{$DIGEST_MARKER};
34 my $checksum = $class->_digest_packed($data, @args);
36 ($checksum eq $old_checksum)
37 || confess "Bad Checksum got=($checksum) expected=($old_checksum)";
39 my $e = MooseX::Storage::Engine->new(class => $class);
40 $class->new($e->expand_object($data, @args));
45 my ( $self, $collapsed, @args ) = @_;
47 my $d = $self->_digest_object(@args);
51 local $Storable::canonical = 1;
52 local $Data::Dumper::Indent = 0;
53 local $Data::Dumper::Sortkeys = 1;
55 #Storable::nfreeze($collapsed);
56 $d->add( Data::Dumper::Dumper($collapsed) );
63 my ( $self, %options ) = @_;
64 my $digest_opts = $options{digest};
65 $digest_opts = [ $digest_opts ] if !ref($digest_opts) or ref($digest_opts) ne 'ARRAY';
66 my ( $d, @args ) = @$digest_opts;
69 if ( $d->can("clone") ) {
71 } elsif ( $d->can("reset") ) {
75 die "Can't clone or reset digest object: $d";
78 return Digest->new($d || "SHA1", @args);
90 MooseX::Storage::Base::WithChecksum
100 =item B<pack (?$salt)>
102 =item B<unpack ($data, ?$salt)>
116 All complex software has bugs lurking in it, and this module is no
117 exception. If you find a bug please either email me, or add the bug
122 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
124 =head1 COPYRIGHT AND LICENSE
126 Copyright 2007 by Infinity Interactive, Inc.
128 L<http://www.iinteractive.com>
130 This library is free software; you can redistribute it and/or modify
131 it under the same terms as Perl itself.