my $e = MooseX::Storage::Engine->new( object => $self );
- my $collapsed = $e->collapse_object;
+ my $collapsed = $e->collapse_object(@args);
$collapsed->{$DIGEST_MARKER} = $self->_digest_packed($collapsed, @args);
|| confess "Bad Checksum got=($checksum) expected=($old_checksum)";
my $e = MooseX::Storage::Engine->new(class => $class);
- $class->new($e->expand_object($data));
+ $class->new($e->expand_object($data, @args));
}
sub _digest_packed {
my ( $self, $collapsed, @args ) = @_;
- my $d = shift @args;
+ my $d = $self->_digest_object(@args);
+
+
+ {
+ local $Storable::canonical = 1;
+ $d->add( Storable::nfreeze($collapsed) );
+ }
+
+ return $d->hexdigest;
+}
+
+sub _digest_object {
+ my ( $self, %options ) = @_;
+ my $digest_opts = $options{digest};
+ $digest_opts = [ $digest_opts ] if !ref($digest_opts) or ref($digest_opts) ne 'ARRAY';
+ my ( $d, @args ) = @$digest_opts;
if ( ref $d ) {
if ( $d->can("clone") ) {
- $d = $d->clone;
+ return $d->clone;
} elsif ( $d->can("reset") ) {
$d->reset;
+ return $d;
} else {
die "Can't clone or reset digest object: $d";
}
} else {
- $d = Digest->new($d || "SHA1", @args);
+ return Digest->new($d || "SHA1", @args);
}
-
- {
- local $Storable::canonical = 1;
- $d->add( Storable::nfreeze($collapsed) );
- }
-
- return $d->hexdigest;
}
-
1;
__END__
our $VERSION = '0.01';
sub pack {
- my $self = shift;
+ my ( $self, @args ) = @_;
my $e = MooseX::Storage::Engine->new( object => $self );
- $e->collapse_object;
+ $e->collapse_object(@args);
}
sub unpack {
- my ( $class, $data ) = @_;
+ my ( $class, $data, @args ) = @_;
my $e = MooseX::Storage::Engine->new( class => $class );
- $class->new( $e->expand_object($data) );
+ $class->new( $e->expand_object($data, @args) );
}
1;
## this is the API used by other modules ...
sub collapse_object {
- my $self = shift;
+ my ( $self, @args ) = @_;
# NOTE:
# mark the root object as seen ...
);
isa_ok( $foo, 'Foo' );
- my $frozen1 = $foo->freeze( "HMAC_SHA1", "secret" );
+ my $frozen1 = $foo->freeze( digest => [ "HMAC_SHA1", "secret" ] );
ok( length($frozen1), "got frozen data" );
my $d2 = Digest::HMAC_SHA1->new("s3cr3t");
- my $frozen2 = $foo->freeze( $d2 );
+ my $frozen2 = $foo->freeze( digest => $d2 );
ok( length($frozen2), "got frozen data" );
cmp_ok( $frozen1, "ne", $frozen2, "versions are different" );
- my $foo1 = eval { Foo->thaw( $frozen1, "HMAC_SHA1", "secret" ) };
+ my $foo1 = eval { Foo->thaw( $frozen1, digest => [ "HMAC_SHA1", "secret" ] ) };
my $e = $@;
ok( $foo1, "thawed" );
ok( !$e, "no error" ) || diag $e;
- my $foo2 = eval { Foo->thaw( $frozen2, $d2 ) };
+ my $foo2 = eval { Foo->thaw( $frozen2, digest => $d2 ) };
$e = $@;
ok( $foo2, "thawed" );
ok( !$e, "no error" ) || diag $e;
- $foo1 = eval { Foo->thaw( $frozen1, $d2 ) };
+ $foo1 = eval { Foo->thaw( $frozen1, digest => $d2 ) };
$e = $@;
ok( !$foo1, "not thawed" );
$frozen1 =~ s/foo/bar/;
- $foo1 = eval { Foo->thaw( $frozen1, "HMAC_SHA1", "secret" ) };
+ $foo1 = eval { Foo->thaw( $frozen1, digest => [ "HMAC_SHA1", "secret" ] ) };
$e = $@;
ok( !$foo1, "not thawed" );