2 use warnings FATAL => 'all';
4 use Data::Dump qw(dump);
6 eval { require HTTP::Request::AsCGI }
8 : (skip_all => 'No HTTP::Request::AsCGI')
12 use Web::Simple 't::Web::Simple::SubDispatchArgs';
13 package t::Web::Simple::SubDispatchArgs;
15 sub dispatch_request {
17 $_[0]->show_landing(@_);
21 $_[0]->show_users(@_);
27 sub (POST + %:id=&:@roles~) {
28 $_[0]->process_post(@_);
35 my ($self, @args) = @_;
37 200, ['Content-Type' => 'application/perl' ],
38 [Data::Dump::dump @args],
42 my ($self, @args) = @_;
44 200, ['Content-Type' => 'application/perl' ],
45 [Data::Dump::dump @args],
49 my ($self, @args) = @_;
51 200, ['Content-Type' => 'application/perl' ],
52 [Data::Dump::dump @args],
56 my ($self, @args) = @_;
58 200, ['Content-Type' => 'application/perl' ],
59 [Data::Dump::dump @args],
64 ok my $app = t::Web::Simple::SubDispatchArgs->new,
68 my @args = (shift, SCRIPT_NAME=> $0);
69 my $c = HTTP::Request::AsCGI->new(@args)->setup;
75 use HTTP::Request::Common qw(GET POST);
77 ok my $get_landing = run_request(GET 'http://localhost/' ),
80 cmp_ok $get_landing->code, '==', 200,
84 my ($self, $env, @noextra) = eval $get_landing->content;
85 is scalar(@noextra), 0, 'No extra stuff';
86 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
87 is ref($env), 'HASH', 'Got hashref';
88 is $env->{SCRIPT_NAME}, $0, 'correct scriptname';
91 ok my $get_users = run_request(GET 'http://localhost/user'),
94 cmp_ok $get_users->code, '==', 200,
98 my ($self, $env, @noextra) = eval $get_users->content;
99 is scalar(@noextra), 0, 'No extra stuff';
100 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
101 is ref($env), 'HASH', 'Got hashref';
102 is $env->{SCRIPT_NAME}, $0, 'correct scriptname';
105 ok my $get_user = run_request(GET 'http://localhost/user/42'),
108 cmp_ok $get_user->code, '==', 200,
112 my ($self, $env, @noextra) = eval $get_user->content;
113 is scalar(@noextra), 0, 'No extra stuff';
114 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
115 is ref($env), 'HASH', 'Got hashref';
116 is $env->{SCRIPT_NAME}, $0, 'correct scriptname';
119 ok my $post_user = run_request(POST 'http://localhost/user/42', [id => '99'] ),
122 cmp_ok $post_user->code, '==', 200,
126 my ($self, $params, $env, @noextra) = eval $post_user->content;
127 is scalar(@noextra), 0, 'No extra stuff';
128 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
129 is ref($params), 'HASH', 'Got POST hashref';
130 is $params->{id}, 99, 'got expected value for id';
131 is ref($env), 'HASH', 'Got hashref';
132 is $env->{SCRIPT_NAME}, $0, 'correct scriptname';