问题
Related to the topic Perl: Force stacktrace for "can't call method on undefined" I have the following followup question:
I'm using Perl and Catalyst as Web-Framework and I want to get a stacktrace for ANY exception (for some there are already stacktraces but not for all, see linked question).
As suggested in the linked question, the solution is to insert use Carp::Always;
"somehwere in the code".
Inserting use Carp::Always;
in the Catalyst main package file MyApp.pm
(where all the initialization is located) or in any other .pm file has no effect.
But putting it into the scripts/myapp_server.pl
prints the desired stacktrace if an exception occurs.
Why do I have to put use Carp::Always;
into the myapp_sever.pl file and why isn't it working if I put it into MyApp.pm?
Putting it into _server.pl
is not the best solution because then I have to define it additionally in the mod_perl config (PerlModule Carp::Always
)
when using apache to deliver the page.
EDIT: I also tried with a freshly created Catalyst app:
- Create a new app:
catalyst.pl ExTest
- Add
use Carp::Always;
tolib/ExTest.pm
(very first line) - Add the example
sub test ...
from Perl: Force stacktrace for "can't call method on undefined" tolib/Controller/Root.pm
right before1;
(last line) - Call
perl Makefile.PL && make
- Start the server
perl scripts/extest_server.pl
Open
http://localhost:3000/test
The full stacktrace is missing...
Now try the following:
- Remove previously added
use Carp::Always
- Add
use Carp::Always;
toscript/extest_server.pl
(second line) Open
http://localhost:3000/test
Now there is a full stacktrace
My Catalyst version is: 5.90041
Perl Version: 5.10.1 (I know it's old but there are no official releases for Ubuntu 10.04 Server)
May it be related to the Perl version?
来源:https://stackoverflow.com/questions/17661617/perl-carpalways-not-working-in-catalyst-myapp-pm