Re: Custom Object-Oriented Module using HTML::Template
That worked great with the test script ( print $template->output; ), but unfortunately, I'm having trouble getting the display onto a web page (via the Handler). The resulting web page is blank, with no source. Below are my Apache configs for the handler, logs, and the handler and view module's latest code. I've also included the test script code, just in case there is some obvious reason it would work and the handler won't. Apache config: PerlRequire /etc/httpd/perl/startup.pl SetHandler modperl PerlResponseHandler Myserver::Handler /etc/httpd/perl/startup.pl: use lib qw(/home/Perl/); 1; Apache log: ==> /var/log/httpd/error_log <== ### HTML::Template Debug ### In _parse: ### HTML::Template _param Stack Dump ### $VAR1 = [ \'Test! ' ]; ### HTML::Template Debug ### In output ### HTML::Template output Stack Dump ### $VAR1 = [ \'Test! ' ]; ==> /var/log/httpd/ssl_request_log <== [13/Mar/2008:10:48:38 -0400] 10.5.5.5 TLSv1 DHE-RSA-AES256-SHA "GET /admin/ HTTP/1.1" - ==> /var/log/httpd/ssl_access_log <== 10.5.5.5 - - [13/Mar/2008:10:48:38 -0400] "GET /admin/ HTTP/1.1" 200 - /home/Perl/Myserver/Handler.pm package Myserver::Handler; #Setup some essentials use strict; #strict tolerance for code use Carp; #debugging use diagnostics;#more debugging use warnings; #more debugging #Handler-related stuff use Apache2::RequestRec (); use Apache2::RequestIO (); use Apache2::Const -compile => qw(OK); sub handler { my $self= shift; my $view= Myserver::View->new(); $view->mainpage; # Obligatory stuff for the handler $self->content_type('text/html'); return Apache2::Const::OK; } 1; /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"; print $template->output; return $self; } 1; /home/Perl/tmpl/mainpage.tmpl: Test! /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; On Thu, 2008-03-13 at 13:29 +0800, Foo JH wrote: > try print $template->output; > > You forgot the print(); > > xyon wrote: > > Hey everyone, > > > > Firstly, I apologize I sent the previous email under an incorrect subject > > line. > > > > 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 >
Re: Custom Object-Oriented Module using HTML::Template
Hi. First, a small disgression : along with perl, comes a beautiful test tool for HTTP stuff, called "lwp-request". Like, at the command-line : lwp-request (to see the options) lwp-request -m GET -Sed "http://myserver/myURL"; (that will show you what you get as a response, without a browser getting in the way) Then, below, are you not now sending one "Content-type" too many ? It looks like you are doing it once in handler(), and once in mainpage(). André xyon wrote: That worked great with the test script ( print $template->output; ), but unfortunately, I'm having trouble getting the display onto a web page (via the Handler). The resulting web page is blank, with no source. Below are my Apache configs for the handler, logs, and the handler and view module's latest code. I've also included the test script code, just in case there is some obvious reason it would work and the handler won't. Apache config: PerlRequire /etc/httpd/perl/startup.pl SetHandler modperl PerlResponseHandler Myserver::Handler /etc/httpd/perl/startup.pl: use lib qw(/home/Perl/); 1; Apache log: ==> /var/log/httpd/error_log <== ### HTML::Template Debug ### In _parse: ### HTML::Template _param Stack Dump ### $VAR1 = [ \'Test! ' ]; ### HTML::Template Debug ### In output ### HTML::Template output Stack Dump ### $VAR1 = [ \'Test! ' ]; ==> /var/log/httpd/ssl_request_log <== [13/Mar/2008:10:48:38 -0400] 10.5.5.5 TLSv1 DHE-RSA-AES256-SHA "GET /admin/ HTTP/1.1" - ==> /var/log/httpd/ssl_access_log <== 10.5.5.5 - - [13/Mar/2008:10:48:38 -0400] "GET /admin/ HTTP/1.1" 200 - /home/Perl/Myserver/Handler.pm package Myserver::Handler; #Setup some essentials use strict; #strict tolerance for code use Carp; #debugging use diagnostics;#more debugging use warnings; #more debugging #Handler-related stuff use Apache2::RequestRec (); use Apache2::RequestIO (); use Apache2::Const -compile => qw(OK); sub handler { my $self= shift; my $view= Myserver::View->new(); $view->mainpage; # Obligatory stuff for the handler $self->content_type('text/html'); return Apache2::Const::OK; } 1; /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"; print $template->output; return $self; } 1; /home/Perl/tmpl/mainpage.tmpl: Test! /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; On Thu, 2008-03-13 at 13:29 +0800, Foo JH wrote: try print $template->output; You forgot the print(); xyon wrote: Hey everyone, Firstly, I apologize I sent the previous email under an incorrect subject line. 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.e
Re: Custom Object-Oriented Module using HTML::Template
Thanks for the reply. I thought as you did (that there were too many "Content-Type" definitions), so commented out this line in the View.pm module, but that doesn't seem to have changed anything: 'print "Content-Type: text/html\n\n";' Here is the lwp command and output: --- $ lwp-request -e -S -s -U -m GET -Sed "http://localhost/admin/"; GET http://localhost/admin/ User-Agent: lwp-request/2.07 GET http://localhost/admin/ --> 200 OK Connection: close Date: Thu, 13 Mar 2008 15:24:23 GMT Server: Apache Content-Length: 0 Content-Type: text/html; charset=UTF-8 Client-Date: Thu, 13 Mar 2008 15:24:23 GMT Client-Peer: 127.0.0.1:80 Client-Response-Num: 1 --- On Thu, 2008-03-13 at 16:11 +0100, André Warnier wrote: > Hi. > > First, a small disgression : along with perl, comes a beautiful test > tool for HTTP stuff, called "lwp-request". > Like, at the command-line : > lwp-request (to see the options) > lwp-request -m GET -Sed "http://myserver/myURL"; > (that will show you what you get as a response, without a browser > getting in the way) > > Then, below, are you not now sending one "Content-type" too many ? > It looks like you are doing it once in handler(), and once in mainpage(). > > André > > xyon wrote: > > That worked great with the test script ( print $template->output; ), but > > unfortunately, I'm having trouble getting the display onto a web page > > (via the Handler). The resulting web page is blank, with no source. > > > > > > Below are my Apache configs for the handler, logs, and the handler and > > view module's latest code. I've also included the test script code, just > > in case there is some obvious reason it would work and the handler > > won't. > > > > > > > > > > Apache config: > > > > PerlRequire /etc/httpd/perl/startup.pl > > > > SetHandler modperl > > PerlResponseHandler Myserver::Handler > > > > > > > > > > > > > > /etc/httpd/perl/startup.pl: > > > > use lib qw(/home/Perl/); > > 1; > > > > > > > > > > > > Apache log: > > > > ==> /var/log/httpd/error_log <== > > ### HTML::Template Debug ### In _parse: > > ### HTML::Template _param Stack Dump ### > > > > $VAR1 = [ > > \'Test! > > ' > > ]; > > > > ### HTML::Template Debug ### In output > > ### HTML::Template output Stack Dump ### > > > > $VAR1 = [ > > \'Test! > > ' > > ]; > > > > > > ==> /var/log/httpd/ssl_request_log <== > > [13/Mar/2008:10:48:38 -0400] 10.5.5.5 TLSv1 DHE-RSA-AES256-SHA > > "GET /admin/ HTTP/1.1" - > > > > ==> /var/log/httpd/ssl_access_log <== > > 10.5.5.5 - - [13/Mar/2008:10:48:38 -0400] "GET /admin/ HTTP/1.1" 200 - > > > > > > > > > > > > /home/Perl/Myserver/Handler.pm > > > > package Myserver::Handler; > > > > #Setup some essentials > > use strict; #strict tolerance for code > > use Carp; #debugging > > use diagnostics;#more debugging > > use warnings; #more debugging > > > > #Handler-related stuff > > use Apache2::RequestRec (); > > use Apache2::RequestIO (); > > use Apache2::Const -compile => qw(OK); > > > > sub handler { > > my $self= shift; > > > > my $view= Myserver::View->new(); > > $view->mainpage; > > > > # Obligatory stuff for the handler > > $self->content_type('text/html'); > > return Apache2::Const::OK; > > > > } > > > > 1; > > > > > > > > > > > > > > /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"; > > print $template->output; > > return $self; > > } > > > > 1; > > > > > > > > > > > > /home/Perl/tmpl/mainpage.tmpl: > > > > Test! > >
Re: Custom Object-Oriented Module using HTML::Template
Just for clarity's sake, here is the test script command and output: --- $ tests/View_mainpage.pl ### HTML::Template Debug ### In _parse: ### HTML::Template _param Stack Dump ### $VAR1 = [ \'Test! ' ]; ### HTML::Template Debug ### In output ### HTML::Template output Stack Dump ### $VAR1 = [ \'Test! ' ]; Main Page..Test! --- On Thu, 2008-03-13 at 11:26 -0400, xyon wrote: > Thanks for the reply. > > I thought as you did (that there were too many "Content-Type" > definitions), so commented out this line in the View.pm module, but that > doesn't seem to have changed anything: > > 'print "Content-Type: text/html\n\n";' > > > > > Here is the lwp command and output: > --- > $ lwp-request -e -S -s -U -m GET -Sed "http://localhost/admin/"; > GET http://localhost/admin/ > User-Agent: lwp-request/2.07 > > GET http://localhost/admin/ --> 200 OK > Connection: close > Date: Thu, 13 Mar 2008 15:24:23 GMT > Server: Apache > Content-Length: 0 > Content-Type: text/html; charset=UTF-8 > Client-Date: Thu, 13 Mar 2008 15:24:23 GMT > Client-Peer: 127.0.0.1:80 > Client-Response-Num: 1 > --- > > > On Thu, 2008-03-13 at 16:11 +0100, André Warnier wrote: > > Hi. > > > > First, a small disgression : along with perl, comes a beautiful test > > tool for HTTP stuff, called "lwp-request". > > Like, at the command-line : > > lwp-request (to see the options) > > lwp-request -m GET -Sed "http://myserver/myURL"; > > (that will show you what you get as a response, without a browser > > getting in the way) > > > > Then, below, are you not now sending one "Content-type" too many ? > > It looks like you are doing it once in handler(), and once in mainpage(). > > > > André > > > > xyon wrote: > > > That worked great with the test script ( print $template->output; ), but > > > unfortunately, I'm having trouble getting the display onto a web page > > > (via the Handler). The resulting web page is blank, with no source. > > > > > > > > > Below are my Apache configs for the handler, logs, and the handler and > > > view module's latest code. I've also included the test script code, just > > > in case there is some obvious reason it would work and the handler > > > won't. > > > > > > > > > > > > > > > Apache config: > > > > > > PerlRequire /etc/httpd/perl/startup.pl > > > > > > SetHandler modperl > > > PerlResponseHandler Myserver::Handler > > > > > > > > > > > > > > > > > > > > > /etc/httpd/perl/startup.pl: > > > > > > use lib qw(/home/Perl/); > > > 1; > > > > > > > > > > > > > > > > > > Apache log: > > > > > > ==> /var/log/httpd/error_log <== > > > ### HTML::Template Debug ### In _parse: > > > ### HTML::Template _param Stack Dump ### > > > > > > $VAR1 = [ > > > \'Test! > > > ' > > > ]; > > > > > > ### HTML::Template Debug ### In output > > > ### HTML::Template output Stack Dump ### > > > > > > $VAR1 = [ > > > \'Test! > > > ' > > > ]; > > > > > > > > > ==> /var/log/httpd/ssl_request_log <== > > > [13/Mar/2008:10:48:38 -0400] 10.5.5.5 TLSv1 DHE-RSA-AES256-SHA > > > "GET /admin/ HTTP/1.1" - > > > > > > ==> /var/log/httpd/ssl_access_log <== > > > 10.5.5.5 - - [13/Mar/2008:10:48:38 -0400] "GET /admin/ HTTP/1.1" 200 - > > > > > > > > > > > > > > > > > > /home/Perl/Myserver/Handler.pm > > > > > > package Myserver::Handler; > > > > > > #Setup some essentials > > > use strict; #strict tolerance for code > > > use Carp; #debugging > > > use diagnostics;#more debugging > > > use warnings; #more debugging > > > > > > #Handler-related stuff > > > use Apache2::RequestRec (); > > > use Apache2::RequestIO (); > > > use Apache2::Const -compile => qw(OK); > > > > > > sub handler { > > > my $self= shift; > > > > > > my $view= Myserver::View->new(); > > > $view->mainpage; > > > > > > # Obligatory stuff for the handler > > > $self->content_type('text/html'); > > > return Apache2::Const::OK; > > > > > > } > > > > > > 1; > > > > > > > > > > > > > > > > > > > > > /home/Perl/Myserver/View.pm: > > > > > > package Myserver::View; > > > > > > #Setup some essentials > > > use strict; #strict tolerance for code > > > use Carp; #d
Re: Custom Object-Oriented Module using HTML::Template
Hi. First, don't take my suggestions as gospel, I don't know the TT2 and do not really know how you're supposed to work with it. But it seems to me that this is in the wrong order : $view->mainpage; $self->content_type('text/html'); I think you should trigger the HTTP header before you generate the content. Now, whether that is the reason of your current problem or not, I haven't a clue. But I'm trying, and I'm really interested, because I am starting to want to know more about TT2 (and Catalyst) these days. So your "from-the-very beginning" approach is also very helpful to me. (And I do have a certain experience of Apache2/mod_perl2) And, re-check your lwp-request switches, you might have disabled the display of the response content (remove the -d). André xyon wrote: Thanks for the reply. I thought as you did (that there were too many "Content-Type" definitions), so commented out this line in the View.pm module, but that doesn't seem to have changed anything: 'print "Content-Type: text/html\n\n";' Here is the lwp command and output: --- $ lwp-request -e -S -s -U -m GET -Sed "http://localhost/admin/"; GET http://localhost/admin/ User-Agent: lwp-request/2.07 GET http://localhost/admin/ --> 200 OK Connection: close Date: Thu, 13 Mar 2008 15:24:23 GMT Server: Apache Content-Length: 0 Content-Type: text/html; charset=UTF-8 Client-Date: Thu, 13 Mar 2008 15:24:23 GMT Client-Peer: 127.0.0.1:80 Client-Response-Num: 1 --- On Thu, 2008-03-13 at 16:11 +0100, André Warnier wrote: Hi. First, a small disgression : along with perl, comes a beautiful test tool for HTTP stuff, called "lwp-request". Like, at the command-line : lwp-request (to see the options) lwp-request -m GET -Sed "http://myserver/myURL"; (that will show you what you get as a response, without a browser getting in the way) Then, below, are you not now sending one "Content-type" too many ? It looks like you are doing it once in handler(), and once in mainpage(). André xyon wrote: That worked great with the test script ( print $template->output; ), but unfortunately, I'm having trouble getting the display onto a web page (via the Handler). The resulting web page is blank, with no source. Below are my Apache configs for the handler, logs, and the handler and view module's latest code. I've also included the test script code, just in case there is some obvious reason it would work and the handler won't. Apache config: PerlRequire /etc/httpd/perl/startup.pl SetHandler modperl PerlResponseHandler Myserver::Handler /etc/httpd/perl/startup.pl: use lib qw(/home/Perl/); 1; Apache log: ==> /var/log/httpd/error_log <== ### HTML::Template Debug ### In _parse: ### HTML::Template _param Stack Dump ### $VAR1 = [ \'Test! ' ]; ### HTML::Template Debug ### In output ### HTML::Template output Stack Dump ### $VAR1 = [ \'Test! ' ]; ==> /var/log/httpd/ssl_request_log <== [13/Mar/2008:10:48:38 -0400] 10.5.5.5 TLSv1 DHE-RSA-AES256-SHA "GET /admin/ HTTP/1.1" - ==> /var/log/httpd/ssl_access_log <== 10.5.5.5 - - [13/Mar/2008:10:48:38 -0400] "GET /admin/ HTTP/1.1" 200 - /home/Perl/Myserver/Handler.pm package Myserver::Handler; #Setup some essentials use strict; #strict tolerance for code use Carp; #debugging use diagnostics;#more debugging use warnings; #more debugging #Handler-related stuff use Apache2::RequestRec (); use Apache2::RequestIO (); use Apache2::Const -compile => qw(OK); sub handler { my $self= shift; my $view= Myserver::View->new(); $view->mainpage; # Obligatory stuff for the handler $self->content_type('text/html'); return Apache2::Const::OK; } 1; /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"; print $templ
Re: Custom Object-Oriented Module using HTML::Template
Good suggestion, I moved the content_type to the top of the handler routine in Handler.pm, so it now looks like: --- sub handler { my $self= shift; $self->content_type('text/html'); my $view= Myserver::View->new(); $view->mainpage; # Obligatory stuff for the handler return Apache2::Const::OK; } --- I am still getting a blank page, though. Here is the latest lwp-request output: --- $ lwp-request -s -U -S -e -m GET "http://localhost/admin/"; GET http://localhost/admin/ User-Agent: lwp-request/2.07 GET http://localhost/admin/ --> 200 OK Connection: close Date: Thu, 13 Mar 2008 15:45:08 GMT Server: Apache Content-Length: 0 Content-Type: text/html; charset=UTF-8 Client-Date: Thu, 13 Mar 2008 15:45:09 GMT Client-Peer: 127.0.0.1:80 Client-Response-Num: 1 --- On Thu, 2008-03-13 at 16:38 +0100, André Warnier wrote: > Hi. > > First, don't take my suggestions as gospel, I don't know the TT2 and do > not really know how you're supposed to work with it. > But it seems to me that this is in the wrong order : > > $view->mainpage; > $self->content_type('text/html'); > > I think you should trigger the HTTP header before you generate the > content. Now, whether that is the reason of your current problem or > not, I haven't a clue. > > But I'm trying, and I'm really interested, because I am starting to want > to know more about TT2 (and Catalyst) these days. So your > "from-the-very beginning" approach is also very helpful to me. > (And I do have a certain experience of Apache2/mod_perl2) > > And, re-check your lwp-request switches, you might have disabled the > display of the response content (remove the -d). > > André > > > > xyon wrote: > > Thanks for the reply. > > > > I thought as you did (that there were too many "Content-Type" > > definitions), so commented out this line in the View.pm module, but that > > doesn't seem to have changed anything: > > > > 'print "Content-Type: text/html\n\n";' > > > > > > > > > > Here is the lwp command and output: > > --- > > $ lwp-request -e -S -s -U -m GET -Sed "http://localhost/admin/"; > > GET http://localhost/admin/ > > User-Agent: lwp-request/2.07 > > > > GET http://localhost/admin/ --> 200 OK > > Connection: close > > Date: Thu, 13 Mar 2008 15:24:23 GMT > > Server: Apache > > Content-Length: 0 > > Content-Type: text/html; charset=UTF-8 > > Client-Date: Thu, 13 Mar 2008 15:24:23 GMT > > Client-Peer: 127.0.0.1:80 > > Client-Response-Num: 1 > > --- > > > > > > On Thu, 2008-03-13 at 16:11 +0100, André Warnier wrote: > >> Hi. > >> > >> First, a small disgression : along with perl, comes a beautiful test > >> tool for HTTP stuff, called "lwp-request". > >> Like, at the command-line : > >> lwp-request (to see the options) > >> lwp-request -m GET -Sed "http://myserver/myURL"; > >> (that will show you what you get as a response, without a browser > >> getting in the way) > >> > >> Then, below, are you not now sending one "Content-type" too many ? > >> It looks like you are doing it once in handler(), and once in mainpage(). > >> > >> André > >> > >> xyon wrote: > >>> That worked great with the test script ( print $template->output; ), but > >>> unfortunately, I'm having trouble getting the display onto a web page > >>> (via the Handler). The resulting web page is blank, with no source. > >>> > >>> > >>> Below are my Apache configs for the handler, logs, and the handler and > >>> view module's latest code. I've also included the test script code, just > >>> in case there is some obvious reason it would work and the handler > >>> won't. > >>> > >>> > >>> > >>> > >>> Apache config: > >>> > >>> PerlRequire /etc/httpd/perl/startup.pl > >>> > >>> SetHandler modperl > >>> PerlResponseHandler Myserver::Handler > >>> > >>> > >>> > >>> > >>> > >>> > >>> /etc/httpd/perl/startup.pl: > >>> > >>> use lib qw(/home/Perl/); > >>> 1; > >>> > >>> > >>> > >>> > >>> > >>> Apache log: > >>> > >>> ==> /var/log/httpd/error_log <== > >>> ### HTML::Template Debug ### In _parse: > >>> ### HTML::Template _param Stack Dump ### > >>> > >>> $VAR1 = [ > >>> \'Test! > >>> ' > >>> ]; > >>> > >>> ### HTML::Template Debug ### In output > >>> ### HTML::Template output Stack Dump ### > >>> > >>> $VAR1 = [ > >>> \'Test! > >>> ' > >>> ]; > >>> > >>> >
Re: Custom Object-Oriented Module using HTML::Template
Hi. I know it's not clean, and it is probably not what you need to do in the long run, and I don't know a bit about HTML::Template. But why don't you try the following, just to check : > package Myserver::Handler; > > #Setup some essentials > use strict; #strict tolerance for code > use Carp; #debugging > use diagnostics;#more debugging > use warnings; #more debugging > #Handler-related stuff > use Apache2::RequestRec (); > use Apache2::RequestIO (); > use Apache2::Const -compile => qw(OK); > use HTML::Template; > > sub handler { > my $self= shift; > $self->content_type('text/html'); > > my $template= HTML::Template->new( >filename => '/home/Perl/tmpl/mainpage.tmpl', > cache => 1, > debug => 1, > stack_debug => 1 ); > print $template->output; > > # Obligatory stuff for the handler > return Apache2::Const::OK; > > } André xyon wrote: Good suggestion, I moved the content_type to the top of the handler routine in Handler.pm, so it now looks like: --- sub handler { my $self= shift; $self->content_type('text/html'); my $view= Myserver::View->new(); $view->mainpage; # Obligatory stuff for the handler return Apache2::Const::OK; } --- I am still getting a blank page, though. Here is the latest lwp-request output: --- $ lwp-request -s -U -S -e -m GET "http://localhost/admin/"; GET http://localhost/admin/ User-Agent: lwp-request/2.07 GET http://localhost/admin/ --> 200 OK Connection: close Date: Thu, 13 Mar 2008 15:45:08 GMT Server: Apache Content-Length: 0 Content-Type: text/html; charset=UTF-8 Client-Date: Thu, 13 Mar 2008 15:45:09 GMT Client-Peer: 127.0.0.1:80 Client-Response-Num: 1 --- On Thu, 2008-03-13 at 16:38 +0100, André Warnier wrote: Hi. First, don't take my suggestions as gospel, I don't know the TT2 and do not really know how you're supposed to work with it. But it seems to me that this is in the wrong order : $view->mainpage; $self->content_type('text/html'); I think you should trigger the HTTP header before you generate the content. Now, whether that is the reason of your current problem or not, I haven't a clue. But I'm trying, and I'm really interested, because I am starting to want to know more about TT2 (and Catalyst) these days. So your "from-the-very beginning" approach is also very helpful to me. (And I do have a certain experience of Apache2/mod_perl2) And, re-check your lwp-request switches, you might have disabled the display of the response content (remove the -d). André xyon wrote: Thanks for the reply. I thought as you did (that there were too many "Content-Type" definitions), so commented out this line in the View.pm module, but that doesn't seem to have changed anything: 'print "Content-Type: text/html\n\n";' Here is the lwp command and output: --- $ lwp-request -e -S -s -U -m GET -Sed "http://localhost/admin/"; GET http://localhost/admin/ User-Agent: lwp-request/2.07 GET http://localhost/admin/ --> 200 OK Connection: close Date: Thu, 13 Mar 2008 15:24:23 GMT Server: Apache Content-Length: 0 Content-Type: text/html; charset=UTF-8 Client-Date: Thu, 13 Mar 2008 15:24:23 GMT Client-Peer: 127.0.0.1:80 Client-Response-Num: 1 --- On Thu, 2008-03-13 at 16:11 +0100, André Warnier wrote: Hi. First, a small disgression : along with perl, comes a beautiful test tool for HTTP stuff, called "lwp-request". Like, at the command-line : lwp-request (to see the options) lwp-request -m GET -Sed "http://myserver/myURL"; (that will show you what you get as a response, without a browser getting in the way) Then, below, are you not now sending one "Content-type" too many ? It looks like you are doing it once in handler(), and once in mainpage(). André xyon wrote: That worked great with the test script ( print $template->output; ), but unfortunately, I'm having trouble getting the display onto a web page (via the Handler). The resulting web page is blank, with no source. Below are my Apache configs for the handler, logs, and the handler and view module's latest code. I've also included the test script code, just in case there is some obvious reason it would work and the handler won't. Apache config: PerlRequire /etc/httpd/perl/startup.pl SetHandler modperl PerlResponseHandler Myserver::Handler ---
RE: Custom Object-Oriented Module using HTML::Template
SetHandler modperl doesn't bind 'print' to '$r->print'. Try SetHandler perl-script, or change your code to pass in the request object and use $r->print instead of print. Adam -Original Message- From: xyon [mailto:[EMAIL PROTECTED] Sent: Thursday, March 13, 2008 11:47 AM To: modperl Subject: Re: Custom Object-Oriented Module using HTML::Template Good suggestion, I moved the content_type to the top of the handler routine in Handler.pm, so it now looks like: --- sub handler { my $self= shift; $self->content_type('text/html'); my $view= Myserver::View->new(); $view->mainpage; # Obligatory stuff for the handler return Apache2::Const::OK; } --- I am still getting a blank page, though. Here is the latest lwp-request output: --- $ lwp-request -s -U -S -e -m GET "http://localhost/admin/"; GET http://localhost/admin/ User-Agent: lwp-request/2.07 GET http://localhost/admin/ --> 200 OK Connection: close Date: Thu, 13 Mar 2008 15:45:08 GMT Server: Apache Content-Length: 0 Content-Type: text/html; charset=UTF-8 Client-Date: Thu, 13 Mar 2008 15:45:09 GMT Client-Peer: 127.0.0.1:80 Client-Response-Num: 1 --- On Thu, 2008-03-13 at 16:38 +0100, André Warnier wrote: > Hi. > > First, don't take my suggestions as gospel, I don't know the TT2 and do > not really know how you're supposed to work with it. > But it seems to me that this is in the wrong order : > > $view->mainpage; > $self->content_type('text/html'); > > I think you should trigger the HTTP header before you generate the > content. Now, whether that is the reason of your current problem or > not, I haven't a clue. > > But I'm trying, and I'm really interested, because I am starting to want > to know more about TT2 (and Catalyst) these days. So your > "from-the-very beginning" approach is also very helpful to me. > (And I do have a certain experience of Apache2/mod_perl2) > > And, re-check your lwp-request switches, you might have disabled the > display of the response content (remove the -d). > > André > > > > xyon wrote: > > Thanks for the reply. > > > > I thought as you did (that there were too many "Content-Type" > > definitions), so commented out this line in the View.pm module, but that > > doesn't seem to have changed anything: > > > > 'print "Content-Type: text/html\n\n";' > > > > > > > > > > Here is the lwp command and output: > > --- > > $ lwp-request -e -S -s -U -m GET -Sed "http://localhost/admin/"; > > GET http://localhost/admin/ > > User-Agent: lwp-request/2.07 > > > > GET http://localhost/admin/ --> 200 OK > > Connection: close > > Date: Thu, 13 Mar 2008 15:24:23 GMT > > Server: Apache > > Content-Length: 0 > > Content-Type: text/html; charset=UTF-8 > > Client-Date: Thu, 13 Mar 2008 15:24:23 GMT > > Client-Peer: 127.0.0.1:80 > > Client-Response-Num: 1 > > --- > > > > > > On Thu, 2008-03-13 at 16:11 +0100, André Warnier wrote: > >> Hi. > >> > >> First, a small disgression : along with perl, comes a beautiful test > >> tool for HTTP stuff, called "lwp-request". > >> Like, at the command-line : > >> lwp-request (to see the options) > >> lwp-request -m GET -Sed "http://myserver/myURL"; > >> (that will show you what you get as a response, without a browser > >> getting in the way) > >> > >> Then, below, are you not now sending one "Content-type" too many ? > >> It looks like you are doing it once in handler(), and once in mainpage(). > >> > >> André > >> > >> xyon wrote: > >>> That worked great with the test script ( print $template->output; ), but > >>> unfortunately, I'm having trouble getting the display onto a web page > >>> (via the Handler). The resulting web page is blank, with no source. > >>> > >>> > >>> Below are my Apache configs for the handler, logs, and the handler and > >>> view module's latest code. I've also included the test script code, just > >>> in case there is some obvious reason it would work and the handler > >>> won't. > >>> > >>> > >>> > >>> > >>> Apache config: > >>> > >>> PerlRequire /etc/httpd/perl/startup.pl > >>> > >>> SetHandler modperl > >>> PerlResponseHandler Myserver::Handler > >>> > >>> > >>> > >>> > >>> > >>> > >>> /etc/httpd/perl/startup.pl: > >>> > >>> use lib qw(/home/Perl/); > >>> 1; > >>> > >>> > >>> > >>> > >>> > >>> Apache log: > >>> > >>> ==> /var/log/httpd/error_log <== > >>> ### HTML::T
RE: Custom Object-Oriented Module using HTML::Template
Thank you all for your advice. With that and some help from a mentor, it is now working, with the below code: Apache config: --- PerlSwitches -I/home/Perl/ PerlModule Myserver::Handler SetHandler modperl PerlResponseHandler Myserver::Handler --- Handler.pm: --- sub handler { my $request = shift; my $view= Myserver::View->new(); if (my $output = $view->mainpage()) { $request->content_type('text/html'); $request->print($output); return Apache2::Const::OK; } else { return Apache2::Const::Declined; }; 1; --- View.pm --- sub new { my $class = shift; my $self= {}; return bless $self, $class; } sub mainpage { my $self= shift; my $template= HTML::Template->new( filename => '/home/Perl/tmpl/mainpage.tmpl', cache => 1, debug => 1, stack_debug => 1 ); return $template->output; } 1; --- On Thu, 2008-03-13 at 12:01 -0400, Adam Prime x443 wrote: > SetHandler modperl doesn't bind 'print' to '$r->print'. Try SetHandler > perl-script, or change your code to pass in the request object and use > $r->print instead of print. > > Adam > > -Original Message- > From: xyon [mailto:[EMAIL PROTECTED] > Sent: Thursday, March 13, 2008 11:47 AM > To: modperl > Subject: Re: Custom Object-Oriented Module using HTML::Template > > Good suggestion, I moved the content_type to the top of the handler > routine in Handler.pm, so it now looks like: > > --- > sub handler { > my $self= shift; > $self->content_type('text/html'); > > my $view= Myserver::View->new(); > $view->mainpage; > > # Obligatory stuff for the handler > return Apache2::Const::OK; > } > --- > > > > I am still getting a blank page, though. Here is the latest lwp-request > output: > > > --- > $ lwp-request -s -U -S -e -m GET "http://localhost/admin/"; > GET http://localhost/admin/ > User-Agent: lwp-request/2.07 > > GET http://localhost/admin/ --> 200 OK > Connection: close > Date: Thu, 13 Mar 2008 15:45:08 GMT > Server: Apache > Content-Length: 0 > Content-Type: text/html; charset=UTF-8 > Client-Date: Thu, 13 Mar 2008 15:45:09 GMT > Client-Peer: 127.0.0.1:80 > Client-Response-Num: 1 > --- > > > > On Thu, 2008-03-13 at 16:38 +0100, André Warnier wrote: > > Hi. > > > > First, don't take my suggestions as gospel, I don't know the TT2 and do > > not really know how you're supposed to work with it. > > But it seems to me that this is in the wrong order : > > > > $view->mainpage; > > $self->content_type('text/html'); > > > > I think you should trigger the HTTP header before you generate the > > content. Now, whether that is the reason of your current problem or > > not, I haven't a clue. > > > > But I'm trying, and I'm really interested, because I am starting to want > > to know more about TT2 (and Catalyst) these days. So your > > "from-the-very beginning" approach is also very helpful to me. > > (And I do have a certain experience of Apache2/mod_perl2) > > > > And, re-check your lwp-request switches, you might have disabled the > > display of the response content (remove the -d). > > > > André > > > > > > > > xyon wrote: > > > Thanks for the reply. > > > > > > I thought as you did (that there were too many "Content-Type" > > > definitions), so commented out this line in the View.pm module, but that > > > doesn't seem to have changed anything: > > > > > > 'print "Content-Type: text/html\n\n";' > > > > > > > > > > > > > > > Here is the lwp command and output: > > > --- > > > $ lwp-request -e -S -s -U -m GET -Sed "http://localhost/admin/"; > > > GET http://localhost/admin/ > > > User-Agent: lwp-request/2.07 > > > > > > GET http://localhost/admin/ --> 200 OK > > > Connection: close > > > Date: Thu, 13 Mar 2008 15:24:23 GMT > > > Server: Apache > > > Content-Length: 0 > > > Content-Type: text/html; charset=UTF-8 > > > Client-Date: Thu, 13 Mar 2008 15:24:23 GMT > > > Client-Peer: 127.0.0.1:80 > > > Client-Response-Num: 1 > > > --- > > > > > > > > > On Thu, 2008-03-13 at 16:11 +0100, André Warnier wrote: > > >> Hi. > > >> > > >> First, a small disgression :
RE: Custom Object-Oriented Module using HTML::Template
FYI, for those interested, I had to do some code adjustments. There was a missing right curly bracket in Handler.pm (need to close the sub), and I wasn't loading DECLINED properly in Handler.pm. Here is the proper setup: --- package Myserver::Handler; #Setup some essentials use strict; #strict tolerance for code use Carp; #debugging use diagnostics;#more debugging use warnings; #more debugging #Handler-related stuff use Apache2::RequestRec (); use Apache2::RequestIO (); use Apache2::Const -compile => qw(OK DECLINED); #Loadup Apache2::Request so we know what's been passed to us use Apache2::Request; #Loadup the Main (Model) and View modules (staying true to the #Model/View/Control (MVC) (We are, Handler, or Control)) use lib "../"; use Myserver::Main; use Myserver::View; sub handler { # We are an instance method my $request = shift; my $view= Myserver::View->new(); if (my $output = $view->mainpage()) { $request->content_type('text/html'); $request->print($output); return Apache2::Const::OK; } else { return Apache2::Const::DECLINED; }; } 1; --- On Thu, 2008-03-13 at 16:32 +, xyon wrote: > Thank you all for your advice. With that and some help from a mentor, it > is now working, with the below code: > > > Apache config: > --- > PerlSwitches -I/home/Perl/ > PerlModule Myserver::Handler > > SetHandler modperl > PerlResponseHandler Myserver::Handler > > --- > > > > > Handler.pm: > --- > sub handler { > my $request = shift; > > my $view= Myserver::View->new(); > if (my $output = $view->mainpage()) { > $request->content_type('text/html'); > $request->print($output); > return Apache2::Const::OK; > } else { > return Apache2::Const::Declined; > }; > > 1; > > --- > > > > > View.pm > --- > sub new { > my $class = shift; > my $self= {}; > return bless $self, $class; > } > > sub mainpage { > my $self= shift; > my $template= HTML::Template->new( > filename => '/home/Perl/tmpl/mainpage.tmpl', > cache => 1, > debug => 1, > stack_debug => 1 ); > return $template->output; > } > > 1; > --- > > > > > On Thu, 2008-03-13 at 12:01 -0400, Adam Prime x443 wrote: > > SetHandler modperl doesn't bind 'print' to '$r->print'. Try SetHandler > > perl-script, or change your code to pass in the request object and use > > $r->print instead of print. > > > > Adam > > > > -Original Message- > > From: xyon [mailto:[EMAIL PROTECTED] > > Sent: Thursday, March 13, 2008 11:47 AM > > To: modperl > > Subject: Re: Custom Object-Oriented Module using HTML::Template > > > > Good suggestion, I moved the content_type to the top of the handler > > routine in Handler.pm, so it now looks like: > > > > --- > > sub handler { > > my $self= shift; > > $self->content_type('text/html'); > > > > my $view= Myserver::View->new(); > > $view->mainpage; > > > > # Obligatory stuff for the handler > > return Apache2::Const::OK; > > } > > --- > > > > > > > > I am still getting a blank page, though. Here is the latest lwp-request > > output: > > > > > > --- > > $ lwp-request -s -U -S -e -m GET "http://localhost/admin/"; > > GET http://localhost/admin/ > > User-Agent: lwp-request/2.07 > > > > GET http://localhost/admin/ --> 200 OK > > Connection: close > > Date: Thu, 13 Mar 2008 15:45:08 GMT > > Server: Apache > > Content-Length: 0 > > Content-Type: text/html; charset=UTF-8 > > Client-Date: Thu, 13 Mar 2008 15:45:09 GMT > > Client-Peer: 127.0.0.1:80 > > Client-Response-Num: 1 > > --- > > > > > > > > On Thu, 2008-03-13 at 16:38 +0100, André Warnier wrote: > > > Hi. > > > > > > First, don't take my suggestions as gospel, I don't know the TT2 and do > > > not really know how you're supposed to work with it. > > > But it seems to me that this is in the wrong order : > > > > > > $view->mainpage; > > > $self->content_type('text/html'); > > > > > > I think you should trigger the HTTP header before you generate the > > > content. Now, whether that is
Apache2::RequestIO::Print: error 104
[error] Apache2::RequestIO::print: (104) Connection reset by peer at /usr/lib/perl5/Template.pm line 178 Has anyone seen that before and/or would you know what I need to look at? Robert
Re: Apache2::RequestIO::Print: error 104
Robert L Hicks wrote: > [error] Apache2::RequestIO::print: (104) Connection reset by peer at > /usr/lib/perl5/Template.pm line 178 Doesn't it just mean that the user hit the stop button before finishing the download of the page? So you were in the middle of writing to the pipe when it was cut. > Has anyone seen that before and/or would you know what I need to look at? A quick search on http://perl.apache.org led me to this: http://perl.apache.org/docs/2.0/api/APR/Socket.html#C_recv_ -- Michael Peters Plus Three, LP
Re: Apache2::RequestIO::Print: error 104
Michael Peters wrote: Robert L Hicks wrote: [error] Apache2::RequestIO::print: (104) Connection reset by peer at /usr/lib/perl5/Template.pm line 178 Doesn't it just mean that the user hit the stop button before finishing the download of the page? So you were in the middle of writing to the pipe when it was cut. Thanks, I only read that once and wanted to make sure.