File: response-filter.t

package info (click to toggle)
libweb-simple-perl 0.033-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 380 kB
  • sloc: perl: 1,622; makefile: 7
file content (36 lines) | stat: -rw-r--r-- 718 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use strictures 1;
use Test::More 0.88;
use Plack::Test;
use HTTP::Request::Common qw(GET POST);

{
  package t::Web::Simple::ResponseFilter;
  use Web::Simple;
  sub dispatch_request {
    my $self = shift;
    sub (.html) {
      response_filter {
        return [
          200,
          [ 'Content-Type' => 'text/html' ], 
          [ shift->{name} ],
        ];
      }
    },
    sub (GET + /index) {
      bless {name=>'john'}, 'CrazyHotWildWet';
    },
  }
}

ok my $app = t::Web::Simple::ResponseFilter->new->to_psgi_app,
  'Got a plack app';

test_psgi $app, sub {
    my $cb = shift;
    my $res = $cb->(GET "/index.html");
    like $res->content, qr/john/,
      'Got Expected Content';
};

done_testing;