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 has 'attr' => (is=>'ro');
17 sub dispatch_request {
20 $self->show_landing(@_);
24 $self->show_users(@_);
30 sub (POST + %:id=&:@roles~) {
31 $self->process_post(@_);
38 my ($self, @args) = @_;
40 200, ['Content-Type' => 'application/perl' ],
41 [Data::Dump::dump @args],
45 my ($self, @args) = @_;
47 200, ['Content-Type' => 'application/perl' ],
48 [Data::Dump::dump @args],
52 my ($self, @args) = @_;
54 200, ['Content-Type' => 'application/perl' ],
55 [Data::Dump::dump @args],
59 my ($self, @args) = @_;
61 200, ['Content-Type' => 'application/perl' ],
62 [Data::Dump::dump @args],
67 ok my $app = t::Web::Simple::SubDispatchArgs->new,
71 my @args = (shift, SCRIPT_NAME=> $0);
72 my $c = HTTP::Request::AsCGI->new(@args)->setup;
78 use HTTP::Request::Common qw(GET POST);
80 ok my $get_landing = run_request(GET 'http://localhost/' ),
83 cmp_ok $get_landing->code, '==', 200,
87 my ($self, $env, @noextra) = eval $get_landing->content;
88 is scalar(@noextra), 0, 'No extra stuff';
89 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
90 is ref($env), 'HASH', 'Got hashref';
91 is $env->{SCRIPT_NAME}, $0, 'correct scriptname';
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';
105 is $env->{SCRIPT_NAME}, $0, 'correct scriptname';
108 ok my $get_user = run_request(GET 'http://localhost/user/42'),
111 cmp_ok $get_user->code, '==', 200,
115 my ($self, $env, @noextra) = eval $get_user->content;
116 is scalar(@noextra), 0, 'No extra stuff';
117 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
118 is ref($env), 'HASH', 'Got hashref';
119 is $env->{SCRIPT_NAME}, $0, 'correct scriptname';
122 ok my $post_user = run_request(POST 'http://localhost/user/42', [id => '99'] ),
125 cmp_ok $post_user->code, '==', 200,
129 my ($self, $params, $env, @noextra) = eval $post_user->content;
130 is scalar(@noextra), 0, 'No extra stuff';
131 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
132 is ref($params), 'HASH', 'Got POST hashref';
133 is $params->{id}, 99, 'got expected value for id';
134 is ref($env), 'HASH', 'Got hashref';
135 is $env->{SCRIPT_NAME}, $0, 'correct scriptname';