2 package MooseX::Storage::Base::WithChecksum;
8 use MooseX::Storage::Engine;
10 our $VERSION = '0.01';
11 our $AUTHORITY = 'cpan:STEVAN';
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);
50 local $Data::Dumper::Indent = 0;
51 local $Data::Dumper::Sortkeys = 1;
52 $d->add( Data::Dumper::Dumper($collapsed) );
59 my ( $self, %options ) = @_;
60 my $digest_opts = $options{digest};
62 $digest_opts = [ $digest_opts ]
63 if !ref($digest_opts) or ref($digest_opts) ne 'ARRAY';
65 my ( $d, @args ) = @$digest_opts;
68 if ( $d->can("clone") ) {
71 elsif ( $d->can("reset") ) {
76 die "Can't clone or reset digest object: $d";
80 return Digest->new($d || "SHA1", @args);
92 MooseX::Storage::Base::WithChecksum
96 This is an early implementation of a more secure Storage role,
97 which does integrity checks on the data. It is still being
98 developed so I recommend using it with caution.
100 Any thoughts, ideas or suggestions on improving our technique
107 =item B<pack (?$salt)>
109 =item B<unpack ($data, ?$salt)>
123 All complex software has bugs lurking in it, and this module is no
124 exception. If you find a bug please either email me, or add the bug
129 Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
133 =head1 COPYRIGHT AND LICENSE
135 Copyright 2007 by Infinity Interactive, Inc.
137 L<http://www.iinteractive.com>
139 This library is free software; you can redistribute it and/or modify
140 it under the same terms as Perl itself.