Re: cgi.pm does not work in handlers (why responsehandlers at all ?)

2003-04-02 Thread pilsl
thnx for your reply.
 
I use mod_perl 2 (1.99_08) and CGI.pm 2.91 and Apache 2.0.44.  I thought that CGI.pm
wouldnt work at all, so I didnt give any examples.
 
I wrote a simply script that checks if running under mod_perl,
displays some parameter and evaluates/presents a form.
 
This script (source below) I implement as simple mod_perl-script one time and as
PerlResponseHandler the other time. As sole mod_perl-script it works
perfect, while as Handler:

*  it fails to read the path_info and the CGI-params.

* The startform-method needs an explicit action-argument or it will post
the form to the (nonexisting) url '/e'. 

* The cgi-header() method causes an error.  Can't call method
send_cgi_header on an undefined value at (eval 6) line 60.. 

* And I cant just print out but need to use the $r-print-method.

So my conclusion was/is that CGI.pm does just not work inside an apache-handle.



For the docs of mod_perl-handlers I read perl.apache.org, but I
couldnt find any tutorials about writing handlers in
mod_perl. Especially a description about the methodes and values of
the responsehandler-object. 

thnx a lot, peter


the source:



  
A) the handler


accessed via http://localhost/time

 
apache-config
PerlModule goldfisch::apache::random
  Location /time
  SetHandler modperl
  PerlResponseHandler goldfisch::apache::random
  /Location



package goldfisch::apache::random;

use 5.008;
use strict;
use warnings;
use Apache::RequestRec ();
use Apache::RequestIO ();
use Apache::Const -compile = qw(OK);
use CGI;

sub handler {
  my $r = shift;
  $r-content_type('text/html');

  my $q=new CGI;
  my $html='';
#  $html.=$q-header(-charset='utf-8',-expires='now');
  $html.='!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 
Transitional//ENHTMLHEADtitletestgoldfisch/title/HEAD';
  $html.=GOLDFISCH.int(rand(1000)).br;
  my $mp='no'; $mp=$ENV{MOD_PERL} if(exists $ENV{MOD_PERL});
  $html.=running under modperl : .$mp.br\n;

  $html.='parameters delivered to the script : br';
  my @k=$q-param; foreach(@k) { $html.=$_ = .$q-param($_).br\n;}
  $html.='--br';

  $html.=path_info CGI = .$q-path_info().br\n;
  $html.=path_info handler = .$r-path_info().br\n;

  $html.='brbr';
  
$html.=$q-startform(-action='/time').$q-textfield(-name='test',-size=50).$q-submit(-value='press').$q-endform();$q-end_html;
 
  
  $r-print($html);
  return Apache::OK;
}

1;



B) the mod_perl-script:

accessed via http://localhost/random


Alias /random /home/htdocs/perl/random.pl
Files ~ \.pl$ 
  SetHandler perl-script
  PerlResponseHandler ModPerl::Registry
  Options +ExecCGI
/Files



#!/usr/bin/perl -w
# mod_perl

use strict;
use warnings;
use CGI;

my $q=new CGI;
my $html='';
$html.=$q-header(-charset='utf-8',-expires='now');
$html.='!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 
Transitional//ENHTMLHEADtitletestgoldfisch/title/HEAD';
$html.=GOLDFISCH.int(rand(1000)).br;
my $mp='no'; $mp=$ENV{MOD_PERL} if(exists $ENV{MOD_PERL});
$html.=running under modperl : .$mp.br\n;

$html.='parameters delivered to the script : br';
my @k=$q-param; foreach(@k) { $html.=$_ = .$q-param($_).br\n;}
$html.='--br';

$html.=path_info CGI = .$q-path_info().br\n;
$html.=path_info handler = .$r-path_info().br\n;

$html.='brbr';
$html.=$q-startform(-action).$q-textfield(-name='test',-size=50).$q-submit(-value='press').$q-endform();$q-end_html;
 

print $html;






ps : sorry for this long posting,




On Wed, Apr 02, 2003 at 09:10:17AM +1000, Stas Bekman wrote:
 [EMAIL PROTECTED] wrote:
 
 I used CGI.pm in my mod_perl-application to get 'path_info', 'param',
 print out headers and more.
 None of this works inside my own handlers any more.
 
 Which mod_perl generation are you using? mod_perl 1.0 (1.27?) or mod_perl 
 2.0 (1.99_08?). I suspect that you use mp2, since you mention later 
 ResponseHandler, which doesn't exist in mp1. If that's the case, are you 
 using the latest CGI.pm version? (older versions are known not malfunction 
 with mp2).
 
 If after getting the latest versions you still have problems, please post a 
 *simple* several lines handler/script which doesn't work for you. Asking 
 *why* CGI.pm doesn't work, is similar to asking why my car doesn't move 
 from its place ;) You have to be more specific and then we will be able to 
 figure out, what the problem is.
 
 - whats the maineffect of a simple ResponseHandler at all compared
 with a perl-program run under mod_perl ? Is it much faster, cause it
 handles things more efficiently ? By now I used to use an
 Alias-Directive in apache to direct certains requests to a single
 perl-script and use path_info() to detect the additional
 arguments. For the use there is no difference at all.
 
 If you are talking about perl-scripts running under Apache::Registry or 
 Apache::PerlRun, you are in fact running response handlers. The scripts are 
 converted to such behind the scenes. In addition registry scripts do a few 
 more things, which slow things down just a tiny-bit, probably 

Re: cgi.pm does not work in handlers (why responsehandlers at all?)

2003-04-02 Thread Stas Bekman
[EMAIL PROTECTED] wrote:
thnx for your reply.
 
I use mod_perl 2 (1.99_08) and CGI.pm 2.91 and Apache 2.0.44.  I thought that CGI.pm
wouldnt work at all, so I didnt give any examples.
 
I wrote a simply script that checks if running under mod_perl,
displays some parameter and evaluates/presents a form.
 
This script (source below) I implement as simple mod_perl-script one time and as
PerlResponseHandler the other time. As sole mod_perl-script it works
perfect, while as Handler:
[...]
apache-config
PerlModule goldfisch::apache::random
  Location /time
  SetHandler modperl
This is your problem. CGI.pm relies on things like Apache-request and env 
vars, neither of which is available under 'SetHandler modperl'. Change it to 
'SetHandler perl-script' and read:
http://perl.apache.org/docs/2.0/user/config/config.html#C_SetHandler_



__
Stas BekmanJAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide --- http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: cgi.pm does not work in handlers (why responsehandlers at all?)

2003-04-01 Thread Stas Bekman
[EMAIL PROTECTED] wrote:

I used CGI.pm in my mod_perl-application to get 'path_info', 'param',
print out headers and more.
None of this works inside my own handlers any more.
Which mod_perl generation are you using? mod_perl 1.0 (1.27?) or mod_perl 2.0 
(1.99_08?). I suspect that you use mp2, since you mention later 
ResponseHandler, which doesn't exist in mp1. If that's the case, are you using 
the latest CGI.pm version? (older versions are known not malfunction with mp2).

If after getting the latest versions you still have problems, please post a 
*simple* several lines handler/script which doesn't work for you. Asking *why* 
CGI.pm doesn't work, is similar to asking why my car doesn't move from its 
place ;) You have to be more specific and then we will be able to figure out, 
what the problem is.

- whats the maineffect of a simple ResponseHandler at all compared
with a perl-program run under mod_perl ? Is it much faster, cause it
handles things more efficiently ? By now I used to use an
Alias-Directive in apache to direct certains requests to a single
perl-script and use path_info() to detect the additional
arguments. For the use there is no difference at all.
If you are talking about perl-scripts running under Apache::Registry or 
Apache::PerlRun, you are in fact running response handlers. The scripts are 
converted to such behind the scenes. In addition registry scripts do a few 
more things, which slow things down just a tiny-bit, probably insignificant if 
you programs are big enough. If you want to explore more, you will find this 
information and a lot more at http://perl.apache.org/docs/.

 I discovered replacements like Apache::Request but I'm now sure if
 this would work inside a handler.
Apache::Request works as a drop-in replacement for CGI.pm's request parsing 
for mp1. It's not yet available for mp2.

__
Stas BekmanJAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide --- http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: cgi.pm does not work in handlers (why responsehandlers at all ?)

2003-04-01 Thread Thomas Klausner
Hi!

On Wed, Apr 02, 2003 at 12:49:56AM +0200, [EMAIL PROTECTED] wrote:

   Is the O'Reilly about apache-modules what I'm looking for ? I've the
 small O'reilly about mod_perl but it raises more questions than its
 answers.

The Eagle book is definitly very interesting (if a little bit old - BTW, is
there a new edition scheduled for mod_perl 2?).

You can find lots of other usefull docs at 
  http://perl.apache.org
including pointers to other books (eg. the mod_perl Developers Cookbook)


-- 
#!/usr/bin/perl   http://domm.zsi.at
for(ref bless{},just'another'perl'hacker){s-:+-$-gprint$_.$/}