简体   繁体   中英

basic mod_perl question

I am very newbie to Perl.

I wrote a very simple Perl program (script):

print "hello";

When I execute it on command prompt (with command - perl first.pl), it works.

However, when I use the same Perl code in "filter" of apache it doesn't work. To provide more details, I am invoking a filter for a URL in Apache Http Server with following configuration in httpd.conf file:

<Location /something.do>
      SetHandler modperl
      PerlResponseHandler MyApache2::FirstPerlProg
</Location>

FirstPerlProg.pm file (in indigoampp\\perl-5.12.1\\site\\lib\\MyApache2 location) has same code as first.pl.

The index.html page (first page) has a form which submits request to something.do and this filter gets invoked.

The issue is, how and where do I see this filter's output (hello)?

Hope my question is clear.

I know that I am not making any HTTP response to be sent to browser in this filter code and that's why I get 'page can't be displayed' after submit. However what shall I do is something I don't know.

Thanks.

Depends on how you wrote it. Going by your code, the skeleton should look like

package MyApache2::FirstPerlProg;

use Apache2::Const qw(OK);
use Apache2::RequestRec;
use Apache2::RequestIO;

sub handler {
  my ($r) = @_;
  $r->content_type("text/html");
  $r->print("hello");
  return OK;
}

1;

This would be roughly the bare minimum for a mod_perl request handler. And this should be the response coming back from the request, should see it in the browser. You can also use Apache2::Log and then use $r->log_error("text") to send to the error_log.

If you want your script to run CGI-ish, then use the ModPerl::Registry.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM