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;
11 use Web::Dispatch::Predicates;
13 has 'attr' => (is=>'ro');
15 sub dispatch_request {
18 match_path(qr/(?-xism:^(\/)$)/), sub {
19 $self->show_landing(@_);
22 match_path_strip(qr/(?-xism:^()(\/.*)$)/) => sub {
26 match_path(qr/(?-xism:^(\/user(?:\.\w+)?)$)/)
28 $self->show_users(@_);
30 match_path(qr/(?-xism:^(\/user\/([^\/]+?)(?:\.\w+)?)$)/), sub {
31 match_method('GET') => sub {
52 $self->process_post(@_);
59 my ($self, @args) = @_;
60 local $self->{_dispatcher};
61 local $args[-1]->{'Web::Dispatch.original_env'};
63 200, ['Content-Type' => 'application/perl' ],
68 my ($self, @args) = @_;
69 local $self->{_dispatcher};
70 local $args[-1]->{'Web::Dispatch.original_env'};
72 200, ['Content-Type' => 'application/perl' ],
77 my ($self, @args) = @_;
78 local $self->{_dispatcher};
79 local $args[-1]->{'Web::Dispatch.original_env'};
81 200, ['Content-Type' => 'application/perl' ],
86 my ($self, @args) = @_;
87 local $self->{_dispatcher};
88 local $args[-1]->{'Web::Dispatch.original_env'};
90 200, ['Content-Type' => 'application/perl' ],
96 ok my $app = t::Web::Simple::SubDispatchArgs->new,
99 sub run_request { $app->run_test_request(@_); }
101 ok my $get_landing = run_request(GET => 'http://localhost/' ),
104 cmp_ok $get_landing->code, '==', 200,
110 my ($self, $env, @noextra) = @{eval($get_landing->content)||[]};
112 is scalar(@noextra), 0, 'No extra stuff';
113 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
114 is ref($env), 'HASH', 'Got hashref';
117 ok my $get_users = run_request(GET => 'http://localhost/user'),
120 cmp_ok $get_users->code, '==', 200,
124 my ($self, $env, @noextra) = @{eval $get_users->content};
125 is scalar(@noextra), 0, 'No extra stuff';
126 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
127 is ref($env), 'HASH', 'Got hashref';
130 ok my $get_user = run_request(GET => 'http://localhost/user/42'),
133 cmp_ok $get_user->code, '==', 200,
137 my ($self, $env, @noextra) = @{eval $get_user->content};
138 is scalar(@noextra), 0, 'No extra stuff';
139 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
140 is ref($env), 'HASH', 'Got hashref';
143 ok my $post_user = run_request(POST => 'http://localhost/user/42', [id => '99'] ),
146 cmp_ok $post_user->code, '==', 200,
150 my ($self, $params, $env, @noextra) = @{eval $post_user->content};
151 is scalar(@noextra), 0, 'No extra stuff';
152 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
153 is ref($params), 'HASH', 'Got POST hashref';
154 is $params->{id}, 99, 'got expected value for id';
155 is ref($env), 'HASH', 'Got hashref';