You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Tatsuhiko Miyagawa <mi...@edge.co.jp> on 2002/07/04 11:12:34 UTC

Apache::Filter can't print outside read() loop?

The following HTML-Template filter code works (becomes useful with
PerlOptions +SetupEnv)
  
  package Slasher::HTMLTemplate;
  
  use strict;
  
  use Apache::RequestRec ();
  use Apache::RequestIO ();
  use Apache::Filter ();
  use HTML::Template;
  
  use Apache::Const -compile => 'OK';
  
  sub handler {
      my $filter = shift;
      my $r = Apache->request;
      while ($filter->read(my $buffer)) {
          my $t = HTML::Template->new(scalarref => \$buffer,
                                      die_on_bad_params => 0);
          $t->param(%ENV);
          $filter->print($t->output);
      }
      return Apache::OK;
  }
  
  1;
 
But when I change while loop to accumulate read() input to a scalar
variable, it doesn't work (it doesn't print out anything)

      my $html;
      while ($filter->read(my $buffer, 1024)) {
          $html .= $buffer;
      }
      my $t = HTML::Template->new(scalarref => \$html,
                                  die_on_bad_params => 0);
      $t->param(%ENV);
      $filter->print($t->output);

In a word, Apache::Filter::print() doesn't work outside the read()
loop. Any pointer for it?


  
Server: Apache/2.0.39 (Unix) mod_perl/1.99_04-dev Perl/v5.8.0


Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.4.2-2, archname=i686-linux-thread-multi
    uname='linux yoshimax 2.4.2-2 #1 sun apr 8 20:41:30 edt 2001 i686 unknown '
    config_args='-des -Dusethreads -Dprefix=~/perl-5.8'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='2.96 20000731 (Red Hat Linux 7.1 2.96-81)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldl -lm -lpthread -lc -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lpthread -lc -lcrypt -lutil
    libc=/lib/libc-2.2.2.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.2.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'


Characteristics of this binary (from libperl):
  Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES PERL_IMPLICIT_
CONTEXT
  Built under linux
  Compiled at Jul  4 2002 14:16:07
  %ENV:
    PERL5LIB="/home/miyagawa/local/lib/perl5/site_perl/5.005"
  @INC:
    /home/miyagawa/local/lib/perl5/site_perl/5.005
    /home/miyagawa/perl-5.8/lib/5.8.0/i686-linux-thread-multi
    /home/miyagawa/perl-5.8/lib/5.8.0
    /home/miyagawa/perl-5.8/lib/site_perl/5.8.0/i686-linux-thread-multi
    /home/miyagawa/perl-5.8/lib/site_perl/5.8.0
    /home/miyagawa/perl-5.8/lib/site_perl
    .

-- 
Tatsuhiko Miyagawa <mi...@edge.co.jp>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: Apache::Filter can't print outside read() loop?

Posted by Tatsuhiko Miyagawa <mi...@edge.co.jp>.
At Thu, 04 Jul 2002 18:12:34 +0900,
Tatsuhiko Miyagawa wrote:
>   
> Server: Apache/2.0.39 (Unix) mod_perl/1.99_04-dev Perl/v5.8.0

I compiled httpd-2.0 with worker MPM + perl 5.8.0 RC2 with ithreads.
(to see how multithreadness in mod_perl2.0 works in Linux box)


-- 
Tatsuhiko Miyagawa <mi...@edge.co.jp>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: Apache::Filter can't print outside read() loop?

Posted by Stas Bekman <st...@stason.org>.
Tatsuhiko Miyagawa wrote:
> At Fri, 05 Jul 2002 22:21:14 +0800,
> Stas Bekman wrote:
> 
> 
>>># testing : Apache::Util::parsedate
>>># expected: 1025779533
>>># received: '0'
>>>not ok 46
>>
>>this one is weird, can you run this one in debug mode? This precooked
>>gdb script should make it really easy to debug the internals on your side.
> 
> 
> Sorry, I mean this one is also due to my weird locale setting of my
> linux box. with locae set to Japanese, date is also returned as
> japanese format.

so this is a non-issue, correct?

>>># write to a file:
>>># This is a test: 15197
>>># testing : expected failure
>>># expected: 'No such file or directory'
>>># received: 'そのようなファイルやディレクトリはありません'
>>>not ok 2
>>>ok 3
>>>
>>>Well, it seems to be due to locale (japanese) stuff in my linux box.
>>
>>That's a tough on. We are definitely not going to supply a set of error
>>messages in all possible errors.
>>
>>Is C "errno" variable's numerical value the same everywhere? If that's
>>the case we could compare the numerical value
> 
> 
> Or, first get the error message by trying to open non-exsitent file,
> and afterword compare error message with it.

that's smart :) thanks!


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: Apache::Filter can't print outside read() loop?

Posted by Tatsuhiko Miyagawa <mi...@edge.co.jp>.
At Fri, 05 Jul 2002 22:21:14 +0800,
Stas Bekman wrote:

> > # testing : Apache::Util::parsedate
> > # expected: 1025779533
> > # received: '0'
> > not ok 46
> 
> this one is weird, can you run this one in debug mode? This precooked
> gdb script should make it really easy to debug the internals on your side.

Sorry, I mean this one is also due to my weird locale setting of my
linux box. with locae set to Japanese, date is also returned as
japanese format.

> 
> > # write to a file:
> > # This is a test: 15197
> > # testing : expected failure
> > # expected: 'No such file or directory'
> > # received: 'そのようなファイルやディレクトリはありません'
> > not ok 2
> > ok 3
> > 
> > Well, it seems to be due to locale (japanese) stuff in my linux box.
> 
> That's a tough on. We are definitely not going to supply a set of error
> messages in all possible errors.
> 
> Is C "errno" variable's numerical value the same everywhere? If that's
> the case we could compare the numerical value

Or, first get the error message by trying to open non-exsitent file,
and afterword compare error message with it.

--
Tatsuhiko Miyagawa <mi...@edge.co.jp>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: Apache::Filter can't print outside read() loop?

Posted by Stas Bekman <st...@stason.org>.
Tatsuhiko Miyagawa wrote:
> At Thu, 04 Jul 2002 18:46:26 +0800,
> Stas Bekman wrote:
> 
> 
>>Does you 'make test' pass properly? Though it doesn't test the thing you 
>>are talking about. Therefore I upgraded the reverse test filter to test 
>>for $filter->print(). Before I commit it, please try it first, it works 
>>for me.
> 
> 
> first try with:
>   perl 5.8.0 RC2
>   httpd 2.0.39 (worker MPM)
>   mod_perl CVS
> 
> filter tests pass okay, but
> 
> Failed Test      Stat Wstat Total Fail  Failed  List of Failed
> -------------------------------------------------------------------------------
> apache/compat2.t               50    1   2.00%  46
> apr/perlio.t                   11    1   9.09%  2
> 
> 
> here's a detail:
> 
> # testing : Apache::Util::parsedate
> # expected: 1025779533
> # received: '0'
> not ok 46

this one is weird, can you run this one in debug mode? This precooked
gdb script should make it really easy to debug the internals on your side.
http://perl.apache.org/release/docs/2.0/devel/debug_c/debug_c.html#Precooked_gdb_Startup_Scripts
If you need help, shout.


> # write to a file:
> # This is a test: 15197
> # testing : expected failure
> # expected: 'No such file or directory'
> # received: 'そのようなファイルやディレクトリはありません'
> not ok 2
> ok 3
> 
> Well, it seems to be due to locale (japanese) stuff in my linux box.

That's a tough on. We are definitely not going to supply a set of error
messages in all possible errors.

Is C "errno" variable's numerical value the same everywhere? If that's
the case we could compare the numerical value

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: Apache::Filter can't print outside read() loop?

Posted by Stas Bekman <st...@stason.org>.
Stas Bekman wrote:
> Stas Bekman wrote:
> 
>> Tatsuhiko Miyagawa wrote:
>>
>>> At Thu, 04 Jul 2002 20:07:12 +0900,
>>> Tatsuhiko Miyagawa wrote:
>>>  
>>>
>>>> I mean I don't use perl-script or modperl for content generation. just
>>>> serves  plain .html file with default-handler.
>>>
>>>
>>>
>>>
>>> OK. I tried
>>>
>>> <Location /hello>
>>> SetHandler modperl
>>> PerlResponseHandler Slasher::Hello
>>> PerlOutputFilterHandler Slasher::HTMLTemplate
>>> </Location>
>>>
>>> and then it worked!
>>>
>>> okay, current TestFilter::lc test is applied to static file, thus
>>> here's a patch to reproduce the failure:
>>>
>>> (does it never get flushed? if I put die() after last print(), the
>>> message gets out before "OK" annoying error messages)
>>
>>
>>
>> Good observation. I can reproduce this problem with non-mod_perl 
>> handler. Actually I've continued building on top of the reverse test. 
>> For some reason I like it :)
>>
>> When a file is sent the EOS bucket arrives as well. And after the EOS 
>> bucket went through the filter shouldn't send anything at all. If the 
>> filter wants to add something it must remove the EOS bucket, send 
>> whatever it needs to send and then re-insert the EOS bucket. And in 
>> the stream mode this should be done transparently to the filter.
>>
>> As a temp workaround to get you going you can use this patch, but I 
>> think it's a bad hack. I'll try to come up with something better.
> 
> 
> here is the proper patch. This patch makes the filter remember that it 
> saw an EOS bucket, but it actually uses this information only at the end 
> of modperl_run_filter so a stream filter gets a chance to send more data 
> after eos was seen.

This is a better patch. The previous one was losing the eos for input 
filters.

Index: src/modules/perl/modperl_filter.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_filter.c,v
retrieving revision 1.36
diff -u -r1.36 modperl_filter.c
--- src/modules/perl/modperl_filter.c	29 Jun 2002 20:38:33 -0000	1.36
+++ src/modules/perl/modperl_filter.c	2 Aug 2002 11:11:57 -0000
@@ -155,6 +155,11 @@

      MP_TRACE_f(MP_FUNC, "%s returned %d\n", handler->name, status);

+    if (filter->seen_eos) {
+        filter->eos = 1;
+        filter->seen_eos = 0;
+    }
+
      if (filter->mode == MP_OUTPUT_FILTER_MODE) {
          modperl_output_filter_flush(filter);
      }
@@ -211,7 +216,8 @@
          return 1;
      }
      else if (MP_FILTER_IS_EOS(filter)) {
-        filter->eos = 1;
+        MP_TRACE_f(MP_FUNC, "received EOS bucket\n");
+        filter->seen_eos = 1;
          return 1;
      }
      else if (filter->bucket != MP_FILTER_SENTINEL(filter)) {
@@ -279,7 +285,7 @@

          if (MP_FILTER_IS_EOS(filter)) {
              MP_TRACE_f(MP_FUNC, "received EOS bucket\n");
-            filter->eos = 1;
+            filter->seen_eos = 1;
              break;
          }
          else if (MP_FILTER_IS_FLUSH(filter)) {
Index: src/modules/perl/modperl_types.h
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_types.h,v
retrieving revision 1.60
diff -u -r1.60 modperl_types.h
--- src/modules/perl/modperl_types.h	29 Jun 2002 20:38:33 -0000	1.60
+++ src/modules/perl/modperl_types.h	2 Aug 2002 11:11:57 -0000
@@ -182,6 +182,7 @@
  } modperl_filter_mode_e;

  typedef struct {
+    int seen_eos;
      int eos;
      int flush;
      ap_filter_t *f;



__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: Apache::Filter can't print outside read() loop?

Posted by Stas Bekman <st...@stason.org>.
Stas Bekman wrote:
> Tatsuhiko Miyagawa wrote:
> 
>> At Thu, 04 Jul 2002 20:07:12 +0900,
>> Tatsuhiko Miyagawa wrote:
>>  
>>
>>> I mean I don't use perl-script or modperl for content generation. just
>>> serves  plain .html file with default-handler.
>>
>>
>>
>> OK. I tried
>>
>> <Location /hello>
>> SetHandler modperl
>> PerlResponseHandler Slasher::Hello
>> PerlOutputFilterHandler Slasher::HTMLTemplate
>> </Location>
>>
>> and then it worked!
>>
>> okay, current TestFilter::lc test is applied to static file, thus
>> here's a patch to reproduce the failure:
>>
>> (does it never get flushed? if I put die() after last print(), the
>> message gets out before "OK" annoying error messages)
> 
> 
> Good observation. I can reproduce this problem with non-mod_perl 
> handler. Actually I've continued building on top of the reverse test. 
> For some reason I like it :)
> 
> When a file is sent the EOS bucket arrives as well. And after the EOS 
> bucket went through the filter shouldn't send anything at all. If the 
> filter wants to add something it must remove the EOS bucket, send 
> whatever it needs to send and then re-insert the EOS bucket. And in the 
> stream mode this should be done transparently to the filter.
> 
> As a temp workaround to get you going you can use this patch, but I 
> think it's a bad hack. I'll try to come up with something better.

here is the proper patch. This patch makes the filter remember that it 
saw an EOS bucket, but it actually uses this information only at the end 
of modperl_run_filter so a stream filter gets a chance to send more data 
after eos was seen.

Index: src/modules/perl/modperl_types.h
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_types.h,v
retrieving revision 1.60
diff -u -r1.60 modperl_types.h
--- src/modules/perl/modperl_types.h	29 Jun 2002 20:38:33 -0000	1.60
+++ src/modules/perl/modperl_types.h	5 Jul 2002 15:09:12 -0000
@@ -182,6 +182,7 @@
  } modperl_filter_mode_e;

  typedef struct {
+    int seen_eos;
      int eos;
      int flush;
      ap_filter_t *f;

Index: src/modules/perl/modperl_filter.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_filter.c,v
retrieving revision 1.36
diff -u -r1.36 modperl_filter.c
--- src/modules/perl/modperl_filter.c	29 Jun 2002 20:38:33 -0000	1.36
+++ src/modules/perl/modperl_filter.c	5 Jul 2002 15:03:08 -0000
@@ -156,6 +156,10 @@
      MP_TRACE_f(MP_FUNC, "%s returned %d\n", handler->name, status);

      if (filter->mode == MP_OUTPUT_FILTER_MODE) {
+        if (filter->seen_eos) {
+            filter->eos = 1;
+            filter->seen_eos = 0;
+        }
          modperl_output_filter_flush(filter);
      }

@@ -211,7 +215,7 @@
          return 1;
      }
      else if (MP_FILTER_IS_EOS(filter)) {
-        filter->eos = 1;
+        filter->seen_eos = 1;
          return 1;
      }
      else if (filter->bucket != MP_FILTER_SENTINEL(filter)) {
@@ -279,7 +283,7 @@

          if (MP_FILTER_IS_EOS(filter)) {
              MP_TRACE_f(MP_FUNC, "received EOS bucket\n");
-            filter->eos = 1;
+            filter->seen_eos = 1;
              break;
          }
          else if (MP_FILTER_IS_FLUSH(filter)) {


-- 


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: Apache::Filter can't print outside read() loop?

Posted by Stas Bekman <st...@stason.org>.
Tatsuhiko Miyagawa wrote:
> At Thu, 04 Jul 2002 20:07:12 +0900,
> Tatsuhiko Miyagawa wrote:
>  
> 
>>I mean I don't use perl-script or modperl for content generation. just
>>serves  plain .html file with default-handler.
> 
> 
> OK. I tried
> 
> <Location /hello>
> SetHandler modperl
> PerlResponseHandler Slasher::Hello
> PerlOutputFilterHandler Slasher::HTMLTemplate
> </Location>
> 
> and then it worked!
> 
> okay, current TestFilter::lc test is applied to static file, thus
> here's a patch to reproduce the failure:
> 
> (does it never get flushed? if I put die() after last print(), the
> message gets out before "OK" annoying error messages)

Good observation. I can reproduce this problem with non-mod_perl 
handler. Actually I've continued building on top of the reverse test. 
For some reason I like it :)

When a file is sent the EOS bucket arrives as well. And after the EOS 
bucket went through the filter shouldn't send anything at all. If the 
filter wants to add something it must remove the EOS bucket, send 
whatever it needs to send and then re-insert the EOS bucket. And in the 
stream mode this should be done transparently to the filter.

As a temp workaround to get you going you can use this patch, but I 
think it's a bad hack. I'll try to come up with something better.

Index: src/modules/perl/modperl_filter.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_filter.c,v
retrieving revision 1.36
diff -u -r1.36 modperl_filter.c
--- src/modules/perl/modperl_filter.c	29 Jun 2002 20:38:33 -0000	1.36
+++ src/modules/perl/modperl_filter.c	5 Jul 2002 13:11:35 -0000
@@ -156,6 +156,14 @@
      MP_TRACE_f(MP_FUNC, "%s returned %d\n", handler->name, status);

      if (filter->mode == MP_OUTPUT_FILTER_MODE) {
+        /* XXX: if the filter wrote something after the original eos
+         *  bucket went through flush the remaining data if any left
+         *  (currently in the stream mode the filter cannot remove an
+         *  eos bucket, or add one)
+         */
+        if (filter->wbucket.outcnt) {
+            filter->flush = 1;
+        }
          modperl_output_filter_flush(filter);
      }


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: Apache::Filter can't print outside read() loop?

Posted by Tatsuhiko Miyagawa <mi...@edge.co.jp>.
At Thu, 04 Jul 2002 20:07:12 +0900,
Tatsuhiko Miyagawa wrote:
 
> I mean I don't use perl-script or modperl for content generation. just
> serves  plain .html file with default-handler.

OK. I tried

<Location /hello>
SetHandler modperl
PerlResponseHandler Slasher::Hello
PerlOutputFilterHandler Slasher::HTMLTemplate
</Location>

and then it worked!

okay, current TestFilter::lc test is applied to static file, thus
here's a patch to reproduce the failure:

(does it never get flushed? if I put die() after last print(), the
message gets out before "OK" annoying error messages)

Index: t/filter/lc.t
===================================================================
RCS file: /home/cvspublic/modperl-2.0/t/filter/lc.t,v
retrieving revision 1.4
diff -u -r1.4 lc.t
--- t/filter/lc.t       20 Dec 2001 03:54:41 -0000      1.4
+++ t/filter/lc.t       4 Jul 2002 11:18:07 -0000
@@ -4,10 +4,11 @@
 use Apache::Test;
 use Apache::TestRequest;

-plan tests => 1;
+plan tests => 2;

 my $location = "/top_dir/Makefile";

 my $str = GET_BODY $location;

 ok $str !~ /[A-Z]/;
+ok $str =~ /lc\(\)ed by mod_perl 2.0/;
Index: t/filter/TestFilter/lc.pm
===================================================================
RCS file: /home/cvspublic/modperl-2.0/t/filter/TestFilter/lc.pm,v
retrieving revision 1.3
diff -u -r1.3 lc.pm
--- t/filter/TestFilter/lc.pm   11 Apr 2002 11:08:43 -0000      1.3
+++ t/filter/TestFilter/lc.pm   4 Jul 2002 11:18:07 -0000
@@ -13,7 +13,7 @@
     while ($filter->read(my $buffer, 1024)) {
         $filter->print(lc $buffer);
     }
-
+    $filter->print("lc()ed by mod_perl 2.0\n");
     Apache::OK;
 }



-- 
Tatsuhiko Miyagawa <mi...@edge.co.jp>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: Apache::Filter can't print outside read() loop?

Posted by Tatsuhiko Miyagawa <mi...@edge.co.jp>.
At Thu, 04 Jul 2002 18:46:26 +0800,
Stas Bekman wrote:

> Does you 'make test' pass properly? Though it doesn't test the thing you 
> are talking about. Therefore I upgraded the reverse test filter to test 
> for $filter->print(). Before I commit it, please try it first, it works 
> for me.

first try with:
  perl 5.8.0 RC2
  httpd 2.0.39 (worker MPM)
  mod_perl CVS

filter tests pass okay, but

Failed Test      Stat Wstat Total Fail  Failed  List of Failed
-------------------------------------------------------------------------------
apache/compat2.t               50    1   2.00%  46
apr/perlio.t                   11    1   9.09%  2


here's a detail:

# testing : Apache::Util::parsedate
# expected: 1025779533
# received: '0'
not ok 46

# write to a file:
# This is a test: 15197
# testing : expected failure
# expected: 'No such file or directory'
# received: 'そのようなファイルやディレクトリはありません'
not ok 2
ok 3

Well, it seems to be due to locale (japanese) stuff in my linux box.
Then I put in your test files and run filter/ tests:

filter/api...............ok
filter/buckets...........ok
filter/input_body........ok
filter/input_msg.........ok
filter/lc................ok
filter/reverse...........ok


Okay another key: my httpd.conf is something like this.

LoadModule perl_module modules/mod_perl.so
PerlInitHandler Apache::Reload
PerlOptions +SetupEnv

PerlModule Slasher::HTMLTemplate
<Location /tmpl>
PerlOptions +GlobalRequest
PerlOutputFilterHandler Slasher::HTMLTemplate
</Location>


I mean I don't use perl-script or modperl for content generation. just
serves  plain .html file with default-handler.




-- 
Tatsuhiko Miyagawa <mi...@edge.co.jp>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: Apache::Filter can't print outside read() loop?

Posted by Stas Bekman <st...@stason.org>.
> When I put "warn $html;" before print(), it dumps HTML code to the
> error_log (thus it doesn't mean $html is empty)

Does you 'make test' pass properly? Though it doesn't test the thing you 
are talking about. Therefore I upgraded the reverse test filter to test 
for $filter->print(). Before I commit it, please try it first, it works 
for me.

but since t/filter/reverse.t was autogenerated, you have to first run 
t/TEST -clean, put the files in place and then run t/TEST -conf, because 
if you don't it'll be deleted on next -clean.

t/filter/reverse.t
------------------
use strict;
use warnings FATAL => 'all';

use Apache::Test;
use Apache::TestRequest;
use Apache::TestUtil;

plan tests => 1;

my $location = '/TestFilter::reverse';

my @data = (join('', 'a'..'z'), join('', 0..9));

my $reversed_data = join '', map { scalar(reverse $_) . "\n" } @data;
#t_debug($reversed_data);
my $sig = "Reversed by mod_perl 2.0\n";
my $expected = join "\n", @data, $sig;

my $response = POST_BODY $location, content => $reversed_data;
ok t_cmp($expected, $response, "reverse filter");


t/filter/TestFilter/reverse.pm
-------------------------------
package TestFilter::reverse;

use strict;
use warnings FATAL => 'all';

use Apache::RequestRec ();
use Apache::RequestIO ();
use Apache::Filter ();

use Apache::Const -compile => qw(OK M_POST);

sub handler {
     my $filter = shift;

     while ($filter->read(my $buffer, 1024)) {
         for (split "\n", $buffer) {
             $filter->print(scalar reverse $_);
             $filter->print("\n");
         }
     }
     $filter->print("Reversed by mod_perl 2.0\n");
     0;
}

sub response {
     my $r = shift;

     $r->content_type('text/plain');

     if ($r->method_number == Apache::M_POST) {
         my $data = ModPerl::Test::read_post($r);
         $r->puts($data);
     }

     Apache::OK;
}

1;
__DATA__
SetHandler modperl
PerlResponseHandler TestFilter::reverse::response

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: Apache::Filter can't print outside read() loop?

Posted by Tatsuhiko Miyagawa <mi...@edge.co.jp>.
At Thu, 04 Jul 2002 17:51:14 +0800,
Stas Bekman wrote:

> > In a word, Apache::Filter::print() doesn't work outside the read()
> > loop. Any pointer for it?
> 
> It did work for me when I've tried more evolved reverse filter (posted 
> here a few weeks ago). Care to provide a simple example that doesn't 
> work for you? without involving HTML::Filter
> 
> can you simply do:
> 
> $filter->print("whatever");
> 
> ?

Yep, the following simplified code also doesn't print anything:

  package Slasher::HTMLTemplate;
  
  use strict;
  
  use Apache::RequestRec ();
  use Apache::RequestIO ();
  use Apache::Filter ();
  #use HTML::Template;
  
  use Apache::Const -compile => 'OK';
  
  sub handler {
      my $filter = shift;
      my $html;
      while ($filter->read(my $buffer)) {
  #       my $t = HTML::Template->new(scalarref => \$buffer,
  #                                   die_on_bad_params => 0);
  #       $t->param(%ENV);
  #       $filter->print($t->output);
          $html .= $buffer;
      }
      $filter->print("foobar\n");
      $filter->print($html);
      return Apache::OK;
  }
  
  1;

When I put "warn $html;" before print(), it dumps HTML code to the
error_log (thus it doesn't mean $html is empty)

I'll look into your reverse filter more deeply ...

Thanks,

-- 
Tatsuhiko Miyagawa <mi...@edge.co.jp>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: Apache::Filter can't print outside read() loop?

Posted by Stas Bekman <st...@stason.org>.
Tatsuhiko Miyagawa wrote:
> The following HTML-Template filter code works (becomes useful with
> PerlOptions +SetupEnv)
>   
>   package Slasher::HTMLTemplate;
>   
>   use strict;
>   
>   use Apache::RequestRec ();
>   use Apache::RequestIO ();
>   use Apache::Filter ();
>   use HTML::Template;
>   
>   use Apache::Const -compile => 'OK';
>   
>   sub handler {
>       my $filter = shift;
>       my $r = Apache->request;
>       while ($filter->read(my $buffer)) {
>           my $t = HTML::Template->new(scalarref => \$buffer,
>                                       die_on_bad_params => 0);
>           $t->param(%ENV);
>           $filter->print($t->output);
>       }
>       return Apache::OK;
>   }
>   
>   1;
>  
> But when I change while loop to accumulate read() input to a scalar
> variable, it doesn't work (it doesn't print out anything)
> 
>       my $html;
>       while ($filter->read(my $buffer, 1024)) {
>           $html .= $buffer;
>       }
>       my $t = HTML::Template->new(scalarref => \$html,
>                                   die_on_bad_params => 0);
>       $t->param(%ENV);
>       $filter->print($t->output);
> 
> In a word, Apache::Filter::print() doesn't work outside the read()
> loop. Any pointer for it?

It did work for me when I've tried more evolved reverse filter (posted 
here a few weeks ago). Care to provide a simple example that doesn't 
work for you? without involving HTML::Filter

can you simply do:

$filter->print("whatever");

?


-- 


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org