Hello,
Apologies for answering only now, but I'll take the organisation of
FPW2005 as an excuse :-)
You wrote:
Show quoted text> using Devel::SimpleTrace stops some tests from working.
>
> If your test expects an exception thrown, and test for the result it
> will likely fail with Devel::SimpleTrace.
>
> This is as $@ is replaced by a text including the callstack.
>
> The problem arises for test like
>
> eval { die "text" };
> ok $@ eq 'text';
Hmm.. That code looks like a red flag to me. I think you should not try
to compare the error message with eq but with a m// to match the
beginning of the string because the actual text may vary from what you
can expect.
And if you are doing this for tests, Test::Warn and Test::Exception are
most certainly better suited for this task.
Show quoted text> or for object or perl data structures beeing thrown.
>
> also watch the following command line scripts
>
> perl -MDevel::SimpleTrace -we ' eval { die { a=>1 }; }; print ref $@; '
>
> perl -we ' eval { die { a=>1 }; }; print ref $@; '
> HASH
I didn't know you could give die() a ref and expect it to actually work.
perldoc confirms me this is a valid and documented usage so I take that
as a bug or caveat of Devel::SimpleTrace.
Show quoted text> Not sure how to Fix, I dont know, why the code is doing anything if
> die occurs in_eval
>
> from sub _do_die :
>
> if($in_eval) {
> $@ = $stderr;
> $stderr = '';
> $in_eval = 0;
> CORE::die $@
> }
IIRC this code is here to avoid some forms of eval() that were causing
Devel::SimpleTrace to produce incorrect traces (I can't remember the
exact details).
Show quoted text> Possible Solutions:
> - do nothing if in_eval
No. The aim of Devel::SimpleTrace is to allow for an easier mean to
trace warnings and errors, even those that are inside eval().
Show quoted text> - do nothing by default, and allow to enable this feature, by passing
> an arg to import:
> use Devel::SimpleTrace 'eval'
> allow several switches, for $@ is plain text, or structure/object
> - do it by default (maybe only for text), and allow to switch on/off
> the rest
Hmm.. I can print the traces as usual when it's plain text and just
return the thing unchanged when it's an object or reference.
But I'd say that I primarily wrote Devel::SimpleTrace in order to ease
interactive debugging sessions, by just adding it to perl switches:
perl -WMDevel::SimpleTrace program_with_hairy_warnings.pl
Of course you can use it permanently with a "use Devel::SimpleTrace",
it's just that I didn't think it would be its typical usage :-)
So I understand the need to preserve the references when seeing them,
but I also see that a mode where Devel::SimpleTrace stringify them
would be very useful. This is what should be the option: stringify
references.
Show quoted text> Also a nice Idea (or has someone a better solution) allow switching
> via $ENV.
>
> if you do "perl -MDevel::SimpleTrace " you cant pass arguments to
> import. So
>
> TRACE_EVAL=0 perl -MDevel::SimpleTrace
> could do the trick.
In fact, you can; for example:
perl -MO=Deparse -le 'print "hello"'
will load the O module, giving it the "Deparse" argument, which will
instruct it to load the B::Deparse module. The generic form is:
perl -MModule=arg1,arg2,arg3
Check perlrun(1) for the details. So no need for environment variable,
although I could also recognize one.
Sébastien Aperghis-Tramoni
-- - --- -- - -- - --- -- - --- -- - --[
http://maddingue.org ]
Close the world, txEn eht nepO