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 {
17 match_path(qr/(?^:^(\/)$)/), sub {
18 $self->show_landing(@_);
20 match_path_strip(qr/(?^:^()(\/.*)$)/) => sub {
24 match_path(qr/(?^:^(\/user(?:\.\w+)?)$)/)
26 $self->show_users(@_);
28 match_path(qr/(?^:^(\/user\/([^\/]+?)(?:\.\w+)?)$)/), sub {
29 match_method('GET') => sub {
50 $self->process_post(@_);
57 my ($self, @args) = @_;
58 local $self->{_dispatcher};
59 local $args[-1]->{'Web::Dispatch.original_env'};
61 200, ['Content-Type' => 'application/perl' ],
66 my ($self, @args) = @_;
67 local $self->{_dispatcher};
68 local $args[-1]->{'Web::Dispatch.original_env'};
70 200, ['Content-Type' => 'application/perl' ],
75 my ($self, @args) = @_;
76 local $self->{_dispatcher};
77 local $args[-1]->{'Web::Dispatch.original_env'};
79 200, ['Content-Type' => 'application/perl' ],
84 my ($self, @args) = @_;
85 local $self->{_dispatcher};
86 local $args[-1]->{'Web::Dispatch.original_env'};
88 200, ['Content-Type' => 'application/perl' ],
94 ok my $app = t::Web::Simple::SubDispatchArgs->new,
97 sub run_request { $app->run_test_request(@_); }
99 ok my $get_landing = run_request(GET => 'http://localhost/' ),
102 cmp_ok $get_landing->code, '==', 200,
108 my ($self, $env, @noextra) = @{eval($get_landing->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 $get_users = run_request(GET => 'http://localhost/user'),
118 cmp_ok $get_users->code, '==', 200,
122 my ($self, $env, @noextra) = @{eval $get_users->content};
123 is scalar(@noextra), 0, 'No extra stuff';
124 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
125 is ref($env), 'HASH', 'Got hashref';
128 ok my $get_user = run_request(GET => 'http://localhost/user/42'),
131 cmp_ok $get_user->code, '==', 200,
135 my ($self, $env, @noextra) = @{eval $get_user->content};
136 is scalar(@noextra), 0, 'No extra stuff';
137 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
138 is ref($env), 'HASH', 'Got hashref';
141 ok my $post_user = run_request(POST => 'http://localhost/user/42', [id => '99'] ),
144 cmp_ok $post_user->code, '==', 200,
148 my ($self, $params, $env, @noextra) = @{eval $post_user->content};
149 is scalar(@noextra), 0, 'No extra stuff';
150 is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
151 is ref($params), 'HASH', 'Got POST hashref';
152 is $params->{id}, 99, 'got expected value for id';
153 is ref($env), 'HASH', 'Got hashref';