Desilets, Alain wrote:
Trying to migrate a complex script from a standard CGI context to a mod_perl 
context, and am having a hell of a time. The latest problem is that I have a call 
to GCI::Utils->getSelfRefUrlWithQuery() which causes a crash.

In an attempt to isolate the problem, I wrote this short script which does 
nothing more than call that method:

--------------
#!perl -w
use strict;
print "Content-type: text/plain\r\n\r\n";
use CGI::Utils;
my $self_url = '';
print "Before calling get_self_ref_url_with_query()\n";
#no strict;
my $cgi_utils = CGI::Utils->new();
$self_url = $cgi_utils->getSelfRefUrlWithQuery();
#$self_url = $cgi_utils->get_self_ref_url_with_query();
#$self_url = CGI::Utils->getSelfRefUrlWithQuery();
#$self_url = CGI::Utils->getSelfRefUrlWithQuery();
#use strict;
---------------

When I run it, I get the following error:

[Thu Dec 01 17:04:21 2011] [error] Can't use string ("HTML::Mason::Commands::m") as a 
SCALAR ref while "strict refs" in use at C:/Perl/site/lib/CGI/Utils.pm line 203.\n

If I comment out the call to getSelfRefUrlWithQuery(), then the script runs 
fine.

I have tried calling that method in four different ways (as CGI::Utils-> or 
$cgi_utils->, with the underscore or hungarian notation variants), with or without 
'no strict'. All of those combinations fail.

I tried running this script as a ModPerl::Registry or a ModPerl::PerlRun mode, 
and neither ones work.

Is getSelfUrlWithQuery() a method that can't be used in a mod_perl context? If 
so, how can I get the URL fo the current script call?


I have no idea about the error above, but
staying with CGI::Utils, you may also want to try passing the request object directly to CGI::Utils->new, as follows :

my $r = shift;
my $params = { 'apache_request' => $r };
my $cgi_utils = CGI::Utils->new( $params );

and see if that works better.

You may also want to have a look at this, to replace that particular function with the equivalent one from CGI.pm :
http://search.cpan.org/~markstos/CGI.pm-3.58/lib/CGI.pm#CREATING_A_SELF-REFERENCING_URL_THAT_PRESERVES_STATE_INFORMATION:
(and the next one). In other words, try this :

#!perl -w
use strict;
print "Content-type: text/plain\r\n\r\n";
use CGI;
my $cgi = CGI->new();
my $self_url = $cgi->url(-path_info=>1,-query=>1);

The CGI.pm module "knows" that it is running under mod_perl, and will automatically retrieve the Apache::RequestRec object.


Later, also have a look at this :
http://httpd.apache.org/apreq/docs/libapreq2/
(which is an Apache add-on module which provides much of the functionality of CGI.pm, and in a mod_perl context, probably more efficiently).

I do not remember on which platform you are working, but on my Linux Debian platforms, installing it is as easy as :
apt-get install libapache2-mod-apreq2

Reply via email to