You make a lovely teddy bear

David Cantrell david at cantrell.org.uk
Thu Mar 27 16:37:35 GMT 2014


I've been hunting down a really weird bug since yesterday morning.

I have a little utility method 'throw' that is basically a wrapper
around 'die', except that if you supply random text instead of an
exception object it reifies it, and that it also uses Devel::StackTrace
to stuff a stacktrace in to it as well.

I was getting errors about how Devel::StackTrace was trying to call a
method 'blessed' on an unblessed reference at line 80:
  https://metacpan.org/source/DROLSKY/Devel-StackTrace-1.31/lib/Devel/StackTrace.pm#L80

The 'blessed' function is quite clearly imported at the top of the file.
And then when I started splattering prints to STDERR and Data::Dumper
all over my code that just moaned about Dumper not existing and I got
very confused. So I started writing this to you all:

> I have this in a function (yeah yeah, obviously the 'use' happens at
> compile-time):
> 
>   use Data::Dumper;local $Data::Dumper::Indent=1;
>   print STDERR Dumper(\@_);
> 
> and I get out ...
> 
>   Undefined subroutine &My::Module::Dumper called at ...
> 
> But it DTRT if I call Data::Dumper::Dumper.
> 
> What on earth could I have done that would prevent Data::Dumper's
> import() method from working?

Naturally, when whining at other people to do my homework for me I
wanted to reduce the problem to the smallest possible example. And in
doing so I found this, in the import() method of the module that was
loading my module:

  sub import {
      [page of weirdness]

  --> local $Exporter::ExportLevel = 1; <--

      [page of weirdness]

      require My::Module;
      My::Module->import();
  }
      
Naturally, the loopy-juice that messes with Exporter's guts is still in
effect later on - it has been insufficiently local()ized.

So I'd like to thank you all for being my teddy bear:
  http://cm.bell-labs.com/cm/cs/tpop/debugging.html

-- 
David Cantrell | Enforcer, South London Linguistic Massive

    Planckton: n, the smallest possible living thing


More information about the london.pm mailing list