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};
38 200, ['Content-Type' => 'application/perl' ],
43 my ($self, @args) = @_;
44 local $self->{_dispatcher};
46 200, ['Content-Type' => 'application/perl' ],
51 my ($self, @args) = @_;
52 local $self->{_dispatcher};
54 200, ['Content-Type' => 'application/perl' ],
59 my ($self, @args) = @_;
60 local $self->{_dispatcher};
62 200, ['Content-Type' => 'application/perl' ],
68 ok my $app = t::Web::Simple::SubDispatchArgs->new,
71 sub run_request { $app->run_test_request(@_); }
73 ok my $get_landing = run_request(GET => 'http://localhost/' ),
76 cmp_ok $get_landing->code, '==', 200,
82 my ($self, $env, @noextra) = @{eval($get_landing->content)||[]};
84 is scalar(@noextra), 0, 'No extra stuff';
85 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
86 is ref($env), 'HASH', 'Got hashref';
89 ok my $get_users = run_request(GET => 'http://localhost/user'),
92 cmp_ok $get_users->code, '==', 200,
96 my ($self, $env, @noextra) = @{eval $get_users->content};
97 is scalar(@noextra), 0, 'No extra stuff';
98 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
99 is ref($env), 'HASH', 'Got hashref';
102 ok my $get_user = run_request(GET => 'http://localhost/user/42'),
105 cmp_ok $get_user->code, '==', 200,
109 my ($self, $env, @noextra) = @{eval $get_user->content};
110 is scalar(@noextra), 0, 'No extra stuff';
111 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
112 is ref($env), 'HASH', 'Got hashref';
115 ok my $post_user = run_request(POST => 'http://localhost/user/42', [id => '99'] ),
118 cmp_ok $post_user->code, '==', 200,
122 my ($self, $params, $env, @noextra) = @{eval $post_user->content};
123 is scalar(@noextra), 0, 'No extra stuff';
124 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
125 is ref($params), 'HASH', 'Got POST hashref';
126 is $params->{id}, 99, 'got expected value for id';
127 is ref($env), 'HASH', 'Got hashref';