Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

mt-spamlookup.cgi displays errors running under mod_perl

by madtoperl (Friar)
on Apr 11, 2006 at 08:56 UTC ( #542486=perlquestion: print w/replies, xml ) Need Help??

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

System specs:
MT 3.16
Windows XP br> ActivePerl 5.8.3 (build 809)
Apache 1.3.33 (Win32)
mod_perl 1.29_01-dev
I have configured my PC to run MT 3.16 under mod_perl using Apache::Registry.
The following errors are alternately displayed each time I browse to mt-nofollow.cgi:

***** Error 1

An error occurred: Error opening file 'mt.cfg': No such file or directory

***** Error 2

Can't load error template; got error 'Loading template 'error.tmpl' failed:
HTML::Template->new() : Cannot open included file error.tmpl : file not found. at c:/Perl/site/lib/HTML/ line 1616
HTML::Template::_init_template('HTML::Template=HASH(0x4b12fa4)') called at c:/Perl/site/lib/HTML/ line 1189
HTML::Template::_init('HTML::Template=HASH(0x4b12fa4)') called at c:/Perl/site/lib/HTML/ line 1083
HTML::Template::new('HTML::Template','type','filename','source','error.tmpl','path','ARRAY(0x4955708)','search_path_on_include',1,...) called at c:/apache/cgi-bin/mt3/lib/MT/ line 460
eval {...} called at c:/apache/cgi-bin/mt3/lib/MT/ line 459
MT::App::load_tmpl('MT::App::SpamLookup=HASH(0x4ac1b2c)','error.tmpl') called at c:/apache/cgi-bin/mt3/lib/MT/ line 295
MT::App::show_error('MT::App::SpamLookup=HASH(0x4ac1b2c)','') called at c:/apache/cgi-bin/mt3/lib/MT/ line 376
MT::App::run('MT::App::SpamLookup=HASH(0x4ac1b2c)') called at c:/apache/cgi-bin/mt3/plugins/spamlookup/mt-spamlookup.cgi line 895
eval {...} called at c:/apache/cgi-bin/mt3/plugins/spamlookup/mt-spamlookup.cgi line 889
Apache::ROOT::cgi_2dbin::mt3::plugins::spamlookup::mt_2dspamlookup_2ecgi::handler('Apache=SCALAR(0x4b12f98)') called at c:/Perl/site/lib/Apache/ line 149
eval {...} called at c:/Perl/site/lib/Apache/ line 149
Apache::Registry::handler('Apache=SCALAR(0x4b12f98)') called at nul line 0
eval {...} called at nul line 0 '. Giving up. Original error was
Can't call method "parse" on an undefined value at c:/apache/cgi-bin/mt3/lib/MT/ line 314.

***** I believe there are 2 issues with the code in mt-nofollow.cgi which cause the above errors and prevent mt-spamlookup.cgi from working under mod_perl:
1) The code that determines the location of the MT directory ($MT_DIR) then adds MT's lib and extlib directories to @INC (lines 14-37) should be enclosed within a BEGIN block, like what is used in MT's cgi scripts.
2) At line 18 in mt-spamlookup.cgi, the code begins to determine the MT directory by evaluating $ENV{PWD}. When not running under mod_perl, $ENV{PWD} does not return any value on my machine (PWD is not set?), and the subsequent lines of code use other means to properly identify my MT directory.
However, when running under mod_perl, $ENV{PWD} returns the path to my Apache directory (c:/apache). Even though MT is not installed in my c:/apache directory, the subsequent lines of code only check whether the path is an absolute path (which c:/apache is). The directory where MT is installed is thus never properly determined,
I've commented out line 18 in my copy of mt-spamlookup.cgi - both dirname($0) and dirname($ENV{SCRIPT_FILENAME}) return the correct path to my MT installation (c:/apache/cgi-bin/mt3). If checking $ENV{PWD} is necessary, it appears to me that it should not be looked at first to determine the MT directory, or the path returned should be subjected to more testing before accepting it as the MT directory.
I had a minor question about lines 33-34 in mt-nofollow.cgi:

$PLUGIN_DIR = $MT_DIR;<br> ($MT_DIR, $PLUGIN_ENVELOPE) = $MT_DIR =~ m|(.*[\\/])(plugins[\\/].*)$| +i;<br> The sltool script included with SpamLookup seems to use more robust co +de: <br><br> if ($MT_DIR =~ m!plugins[\\/]!) {<br> $PLUGIN_DIR = $MT_DIR;<br> ($MT_DIR, $PLUGIN_ENVELOPE) = $MT_DIR =~ m|(.*[\\/])(plugins[\\/]. +*)?$|i;<br> }<br> $MT_DIR .= '/' unless $MT_DIR =~ m![\\/]$!;<br>
I have replaced lines 33-34 in mt-spamlookup.cgi with the above code, but I don't know if it is really better, or if it's not really necessary.

2006-10-08 Unapproved by planetscape once evidence of habitual plagiarism uncovered.

Considered by hossman: plagarism
Unconsidered by planetscape: keep (and edit) votes prevented reaping ( keep:4 edit:7 reap:20 )

Replies are listed 'Best First'.
Re: mt-spamlookup.cgi displays errors running under mod_perl
by hossman (Prior) on Oct 08, 2006 at 20:33 UTC
Re: mt-spamlookup.cgi displays errors running under mod_perl
by astaines (Curate) on Apr 11, 2006 at 15:12 UTC

    What is MT? What is it meant to do? A fairly common problem in debugging Perl is that one initial error generates a cascade of error messages. This may be happening here. Does the error.tmpl file exist?

    Also try using more code blocks around the computer output - it renders better in Firefox (and probably IE) if you do.

    -- Anthony Staines

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://542486]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2020-09-28 09:25 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (143 votes). Check out past polls.