Skip to content

Commit

Permalink
Document new trailing slashes behaviour
Browse files Browse the repository at this point in the history
Added the documentation test cases to the test suite.

Signed-off-by: Pedro Melo <melo@simplicidade.org>
  • Loading branch information
melo committed Jan 7, 2013
1 parent 2a58680 commit bdd2292
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
39 changes: 27 additions & 12 deletions lib/Mason/Manual/RequestDispatch.pod
Expand Up @@ -73,29 +73,44 @@ dhandlers is to match partial paths.


=head2 Trailing slash =head2 Trailing slash


If the request URL has a trailing slash (ends with C</>), we remove it before If the request URL has a trailing slash (ends with C</>), we remove it
the match process begins and add it to the C<< $m->path_info >>. Components before the match process begins. If your component has
that should match must have C<allow_path_info> return true. 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: For example:


## request URL /news/ ## request URL /news/
/news/index.{mp,mc} # $m->path_info = / if index.{mp,mc} has /news/index.{mp,mc} # $m->path_info = '' if allow_path_info => false
# allow_path_info => true /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 /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 # allow_path_info => true


## request URL /news/sports/ ## 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 # 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 # 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 # has allow_path_info => true



=head2 Routes =head2 Routes


It is possible to use route syntax to more elegantly parse C<< $m->path_info >> It is possible to use route syntax to more elegantly parse C<< $m->path_info >>
Expand Down
22 changes: 20 additions & 2 deletions lib/Mason/t/ResolveURI.pm
Expand Up @@ -9,6 +9,8 @@ sub test_resolve : Tests {
my ( $run_path, $existing_paths, $resolve_path, $path_info ) = @_; my ( $run_path, $existing_paths, $resolve_path, $path_info ) = @_;
$path_info ||= ''; $path_info ||= '';


my ($line) = (caller)[2];

$self->setup_dirs(@interp_params); $self->setup_dirs(@interp_params);
foreach (@$existing_paths) { foreach (@$existing_paths) {
my $existing_path = $_; my $existing_path = $_;
Expand All @@ -27,12 +29,12 @@ sub test_resolve : Tests {
my $desc = sprintf( "run %s against %s", $run_path, join( ",", @$existing_paths ) ); my $desc = sprintf( "run %s against %s", $run_path, join( ",", @$existing_paths ) );
if ( defined($resolve_path) ) { if ( defined($resolve_path) ) {
my $good = "path: $resolve_path; path_info: $path_info"; 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 { else {
throws_ok { $self->interp->run($run_path)->output } throws_ok { $self->interp->run($run_path)->output }
qr/could not resolve request path/, qr/could not resolve request path/,
"$desc = failed to match"; "$desc = failed to match ($line)";
} }
}; };


Expand Down Expand Up @@ -107,6 +109,22 @@ sub test_resolve : Tests {
$try->( '/foo/', ['/foo/dhandler', '/foo/index=1'], '/foo/index', '/' ); $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'], '/foo/dhandler', 'more' );
$try->( '/foo/more', ['/foo/dhandler', '/foo/index=1'], '/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 { sub test_decline : Tests {
Expand Down

0 comments on commit bdd2292

Please sign in to comment.