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};
37 local $args[-1]->{'Web::Dispatch.original_env'};
39 200, ['Content-Type' => 'application/perl' ],
44 my ($self, @args) = @_;
45 local $self->{_dispatcher};
46 local $args[-1]->{'Web::Dispatch.original_env'};
48 200, ['Content-Type' => 'application/perl' ],
53 my ($self, @args) = @_;
54 local $self->{_dispatcher};
55 local $args[-1]->{'Web::Dispatch.original_env'};
57 200, ['Content-Type' => 'application/perl' ],
62 my ($self, @args) = @_;
63 local $self->{_dispatcher};
64 local $args[-1]->{'Web::Dispatch.original_env'};
66 200, ['Content-Type' => 'application/perl' ],
72 ok my $app = t::Web::Simple::SubDispatchArgs->new,
75 sub run_request { $app->run_test_request(@_); }
77 ok my $get_landing = run_request(GET => 'http://localhost/' ),
80 cmp_ok $get_landing->code, '==', 200,
86 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';
93 ok my $get_users = run_request(GET => 'http://localhost/user'),
96 cmp_ok $get_users->code, '==', 200,
100 my ($self, $env, @noextra) = @{eval $get_users->content};
101 is scalar(@noextra), 0, 'No extra stuff';
102 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
103 is ref($env), 'HASH', 'Got hashref';
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';
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';