| 1 | use strict; |
|---|
| 2 | use warnings; |
|---|
| 3 | use Test::Base; |
|---|
| 4 | use YAML; |
|---|
| 5 | use HTTPx::Dispatcher::Declare; |
|---|
| 6 | use HTTP::Request; |
|---|
| 7 | |
|---|
| 8 | plan tests => 1*blocks; |
|---|
| 9 | |
|---|
| 10 | filters { |
|---|
| 11 | dispatcher => [qw/_eval/], |
|---|
| 12 | uri_for => [qw/eval/], |
|---|
| 13 | expected => [qw//], |
|---|
| 14 | }; |
|---|
| 15 | |
|---|
| 16 | run { |
|---|
| 17 | my $block = shift; |
|---|
| 18 | my $dispatcher = $block->dispatcher; |
|---|
| 19 | is $dispatcher->uri_for( $block->uri_for ), $block->expected; |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | my $cnt = 1; |
|---|
| 23 | sub _eval { |
|---|
| 24 | my ($input, ) = @_; |
|---|
| 25 | my $pkg = "t::Dispatcher::" . ++$cnt; |
|---|
| 26 | |
|---|
| 27 | eval <<"..."; |
|---|
| 28 | package $pkg; |
|---|
| 29 | use HTTPx::Dispatcher::Declare; |
|---|
| 30 | $input; |
|---|
| 31 | ... |
|---|
| 32 | |
|---|
| 33 | return $pkg; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | __END__ |
|---|
| 37 | |
|---|
| 38 | === |
|---|
| 39 | --- dispatcher: connect ':controller/:action/:id'; |
|---|
| 40 | --- uri_for: {controller => 'blog', action => 'show', id => 3} |
|---|
| 41 | --- expected: /blog/show/3 |
|---|
| 42 | |
|---|
| 43 | === |
|---|
| 44 | --- dispatcher: connect 'blog/:action/:id'; |
|---|
| 45 | --- uri_for: {action => 'show', id => 3} |
|---|
| 46 | --- expected: /blog/show/3 |
|---|
| 47 | |
|---|
| 48 | === |
|---|
| 49 | --- dispatcher |
|---|
| 50 | connect 'blog/:action/:id'; |
|---|
| 51 | connect ':controller/:action/:id'; |
|---|
| 52 | --- uri_for: {controller => 'entry', action => 'show', id => 3} |
|---|
| 53 | --- expected: /entry/show/3 |
|---|
| 54 | |
|---|
| 55 | === |
|---|
| 56 | --- dispatcher |
|---|
| 57 | connect 'content/:id' => { controller => 'Content', action => 'show' }; |
|---|
| 58 | --- uri_for: { controller => 'Content', action => 'show', 'id' => 3 } |
|---|
| 59 | --- expected: /content/3 |
|---|
| 60 | |
|---|
| 61 | === |
|---|
| 62 | --- dispatcher |
|---|
| 63 | connect '' => { controller => 'Root', action => 'index' }; |
|---|
| 64 | --- uri_for: { controller => 'Root', action => 'index' } |
|---|
| 65 | --- expected: / |
|---|
| 66 | |
|---|