in reply to CGI::Carp reports line numbers incorrectly
Here are a few tests that I found interesting, and which give results that are in some ways inconsistant with documentation.
use strict; use warnings; use CGI::Carp; eval { die "Ouch. 1" }; print $@, "\n" if $@; eval { die "Ouch. 2\n" }; print $@, "\n" if $@; eval { CORE::die "Ouch. 3" }; print $@, "\n" if $@; eval { CORE::die "Ouch 4.\n" }; print $@, "\n" if $@; __Output__ Ouch. 1 at C:/Perl/lib/CGI/Carp.pm line 312. Ouch. 2 Ouch. 3 at C:\Perl\scripts\mytest.pl line 14. Ouch. 4
And now the same tests but with Carp.pm (not CGI::Carp)...
use strict; use warnings; use Carp; eval { die "Ouch. 1" }; print $@, "\n" if $@; eval { die "Ouch. 2\n" }; print $@, "\n" if $@; eval { CORE::die "Ouch. 3" }; print $@, "\n" if $@; eval { CORE::die "Ouch 4.\n" }; print $@, "\n" if $@; __OUTPUT__ Ouch. 1 at C:\Perl\scripts\mytest.pl line 8. Ouch. 2 Ouch. 3 at C:\Perl\scripts\mytest.pl line 14. Ouch. 4
Clearly Carp.pm's output is what we want. And CGI::Carp's output is improper. This bug appears only in scripts that are evaled. mod_perl scripts are eval'ed too, so the problem shows up there too. The POD for CGI::Carp says that CGI::Carp is a CGI-friendly equivilant to Carp. But it turns out that CGI::Carp is not as good as Carp at reporting the correct line numbers. I would consider this a bug.
As for why a "\n" character in the die string suppresses the printing of line numbers, that's a mystery for which I can't find any documentation anywhere.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: CGI::Carp peculiarity
by shenme (Priest) on Dec 27, 2003 at 18:14 UTC |