Subject: | Test::Builder::is_eq() doesn't handle stringification overload edge case |
Perl 5.8.8
Test-Simple 0.62
Linux 2.6.16
According to the overload.pm doc:
'The table of methods for all operations is cached in magic for the
symbol table hash for the package. The cache is invalidated during
processing of "use overload", "no overload", new function definitions,
and changes in @ISA. However, this invalidation remains unprocessed
until the next bless"ing into the package. Hence if you want to change
overloading structure dynamically, you'll need an additional (fake)
"bless"ing to update the table.'
Test::Build::is_eq digs into the internal overload table (via
overload::Method) to get the stringification method and calls it
directly. In the rare case that the package symbol table has not been
updated (as described above), this can cause a test to pass even when
stringification is not working correctly.
The attached files demonstrate this.
Admittedly this is a rare case, but its not hypothetical -
Class-Constant-0.03 needs to work around this in t/values.t to make the
tests pass (indeed, earlier versions were actually broken due to this).
Subject: | thunk.pl |
#!/usr/bin/perl
use warnings;
use strict;
use lib '.';
use thunk;
use Test::More "no_plan";
is(thunk::object::value, "thunk! thats an object!");
my $x = "".$thunk::object::value;
is($x, "thunk! thats an object!");
Subject: | thunk.pm |
package thunk;
use warnings;
use strict;
sub import {
my $value = bless \do { my $x }, "thunk::object";
*thunk::object::value = sub { $value };
unshift @thunk::object::ISA, "thunk::value";
}
package thunk::value;
use overload q{""} => sub { "thunk! thats an object!" };
1;