2 use warnings FATAL => 'all';
4 use Data::Dumper::Concise;
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(@_);
23 q(GET + /user) => sub {
24 $self->show_users(@_);
30 sub (POST + %:id=&:@roles~) {
31 $self->process_post(@_);
38 my ($self, @args) = @_;
39 local $self->{_dispatcher};
41 200, ['Content-Type' => 'application/perl' ],
46 my ($self, @args) = @_;
47 local $self->{_dispatcher};
49 200, ['Content-Type' => 'application/perl' ],
54 my ($self, @args) = @_;
55 local $self->{_dispatcher};
57 200, ['Content-Type' => 'application/perl' ],
62 my ($self, @args) = @_;
63 local $self->{_dispatcher};
65 200, ['Content-Type' => 'application/perl' ],
71 ok my $app = t::Web::Simple::SubDispatchArgs->new,
75 my @args = (shift, SCRIPT_NAME=> $0);
76 my $c = HTTP::Request::AsCGI->new(@args)->setup;
82 use HTTP::Request::Common qw(GET POST);
84 ok my $get_landing = run_request(GET 'http://localhost/' ),
87 cmp_ok $get_landing->code, '==', 200,
91 my ($self, $env, @noextra) = @{eval $get_landing->content};
93 is scalar(@noextra), 0, 'No extra stuff';
94 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
95 is ref($env), 'HASH', 'Got hashref';
96 is $env->{SCRIPT_NAME}, $0, 'correct scriptname';
99 ok my $get_users = run_request(GET 'http://localhost/user'),
102 cmp_ok $get_users->code, '==', 200,
106 my ($self, $env, @noextra) = @{eval $get_users->content};
107 is scalar(@noextra), 0, 'No extra stuff';
108 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
109 is ref($env), 'HASH', 'Got hashref';
110 is $env->{SCRIPT_NAME}, $0, 'correct scriptname';
113 ok my $get_user = run_request(GET 'http://localhost/user/42'),
116 cmp_ok $get_user->code, '==', 200,
120 my ($self, $env, @noextra) = @{eval $get_user->content};
121 is scalar(@noextra), 0, 'No extra stuff';
122 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
123 is ref($env), 'HASH', 'Got hashref';
124 is $env->{SCRIPT_NAME}, $0, 'correct scriptname';
127 ok my $post_user = run_request(POST 'http://localhost/user/42', [id => '99'] ),
130 cmp_ok $post_user->code, '==', 200,
134 my ($self, $params, $env, @noextra) = @{eval $post_user->content};
135 is scalar(@noextra), 0, 'No extra stuff';
136 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
137 is ref($params), 'HASH', 'Got POST hashref';
138 is $params->{id}, 99, 'got expected value for id';
139 is ref($env), 'HASH', 'Got hashref';
140 is $env->{SCRIPT_NAME}, $0, 'correct scriptname';