2 package MooseX::Storage::Base::WithChecksum;
8 use MooseX::Storage::Engine;
10 our $VERSION = '0.01';
12 our $DIGEST_MARKER = '__DIGEST__';
15 my ($self, @args ) = @_;
17 my $e = MooseX::Storage::Engine->new( object => $self );
19 my $collapsed = $e->collapse_object(@args);
21 $collapsed->{$DIGEST_MARKER} = $self->_digest_packed($collapsed, @args);
27 my ($class, $data, @args) = @_;
29 # check checksum on data
31 my $old_checksum = 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);
49 local $Data::Dumper::Indent = 0;
50 local $Data::Dumper::Sortkeys = 1;
51 $d->add( Data::Dumper::Dumper($collapsed) );
58 my ( $self, %options ) = @_;
59 my $digest_opts = $options{digest};
61 $digest_opts = [ $digest_opts ]
62 if !ref($digest_opts) or ref($digest_opts) ne 'ARRAY';
64 my ( $d, @args ) = @$digest_opts;
67 if ( $d->can("clone") ) {
70 elsif ( $d->can("reset") ) {
75 die "Can't clone or reset digest object: $d";
79 return Digest->new($d || "SHA1", @args);
91 MooseX::Storage::Base::WithChecksum
95 This is an early implementation of a more secure Storage role,
96 which does integrity checks on the data. It is still being
97 developed so I recommend using it with caution.
99 Any thoughts, ideas or suggestions on improving our technique
106 =item B<pack (?$salt)>
108 =item B<unpack ($data, ?$salt)>
122 All complex software has bugs lurking in it, and this module is no
123 exception. If you find a bug please either email me, or add the bug
128 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
132 =head1 COPYRIGHT AND LICENSE
134 Copyright 2007 by Infinity Interactive, Inc.
136 L<http://www.iinteractive.com>
138 This library is free software; you can redistribute it and/or modify
139 it under the same terms as Perl itself.