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 {
18 $self->show_landing(@_);
22 $self->show_users(@_);
28 sub (POST + %:id=&:@roles~) {
29 $self->process_post(@_);
36 my ($self, @args) = @_;
38 200, ['Content-Type' => 'application/perl' ],
39 [Data::Dump::dump @args],
43 my ($self, @args) = @_;
45 200, ['Content-Type' => 'application/perl' ],
46 [Data::Dump::dump @args],
50 my ($self, @args) = @_;
52 200, ['Content-Type' => 'application/perl' ],
53 [Data::Dump::dump @args],
57 my ($self, @args) = @_;
59 200, ['Content-Type' => 'application/perl' ],
60 [Data::Dump::dump @args],
65 ok my $app = t::Web::Simple::SubDispatchArgs->new,
69 my @args = (shift, SCRIPT_NAME=> $0);
70 my $c = HTTP::Request::AsCGI->new(@args)->setup;
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,
85 my ($self, $env, @noextra) = eval $get_landing->content;
86 is scalar(@noextra), 0, 'No extra stuff';
87 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
88 is ref($env), 'HASH', 'Got hashref';
89 is $env->{SCRIPT_NAME}, $0, 'correct scriptname';
92 ok my $get_users = run_request(GET 'http://localhost/user'),
95 cmp_ok $get_users->code, '==', 200,
99 my ($self, $env, @noextra) = eval $get_users->content;
100 is scalar(@noextra), 0, 'No extra stuff';
101 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
102 is ref($env), 'HASH', 'Got hashref';
103 is $env->{SCRIPT_NAME}, $0, 'correct scriptname';
106 ok my $get_user = run_request(GET 'http://localhost/user/42'),
109 cmp_ok $get_user->code, '==', 200,
113 my ($self, $env, @noextra) = eval $get_user->content;
114 is scalar(@noextra), 0, 'No extra stuff';
115 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
116 is ref($env), 'HASH', 'Got hashref';
117 is $env->{SCRIPT_NAME}, $0, 'correct scriptname';
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';
133 is $env->{SCRIPT_NAME}, $0, 'correct scriptname';