Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Mixing Carp and CGI::Carp

by knowmad (Monk)
on Oct 17, 2003 at 21:36 UTC ( [id://300177]=perlquestion: print w/replies, xml ) Need Help??

knowmad has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I've sought high and low for an answer to my predicament. I am running several scripts on a mod_perl server. Both Carp and CGI::Carp are being loaded. In one of my modules (Petal), code is evaluated inside of a Safe compartment. When calling confess inside of this compartment, I get the following fatal error from CGI::Carp:

Can't locate object method "splitpath" via package "File::Spec" (perhaps you forgot to load "File::Spec"?) at /usr/share/perl/5.6.1/CGI/Carp.pm line 317.

I wrote a test that proves this is only an issue with Safe and CGI::Carp (which is the topic for another discussion). For a quick workaround, I was hoping to find a way to tell my code being evaluated to use Carp::confess instead of using CGI::Carp. I can't convince it to do that. Is there a way to tell Perl which module to use for a method that is defined in more than one module?

Thanks!
William

Replies are listed 'Best First'.
Re: Mixing Carp and CGI::Carp
by chromatic (Archbishop) on Oct 17, 2003 at 23:12 UTC

    What happens when you call Carp::confess() explicitly?

      Actually, a bit further evaluation seems to indicate the problem is coming from either die() or warn(), which in turn call id() which causes the splitpath error. However, looking at confess(), it's just a wrapper for calling die so it may be in there. Since there were several instances of confess being called, I added the following subroutine to the package where I think the error may be coming:

      sub confess { Carp::confess @_ }

      Still got the splitpath error from CGI::Carp. I then manually switched confess to Carp::confess. Still no dice. I'm not entirely sure where this warning is being called from since the code being eval'ed includes objects from several other packages. I've tried adding use Carp; to all the relevant packages, but CGI::Carp continues to be called. I've tried tracking down the error in the debugger, but I can't seem to track into the eval. I'm guessing that's not possible via the debugger.

      I'm in the process of running other tests to try to track down where the warn/die is being called. Unfortunately, I'm having a hard time repeating the error in slimmed-down versions of my code. The crux of the problem seems to be that CGI::Carp does not work inside of Safe. I need to send a bug report to Lincoln.

      Thanks for your input,
      William

Re: Mixing Carp and CGI::Carp
by Anonymous Monk on Oct 17, 2003 at 22:48 UTC
    Why are you mixing Carp with CGI::Carp? Nevermind, just don't do it.

      As I said in my original message, the code in question is running in mod_perl. Lots of packages get loaded. Some load Carp, some load CGI::Carp. Thus, I have both in my module hierarchy.

      The real issue is that CGI::Carp is not cooperating inside of a Safe environment.

      .

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://300177]
Approved by BazB
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2024-04-23 13:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found