perl-modperl-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject cvs commit: modperl-2.0/t/filter/TestFilter both_str_req_add.pm both_str_rec_add.pm
Date Wed, 02 Apr 2003 02:44:15 GMT
stas        2003/04/01 18:44:15

  Added:       t/filter both_str_req_add.t
               t/filter/TestFilter both_str_req_add.pm
  Removed:     t/filter both_str_rec_add.t
               t/filter/TestFilter both_str_rec_add.pm
  Log:
  s/rec/req/ since it's a shortcut for request
  
  Revision  Changes    Path
  1.1                  modperl-2.0/t/filter/both_str_req_add.t
  
  Index: both_str_req_add.t
  ===================================================================
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  use Apache::TestRequest;
  use Apache::TestUtil;
  
  plan tests => 1;
  
  my $data = join ' ', 'A'..'Z', 0..9;
  my $expected = lc $data; # that's what the input filter does
  $expected =~ s/\s+//g;   # that's what the output filter does
  my $location = '/TestFilter::both_str_req_add';
  my $response = POST_BODY $location, content => $data;
  ok t_cmp($expected, $response, "lc input and reverse output filters");
  
  
  
  
  1.1                  modperl-2.0/t/filter/TestFilter/both_str_req_add.pm
  
  Index: both_str_req_add.pm
  ===================================================================
  package TestFilter::both_str_req_add;
  
  # insert an input filter which lowers the case of the data
  # insert an output filter which strips spaces
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Filter ();
  
  use Apache::Const -compile => qw(OK M_POST);
  
  sub header_parser {
      my $r = shift;
      # test adding by coderef
      $r->add_input_filter(\&in_filter);
      # test adding by sub's name
      $r->add_output_filter("out_filter");
  
      return Apache::DECLINED;
  }
  
  sub in_filter {
      my $filter = shift;
  
      while ($filter->read(my $buffer, 1024)) {
          $filter->print(lc $buffer);
      }
  
      Apache::OK;
  }
  
  sub out_filter {
      my $filter = shift;
  
      while ($filter->read(my $buffer, 1024)) {
          $buffer =~ s/\s+//g;
          $filter->print($buffer);
      }
  
      Apache::OK;
  }
  
  sub handler {
      my $r = shift;
  
      $r->content_type('text/plain');
  
      if ($r->method_number == Apache::M_POST) {
          $r->print(ModPerl::Test::read_post($r));
      }
  
      return Apache::OK;
  }
  
  
  
  1;
  __DATA__
  <NoAutoConfig>
      PerlModule TestFilter::both_str_req_add
      <Location /TestFilter::both_str_req_add>
          SetHandler modperl
          PerlHeaderParserHandler TestFilter::both_str_req_add::header_parser
          PerlResponseHandler     TestFilter::both_str_req_add
      </Location>
  </NoAutoConfig>
  
  
  
  
  
  
  

Mime
View raw message