You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Dave Morgan <dv...@telusplanet.net> on 2002/01/17 05:15:59 UTC

Summary: CGI.pm problems in BEGIN blocks

Hi All,
	Basically comes down to you cannot call the CGI.pm module in a
functional style within a block of code that is loaded at startup by a
mod-perl enabled web server. 

Using CGI.pm in an OOP way eliminates the problem.

#######################################
# this code causes problems with the usage 
# of CGI.pm with mod-perl
package NOGOOD;

require Exporter;
use strict;
use CGI qw/:standard/;

our (@ISA, @EXPORT);
our ($USERID, $PASSWORD, $select_list);

@ISA    = qw(Exporter);
@EXPORT = qw($USERID $PASSWORD $select_list);
          
BEGIN{
        $select_list = scrolling_list(-name=>'TEST',
                                -values=>[1,2,3,4],
                                -default=>'1',
                                -size=> 1);
}
1;
# END

#######################################
# this code WORKS
package GOOD;

require Exporter;
use strict;
use CGI;

our (@ISA, @EXPORT);
our ($USERID, $PASSWORD, $select_list);

@ISA    = qw(Exporter);
@EXPORT = qw($USERID $PASSWORD $select_list);
          
BEGIN{
	my $cgihandler = new CGI;
        $select_list = $cgihandler->scrolling_list(-name=>'TEST',
                                -values=>[1,2,3,4],
                                -default=>'1',
                                -size=> 1);
}
1;
# END

I can't believe no-one else has run in to this. Something
to do with the default instantiation of CGI is my guess.

Thanks to all

Dave
-- 
Dave Morgan
dvmrgn@telusplanet.net
403 399 2442

Re: Summary: CGI.pm problems in BEGIN blocks

Posted by Perrin Harkins <pe...@elem.com>.
> I can't believe no-one else has run in to this. Something
> to do with the default instantiation of CGI is my guess.

It's actually highly unusual to do anything with CGI other than compile
it  inside a BEGIN block.  You may very well be the first person who
ever tried.  Typical usage is to do initialization at the start of each
request, since CGI is all about the current request context.
- Perrin