Permalink
Browse files

Document new trailing slashes behaviour

Added the documentation test cases to the test suite.

Signed-off-by: Pedro Melo <melo@simplicidade.org>
  • Loading branch information...
1 parent 2a58680 commit bdd2292bdbc7a56a903c2cde1d81fcd96cc8371f @melo committed Jan 7, 2013
Showing with 47 additions and 14 deletions.
  1. +27 −12 lib/Mason/Manual/RequestDispatch.pod
  2. +20 −2 lib/Mason/t/ResolveURI.pm
@@ -73,29 +73,44 @@ dhandlers is to match partial paths.
=head2 Trailing slash
-If the request URL has a trailing slash (ends with C</>), we remove it before
-the match process begins and add it to the C<< $m->path_info >>. Components
-that should match must have C<allow_path_info> return true.
+If the request URL has a trailing slash (ends with C</>), we remove it
+before the match process begins. If your component has
+C<allow_path_info> return true or if it is a dhandler, the slash will be
+part of the C<path_info> information.
For example:
## request URL /news/
- /news/index.{mp,mc} # $m->path_info = / if index.{mp,mc} has
- # allow_path_info => true
- /news/dhandler.{mp,mc} # $m->path_info = /
- /news.{mp,mc} # $m->path_info = / if news.{mp,mc} has
+ /news/index.{mp,mc} # $m->path_info = '' if allow_path_info => false
+ /news/index.{mp,mc} # $m->path_info = '/' if allow_path_info => true
+
+ /news/dhandler.{mp,mc} # $m->path_info = '/'
+
+ /news.{mp,mc} # $m->path_info = '' if news.{mp,mc} has
+ # allow_path_info => false
+ /news.{mp,mc} # $m->path_info = '/' if news.{mp,mc} has
# allow_path_info => true
## request URL /news/sports/
- /news/sports/index.{mp,mc} # $m->path_info = / if index.{mp,mc} has
+ /news/sports/index.{mp,mc} # $m->path_info = '' if index.{mp,mc} has
+ # allow_path_info => false
+ /news/sports/index.{mp,mc} # $m->path_info = '/' if index.{mp,mc} has
# allow_path_info => true
- /news/sports/dhandler.{mp,mc} # $m->path_info = /
- /news/sports.{mp,mc} # $m->path_info = / if sports.{mp,mc}
+
+ /news/sports/dhandler.{mp,mc} # $m->path_info = '/'
+
+ /news/sports.{mp,mc} # $m->path_info = '' if sports.{mp,mc}
+ # has allow_path_info => false
+ /news/sports.{mp,mc} # $m->path_info = '/' if sports.{mp,mc}
# has allow_path_info => true
- /news/dhandler.{mp,mc} # $m->path_info = sports/
- /news.{mp,mc} # $m->path_info = /sports/ if news.{mp,mc}
+
+ /news/dhandler.{mp,mc} # $m->path_info = 'sports/'
+
+ /news.{mp,mc} # will not match if allow_path_info => false
+ /news.{mp,mc} # $m->path_info = '/sports/' if news.{mp,mc}
# has allow_path_info => true
+
=head2 Routes
It is possible to use route syntax to more elegantly parse C<< $m->path_info >>
View
@@ -9,6 +9,8 @@ sub test_resolve : Tests {
my ( $run_path, $existing_paths, $resolve_path, $path_info ) = @_;
$path_info ||= '';
+ my ($line) = (caller)[2];
+
$self->setup_dirs(@interp_params);
foreach (@$existing_paths) {
my $existing_path = $_;
@@ -27,12 +29,12 @@ sub test_resolve : Tests {
my $desc = sprintf( "run %s against %s", $run_path, join( ",", @$existing_paths ) );
if ( defined($resolve_path) ) {
my $good = "path: $resolve_path; path_info: $path_info";
- is( $self->interp->run($run_path)->output, $good, "$desc = matched $good" );
+ is( $self->interp->run($run_path)->output, $good, "$desc = matched $good ($line)" );
}
else {
throws_ok { $self->interp->run($run_path)->output }
qr/could not resolve request path/,
- "$desc = failed to match";
+ "$desc = failed to match ($line)";
}
};
@@ -107,6 +109,22 @@ sub test_resolve : Tests {
$try->( '/foo/', ['/foo/dhandler', '/foo/index=1'], '/foo/index', '/' );
$try->( '/foo/more', ['/foo/dhandler', '/foo/index'], '/foo/dhandler', 'more' );
$try->( '/foo/more', ['/foo/dhandler', '/foo/index=1'], '/foo/dhandler', 'more' );
+
+ # trailing slashes: cases from Mason::Manual::RequestDispatch
+ @interp_params = ( dhandler_names => ['dhandler'], index_names => ['index'] );
+ $try->( '/news/', ['/news/index'], '/news/index', '');
+ $try->( '/news/', ['/news/index=1'], '/news/index', '/');
+ $try->( '/news/', ['/news/dhandler'], '/news/dhandler', '/');
+ $try->( '/news/', ['/news.mc'], '/news.mc', '');
+ $try->( '/news/', ['/news.mc=1'], '/news.mc', '/');
+ $try->( '/news/sports/', ['/news/sports/index'], '/news/sports/index', '');
+ $try->( '/news/sports/', ['/news/sports/index=1'], '/news/sports/index', '/');
+ $try->( '/news/sports/', ['/news/sports/dhandler'], '/news/sports/dhandler', '/');
+ $try->( '/news/sports/', ['/news/sports.mc'], '/news/sports.mc', '');
+ $try->( '/news/sports/', ['/news/sports.mc=1'], '/news/sports.mc', '/');
+ $try->( '/news/sports/', ['/news/dhandler'], '/news/dhandler', 'sports/');
+ $try->( '/news/sports/', ['/news.mc'], undef);
+ $try->( '/news/sports/', ['/news.mc=1'], '/news.mc', 'sports/');
}
sub test_decline : Tests {

0 comments on commit bdd2292

Please sign in to comment.