Re: mod_perl 2.0 Handler issue
xyon wrote: Hello everyone, I am writing my first mod_perl handler. I've looked at some of the docs online and have come up with the config/code below. However, when I go to visit the URL in Apache, I get a download prompt for type: httpd/unix-directory. [snip] try this : sub handler { my $r= shift; # get the Apache Request object $r-content_type('text/html'); # set some Response header $r-print(h1It works !/h1); # send some content return Apache2::Const::OK; # make Apache happy } In your original version, what happens is : sub handler { my $self= shift; # you get the Request object here # you return no content at all return Apache2::Const::OK; # tell Apache it's OK } I guess that with no content returned (not even HTTP headers), Apache is left to wonder what to return, and returns something to the browser with a funny content type. On the other hand, if in your http config you had : PerlResponseHandler Myserver::Handler-handler then your handler sub should be : sub handler { my $self = shift; # get Myserver::Handler class my $r= shift; # get the Apache Request object $r-content_type('text/html'); # set the Response headers $r-print(h1It works !/h1); # send some content return Apache2::Const::OK; # make Apache happy } That is because with the Package-sub syntax in the http config, mod_perl sets up the call differently, and calls you sub() as a method. One last tip : If, instead of returning Apache2::const::OK in your handler, you send nothing back but return Apache2::const::DECLINED, then Apache will revert to its own default handler, and send back what it would normally send (probably a directory listing in this case). Hope this helps. André
Re: mod_perl 2.0 Handler issue
Hey everyone, I am working on my first Object-Oriented project, and have hit a slight snag. I am using HTML::Template to output within the View module, but it never outputs. I don't see any errors in the logs, I just get a blank page. Below is pertinent information including a test script with its output: OS Info: CentOS release 4.6 (Final) Package info: perl-5.8.8-11 perl-HTML-Template-2.9-1 httpd-2.0.59-1.el4s1.10.el4.centos mod_perl-2.0.3-1.el4s1.3 /home/perl/Myserver/View.pm package Myserver::View; #Setup some essentials use strict; #strict tolerance for code use Carp; #debugging use diagnostics;#more debugging use warnings; #more debugging #Loadup some needed functions use HTML::Template; sub new { my $self= shift; return $self; } sub mainpage { my $self= shift; my $template= HTML::Template-new( filename = '/home/Perl/tmpl/mainpage.tmpl', cache = 1, debug = 1, stack_debug = 1 ); print Content-Type: text/html\n\n; $template-output; return $self; } 1; /home/Perl/tests/View_mainpage.pl #!/usr/bin/perl -w # Test printing of the main page print Main Page..; #Let's load the view module use lib ../; use Myserver::View; #Now let's load some things that are very handy use strict; #strict tolerance for code use Carp; #debugging use warnings; #more debugging use diagnostics;#even more debugging # Let's create an object my $view= Myserver::View-new; # Now, let's tell View to display the main page $view-mainpage; print .OK; 1; /home/Perl/tmpl/mainpage.tmpl: htmlbody bgcolor=#FF00FFTest!/body/html Output with debugging on (as above): $ tests/View_mainpage.pl ### HTML::Template Debug ### In _parse: ### HTML::Template _param Stack Dump ### $VAR1 = [ \'htmlbody bgcolor=#FF00FFTest!/body/html ' ]; Main Page..Content-Type: text/html ### HTML::Template Debug ### In output ### HTML::Template output Stack Dump ### $VAR1 = [ \'htmlbody bgcolor=#FF00FFTest!/body/html ' ]; .OK Output without debugging: $ tests/View_mainpage.pl Main Page..Content-Type: text/html .OK -- xyon [EMAIL PROTECTED]