CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: mod_perl: What package is the main script in?: Edit Log


Aug 16, 2003, 5:04 PM

Views: 23002
What package is the main script in?

Hi Folks,

Does anyone know what the package name is for a script running under Apache::Registry? I'm trying to access a subroutine in a custom perl module I've written.

In simple terms, here's what I'm doing:

Main Script
our %G;
$G{'dirs'}{'template'} = '/home/username/safe/templates/';
use Custom::Common; # contains sub Error
use Custom::Template; # contains sub Load_Template

my %args = (template => 'template_filename.html');
my $template;
unless($template = &Load_Template(\%args)) {
# print error message here

package Custom::Template
sub Load_Template {
my $arg_ref = shift;

# test access to template file
my $file = $main::G{'dirs'}{'template'} . $arg_ref->{'template'};
unless (-e $file) {
&main::Error({ msg => "Load_Template: requested template file ($file) does not exist.",
actions => 'collect_all log_msg email_developer' });
return 0;

What's happening is that the reference to main:: isn't correct, so the path to $file is not correct. Since the path is not correct, the -e file test returns false. The call to &main::Error is unable to find sub Error and leaves this message in the error log: "Undefined subroutine &main::Error called at /home/username/safe/pm/Custom/ line 32"

sub Error is exported into package main properly, and this system works fine when run as a CGI script.

I'm guessing that the problem is the reference to main::, when in fact it's probably the Apache handler subroutine which is in main and my "main" script is in some other package. Any suggestions? Thanks.

>> If you can't control it, improve it, correlate it or disseminate it with PERL, it doesn't exist!

(This post was edited by kencl on Aug 16, 2003, 5:50 PM)

Edit Log:
Post edited by kencl (User) on Aug 16, 2003, 5:26 PM
Post edited by kencl (User) on Aug 16, 2003, 5:29 PM
Post edited by kencl (User) on Aug 16, 2003, 5:30 PM
Post edited by kencl (User) on Aug 16, 2003, 5:50 PM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives