Return-Path: Delivered-To: apmail-perl-modperl-archive@www.apache.org Received: (qmail 3437 invoked from network); 13 Mar 2008 15:47:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Mar 2008 15:47:37 -0000 Received: (qmail 2821 invoked by uid 500); 13 Mar 2008 15:47:28 -0000 Delivered-To: apmail-perl-modperl-archive@perl.apache.org Received: (qmail 2803 invoked by uid 500); 13 Mar 2008 15:47:28 -0000 Mailing-List: contact modperl-help@perl.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list modperl@perl.apache.org Received: (qmail 2791 invoked by uid 99); 13 Mar 2008 15:47:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Mar 2008 08:47:28 -0700 X-ASF-Spam-Status: No, hits=1.8 required=10.0 tests=MIME_QP_LONG_LINE,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of xyon@indigorobot.com designates 72.156.224.172 as permitted sender) Received: from [72.156.224.172] (HELO indigorobot.com) (72.156.224.172) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Mar 2008 15:46:51 +0000 Subject: Re: Custom Object-Oriented Module using HTML::Template From: xyon To: modperl In-Reply-To: <47D94A83.9040906@ice-sa.com> Content-Type: text/plain; charset=utf8 Date: Thu, 13 Mar 2008 15:46:54 +0000 Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.7 (---) X-Spam-Report: Spam detection software, running on the system "ettinsmoor.indigorobot.com", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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'); [...] Content analysis details: (-3.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.8 ALL_TRUSTED Passed through trusted hosts only via SMTP -2.6 BAYES_00 BODY: Bayesian spam probability is 0 to 1% [score: 0.0000] 1.4 MIME_QP_LONG_LINE RAW: Quoted-printable line longer than 76 chars -0.7 AWL AWL: From: address is in the auto white-list Message-Id: X-Virus-Checked: Checked by ClamAV on apache.org X-Old-Spam-Flag: YES 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 =3D shift; $self->content_type('text/html'); =20 my $view =3D 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=3DUTF-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=C3=A9 Warnier wrote: > Hi. >=20 > First, don't take my suggestions as gospel, I don't know the TT2 and do=20 > not really know how you're supposed to work with it. > But it seems to me that this is in the wrong order : >=20 > $view->mainpage; > $self->content_type('text/html'); >=20 > I think you should trigger the HTTP header before you generate the=20 > content. Now, whether that is the reason of your current problem or=20 > not, I haven't a clue. >=20 > But I'm trying, and I'm really interested, because I am starting to want=20 > to know more about TT2 (and Catalyst) these days. So your=20 > "from-the-very beginning" approach is also very helpful to me. > (And I do have a certain experience of Apache2/mod_perl2) >=20 > And, re-check your lwp-request switches, you might have disabled the=20 > display of the response content (remove the -d). >=20 > Andr=C3=A9 >=20 >=20 >=20 > xyon wrote: > > Thanks for the reply. > >=20 > > I thought as you did (that there were too many "Content-Type" > > definitions), so commented out this line in the View.pm module, but tha= t > > doesn't seem to have changed anything: > >=20 > > 'print "Content-Type: text/html\n\n";' > >=20 > >=20 > >=20 > >=20 > > 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 > >=20 > > 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=3DUTF-8 > > Client-Date: Thu, 13 Mar 2008 15:24:23 GMT > > Client-Peer: 127.0.0.1:80 > > Client-Response-Num: 1 > > ------------------------------------------------------------------- > >=20 > >=20 > > On Thu, 2008-03-13 at 16:11 +0100, Andr=C3=A9 Warnier wrote: > >> Hi. > >> > >> First, a small disgression : along with perl, comes a beautiful test=20 > >> 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=20 > >> 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=C3=A9 > >> > >> 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 an= d > >>> view module's latest code. I've also included the test script code, j= ust > >>> 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=20 > >>> PerlResponseHandler Myserver::Handler > >>> > >>> ---------------------------------------------------- > >>> > >>> > >>> > >>> > >>> /etc/httpd/perl/startup.pl: > >>> ---------------------------------------------------- > >>> use lib qw(/home/Perl/); > >>> 1; > >>> ---------------------------------------------------- > >>> > >>> > >>> > >>> > >>> Apache log: > >>> ---------------------------------------------------- > >>> =3D=3D> /var/log/httpd/error_log <=3D=3D > >>> ### HTML::Template Debug ### In _parse: > >>> ### HTML::Template _param Stack Dump ### > >>> > >>> $VAR1 =3D [ > >>> \'Test! > >>> ' > >>> ]; > >>> > >>> ### HTML::Template Debug ### In output > >>> ### HTML::Template output Stack Dump ### > >>> > >>> $VAR1 =3D [ > >>> \'Test! > >>> ' > >>> ]; > >>> > >>> > >>> =3D=3D> /var/log/httpd/ssl_request_log <=3D=3D > >>> [13/Mar/2008:10:48:38 -0400] 10.5.5.5 TLSv1 DHE-RSA-AES256-SHA > >>> "GET /admin/ HTTP/1.1" - > >>> > >>> =3D=3D> /var/log/httpd/ssl_access_log <=3D=3D > >>> 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 =3D> qw(OK); > >>> > >>> sub handler { > >>> my $self =3D shift; > >>> =20 > >>> my $view =3D 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 =3D shift; > >>> return $self; > >>> } > >>> > >>> sub mainpage { > >>> my $self =3D shift; > >>> my $template =3D HTML::Template->new( > >>> filename =3D> '/home/Perl/tmpl/mainpage.tmpl', > >>> cache =3D> 1, > >>> debug =3D> 1, > >>> stack_debug =3D> 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 =3D 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 s= ubject line. > >>>>> > >>>>> I am working on my first Object-Oriented project, and have hit a sl= ight > >>>>> snag. I am using HTML::Template to output within the View module, b= ut it > >>>>> never outputs. I don't see any errors in the logs, I just get a bla= nk > >>>>> page. Below is pertinent information including a test script with i= ts > >>>>> 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 =3D shift; > >>>>> return $self; > >>>>> } > >>>>> > >>>>> sub mainpage { > >>>>> my $self =3D shift; > >>>>> my $template =3D HTML::Template->new( filename =3D> > >>>>> '/home/Perl/tmpl/mainpage.tmpl', > >>>>> cache =3D> 1, > >>>>> debug =3D> 1,=20 > >>>>> stack_debug =3D> 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 =3D Myserver::View->new; > >>>>> > >>>>> # Now, let's tell View to display the main page > >>>>> $view->mainpage; > >>>>> > >>>>> print ".OK"; > >>>>> > >>>>> 1; > >>>>> ---------------------------------------------------- > >>>>> > >>>>> > >>>>> > >>>>> /home/Perl/tmpl/mainpage.tmpl: > >>>>> ---------------------------------------------------- > >>>>> Test! > >>>>> ---------------------------------------------------- > >>>>> > >>>>> > >>>>> > >>>>> Output with debugging on (as above): > >>>>> ---------------------------------------------------- > >>>>> $ tests/View_mainpage.pl=20 > >>>>> ### HTML::Template Debug ### In _parse: > >>>>> ### HTML::Template _param Stack Dump ### > >>>>> > >>>>> $VAR1 =3D [ > >>>>> \'Test! > >>>>> ' > >>>>> ]; > >>>>> > >>>>> Main Page..Content-Type: text/html > >>>>> > >>>>> ### HTML::Template Debug ### In output > >>>>> ### HTML::Template output Stack Dump ### > >>>>> > >>>>> $VAR1 =3D [ > >>>>> \'Test! > >>>>> ' > >>>>> ]; > >>>>> > >>>>> .OK > >>>>> ---------------------------------------------------- > >>>>> > >>>>> > >>>>> > >>>>> Output without debugging: > >>>>> ---------------------------------------------------- > >>>>> $ tests/View_mainpage.pl=20 > >>>>> Main Page..Content-Type: text/html > >>>>> > >>>>> .OK > >>>>> ---------------------------------------------------- > >>>>> > >>>>> > >>>>> > >>>>> > >>>>> =20 > >=20 > >=20