2 use warnings FATAL => 'all';
4 use Data::Dumper::Concise;
5 use Test::More 'no_plan';
9 use Web::Simple 't::Web::Simple::SubDispatchArgs';
10 package t::Web::Simple::SubDispatchArgs;
12 has 'attr' => (is=>'ro');
14 sub dispatch_request {
17 $self->show_landing(@_);
20 q(GET + /user) => sub {
21 $self->show_users(@_);
27 sub (POST + %:id=&:@roles~) {
28 $self->process_post(@_);
35 my ($self, @args) = @_;
36 local $self->{_dispatcher};
38 200, ['Content-Type' => 'application/perl' ],
43 my ($self, @args) = @_;
44 local $self->{_dispatcher};
46 200, ['Content-Type' => 'application/perl' ],
51 my ($self, @args) = @_;
52 local $self->{_dispatcher};
54 200, ['Content-Type' => 'application/perl' ],
59 my ($self, @args) = @_;
60 local $self->{_dispatcher};
62 200, ['Content-Type' => 'application/perl' ],
68 ok my $app = t::Web::Simple::SubDispatchArgs->new,
73 return test_psgi $app->to_psgi_app, sub { shift->($request) };
76 use HTTP::Request::Common qw(GET POST);
78 ok my $get_landing = run_request(GET 'http://localhost/' ),
81 cmp_ok $get_landing->code, '==', 200,
87 my ($self, $env, @noextra) = @{eval($get_landing->content)||[]};
89 is scalar(@noextra), 0, 'No extra stuff';
90 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
91 is ref($env), 'HASH', 'Got hashref';
94 ok my $get_users = run_request(GET 'http://localhost/user'),
97 cmp_ok $get_users->code, '==', 200,
101 my ($self, $env, @noextra) = @{eval $get_users->content};
102 is scalar(@noextra), 0, 'No extra stuff';
103 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
104 is ref($env), 'HASH', 'Got hashref';
107 ok my $get_user = run_request(GET 'http://localhost/user/42'),
110 cmp_ok $get_user->code, '==', 200,
114 my ($self, $env, @noextra) = @{eval $get_user->content};
115 is scalar(@noextra), 0, 'No extra stuff';
116 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
117 is ref($env), 'HASH', 'Got hashref';
120 ok my $post_user = run_request(POST 'http://localhost/user/42', [id => '99'] ),
123 cmp_ok $post_user->code, '==', 200,
127 my ($self, $params, $env, @noextra) = @{eval $post_user->content};
128 is scalar(@noextra), 0, 'No extra stuff';
129 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
130 is ref($params), 'HASH', 'Got POST hashref';
131 is $params->{id}, 99, 'got expected value for id';
132 is ref($env), 'HASH', 'Got hashref';