use warnings; use strict; use Test::More tests=>7; use Digest::MD5; use Class::Method::Modifiers; my $cnt = 0; before 'Digest::MD5::hexdigest' => sub { $cnt++ }; my $d1 = Digest::MD5->new; $d1->add("1"); $d1->add("1"); is $d1->hexdigest, "6512bd43d9caa6e02c990b0a82652dca"; is $d1->hexdigest, "d41d8cd98f00b204e9800998ecf8427e"; is $cnt, 2; use Memoize; memoize('Digest::MD5::add'); memoize('Digest::MD5::hexdigest'); # the *exact same* tests as above! my $d2 = Digest::MD5->new; $d2->add("1"); $d2->add("1"); # now we get the MD5 sum of "1" instead of "11" is $d2->hexdigest, "6512bd43d9caa6e02c990b0a82652dca"; # hexdigest should reset the state of the object is $d2->hexdigest, "d41d8cd98f00b204e9800998ecf8427e"; $cnt = 0; my $d3 = Digest::MD5->new; # "hexdigest" was memoized above, so should we get the MD5 sum of # "" or of "1"? Also, should $cnt be incremented or not? is $d3->hexdigest, "c4ca4238a0b923820dcc509a6f75849b"; is $cnt, 0; __END__ 1..7 ok 1 ok 2 ok 3 not ok 4 # Failed test at m.pl line 27. # got: 'c4ca4238a0b923820dcc509a6f75849b' # expected: '6512bd43d9caa6e02c990b0a82652dca' not ok 5 # Failed test at m.pl line 29. # got: 'c4ca4238a0b923820dcc509a6f75849b' # expected: 'd41d8cd98f00b204e9800998ecf8427e' not ok 6 # Failed test at m.pl line 35. # got: 'd41d8cd98f00b204e9800998ecf8427e' # expected: 'c4ca4238a0b923820dcc509a6f75849b' not ok 7 # Failed test at m.pl line 36. # got: '1' # expected: '0' # Looks like you failed 4 tests of 7.