David Golden wrote:
> On Tue, Sep 9, 2008 at 6:10 PM, Michael G Schwern <[EMAIL PROTECTED]> wrote:
>> Taking a knife to CORE::caller() and then calling someone else's functions 
>> and
>> expecting them to work is not a good idea.
> 
> The problem is that we want Sub::Uplevel to do what people expect if
> they have already taken a knife to CORE::caller for some stupid
> reason, since nothing in Perl stops them from doing so.

Indeed, but that doesn't mean you need to wave a knife around in your tests.
It can be simulated just fine with a working caller() that increments a 
variable.


>> After some poking around, the test fails because "use vars" depends on
>> caller() and caller() is bleeding on the floor.  It used to work because
>> Test::More happened to load vars.pm before caller() got the knife.  Now it
>> doesn't, it uses our().
> 
> Looks like this is fixable in Sub::Uplevel just by avoiding vars.
> Since Schwern has declared 5.005 dead and the toolchain is moving on,
> I'll convert to "our" as well and make 5.006 a requirement.

[Slow motion leap towards the time bomb] Noooooooooooooooo!!!!!

With caller() broken, anything that Sub::Uplevel uses which depends on it
working may fail.  This includes core dependencies, like Exporter which works
here only because Test::More loads it before caller() gets scrambled.  It's a
matter of time before some dependency changes what loads again and the test 
fails.

You can see it all go wrong again by cutting out Test::More.

$ cat ~/tmp/bug.plx
sub _reverse_caller(;$) {
    my $height = $_[0];
    my @caller = CORE::caller(++$height);
    $caller[0] = reverse $caller[0];
    if( wantarray and [EMAIL PROTECTED] ) {
        return @caller[0..2];
    }
    elsif (wantarray) {
        return @caller;
    }
    else {
        return $caller[0];
    }
}

BEGIN {
    my $old_W = $^W;
    $^W = 0;
    *CORE::GLOBAL::caller = \&_reverse_caller;
    $^W = $old_W;
}

use Sub::Uplevel;
uplevel(0, sub { print caller });

$ perl -Ilib ~/tmp/bug.plx
Undefined subroutine &main::uplevel called at /Users/schwern/tmp/bug.plx line 
26.


And that's after I replaced all the uses of vars.pm with our().


-- 
I do have a cause though. It's obscenity. I'm for it.
    - Tom Lehrer

Reply via email to