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

hi all, yet another mod_perl/ Apache2 specific question. as you can see from the title of my post, it's about an error message that i get. in my startup.pl there is the line:
use Apache2::Const -compile => qw(:common :http);
and in another module, called Lib.pm (because it contains a bunch of common functions for all 'CGI' pages), the tune goes:
sub decline { # print some stuff Apache2::Const::OK; }
which works absolutely fine. but now, in a 'CGI' script, being executed under ModPerl::Registry, the following lines
$r->headers_out->add('Location' => "/main"); $r->content_type('text/html'); return Apache2::Const::REDIRECT;
produce the above error message. to me that looks like a problem of ModPerl::Registry, but even if it were, i probably hadn't the skills to correct it.

any ideas?
many thx in advance
martin (aka thcsoft)


language is a virus from outer space.

Replies are listed 'Best First'.
Re: Bareword "Apache2::Const::REDIRECT" not allowed while "strict subs" in use
by nerfherder (Monk) on May 03, 2005 at 07:18 UTC
    You may need to add () , like so:
    return Apache2::Const::REDIRECT();
    Good luck!
      hmm... i tried using the ampersand &Apache2... - with the only result, that now i got a runtime-error instead of a compile-time one.

      language is a virus from outer space.

        An ampersand is not the same thing as parens to mark something as a function. An ampersand marks it as being a local subroutine. When you're using something from a module, you'll want to use parens:

        Apache2::Const::REDIRECT()

        You could also import 'REDIRECT', so that perl knows that it's a function, and not a variable or filehandle, or something else.

        Update: see further down in the thread. Still need to confirm exactly what's going on, but I'll place that in the other node.

Re: Bareword "Apache2::Const::REDIRECT" not allowed while "strict subs" in use
by perrin (Chancellor) on May 03, 2005 at 13:15 UTC
    You have to import that constant (which is really a subroutine) in your script before you call it.
      hmm... well, thank you for your replies. i've tried both ways meanwhile, explicitly using
      use Apache2::Const -compile => qw/:common :http/; ... return Apache2::Const::REDIRECT();
      but all that i get is a runtime error:
      Undefined subroutine &Apache2::Const::REDIRECT called
      so i think i'll be better off calling an internal redirect instead - although that behaviour still smells to me like a bug in ModPerl::Registry ...

      thank you again.
      language is a virus from outer space.
        If it's a bug, it's a bug in Apache2::Const. My previous advice about importing was wrong -- what you did should work with the () on the end. Maybe REDIRECT is documented in the wrong group. Can you try listing it explicitly in your compile list, or compiling some different groups?