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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



kencl
User

Aug 16, 2003, 5:04 PM

Post #1 of 4 (13331 views)
What package is the main script in? Can't Post

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/Template.pm 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)


Paul
Enthusiast

Aug 20, 2003, 5:29 PM

Post #2 of 4 (13320 views)
Re: [kencl] What package is the main script in? [In reply to] Can't Post

It's not really a mod_perl issue, it's basic modulation issues.

You aren't specifying the class name. Instead of:

Load_Template(\%blah) you need:

Custom::Template::Load_Template(\%blah)

...then it will find the right routine. You only leave the class name out if you are importing the routine into your script, eg...

use Custom::Template qw/Load_Template/;


(This post was edited by Paul on Aug 20, 2003, 5:30 PM)


kencl
User

Aug 21, 2003, 2:24 PM

Post #3 of 4 (13314 views)
Re: [Paul] What package is the main script in? [In reply to] Can't Post

sub Load_Template is imported into the "main" script properly via use Custom::Template. It doesn't need to be explicitely imported as it is part of the default export list.

I have determined the name of the script's package. It is:
Apache::ROOTwww_2edomain_2enet::cgi_2dbin::dev::test_2empl::handler

Since this contains the script name, I cannot use it within my packages. A new strategy for creating a global variable which is accessable within imported packages is required.

I'll keep working on it and post my result here for the benefit of others who may be interested in how to accomplish this.


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


kencl
User

Dec 16, 2006, 2:32 PM

Post #4 of 4 (8929 views)
Re: [kencl] What package is the main script in? [In reply to] Can't Post

My solution was to explicitely name the package of my "main" script.

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

 
 


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

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