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

I want to set -no_undef_params in CGI::Application.

In a CGI program it would be something like;
use CGI qw/-no_undef_params/;

in C::A I need to say my package isa C::A. I do that like so;
use base CGI::Application;

However
use base CGI::Application -no_undef_params;
does not seem to work, (nor any other permutation I could think of).
I was just wondering what the right syntax would be?

Oh.. while I'm here.
Is there any way I could import the HTML shortcuts into my C::A namespace, so as not to have to use the OO style.
I want to be able to say td(foo) instead of $q->td(foo)

I should mention this is all in a mod_perl handler.

Replies are listed 'Best First'.
Re: CGI::Application and CGI pragmas?
by cees (Curate) on May 27, 2005 at 22:55 UTC

    did you try just putting in both those statements?

    use CGI qw/-no_undef_params/; use base CGI::Application;

    If you want to import all the HTML shortcuts, just add them to the use CGI statement.

    use CGI qw/-no_undef_params :standard/;

    Since you mention that this is in a mod_perl environment, you should note that the -no_undef_params option may cause all your programs running under mod_perl that use CGI to have that option turned on regradless of how they load CGI.pm. CGI.pm handles these things in Global variables.

      Yeah, I tried that but it seems to step on some mod_perl stuff?

      I get an error message like;
      Can't locate object method "server" via package "request" (perhaps you forgot to load "request"?)
      on some code that looks something like;

      my $r = $self->param('request'); $r->server->loglevel(VERBOSE);
      This code works before importing :standard
      If I just do the pragma nothing seems to happen, i.e. its ignored

        OK, that helps a bit. Are you sure you are getting a proper request object when you call $self->param('request')? It would help if you showed us the code that populates that parameter.

        What I would try instead is call Apache->request->server->loglevel(VERBOSE) and see what that does. If that works, then your problem is with the 'request' parameter you set in CGI::Application. Try dumping that variable using Data::Dumper and you will see exactly what you have there.