diff --git a/lib/Dancer2/Core/App.pm b/lib/Dancer2/Core/App.pm index fb447c8ea..947824fb4 100644 --- a/lib/Dancer2/Core/App.pm +++ b/lib/Dancer2/Core/App.pm @@ -10,7 +10,6 @@ use Safe::Isa; use Sub::Quote; use File::Spec; use Module::Runtime qw< require_module use_module >; -use List::Util (); use Ref::Util qw< is_ref is_arrayref is_globref is_scalarref is_regexpref >; use Plack::App::File; diff --git a/lib/Dancer2/Core/DSL.pm b/lib/Dancer2/Core/DSL.pm index d286e1b5d..d6e7fac94 100644 --- a/lib/Dancer2/Core/DSL.pm +++ b/lib/Dancer2/Core/DSL.pm @@ -5,7 +5,7 @@ package Dancer2::Core::DSL; use Moo; use Carp; use Module::Runtime 'require_module'; -use Ref::Util qw< is_arrayref >; +use Ref::Util qw< is_arrayref is_hashref >; use Dancer2::Core::Hook; use Dancer2::FileUtils; use Dancer2::Core::Response::Delayed; @@ -253,10 +253,10 @@ sub _normalize_route { @args{qw} = ( $_[0], {}, $_[1] ); } elsif ( @_ == 3 ) { # @_ = ( REGEXP, OPTIONS, CODE ) - # get '/foo', { 'user_agent' => '...', sub {...} + # get '/foo', { 'user_agent' => '...' }, sub {...} # @_ = ( NAME, REGEXP, CODE ) # get 'foo', '/foo',sub {...} - if (ref $_[1] eq 'HASH') { + if ( is_hashref( $_[1] ) ) { @args{qw} = @_; } else { @args{qw} = @_; diff --git a/lib/Dancer2/Core/Route.pm b/lib/Dancer2/Core/Route.pm index caec9dbb8..48f0159ba 100644 --- a/lib/Dancer2/Core/Route.pm +++ b/lib/Dancer2/Core/Route.pm @@ -12,8 +12,6 @@ use Type::Registry; our ( $REQUEST, $RESPONSE, $RESPONDER, $WRITER, $ERROR_HANDLER ); -my $count = 0; - has name => ( is => 'ro', isa => Str, diff --git a/lib/Dancer2/Manual.pod b/lib/Dancer2/Manual.pod index bbf9217cf..42b095251 100644 --- a/lib/Dancer2/Manual.pod +++ b/lib/Dancer2/Manual.pod @@ -218,7 +218,7 @@ You can also provide routes with a name: get 'hi_to' => '/hello/:name' => sub {...}; -See C on how this can be used. +See L on how this can be used. =head3 Retrieving request parameters diff --git a/lib/Dancer2/Manual/Keywords.pod b/lib/Dancer2/Manual/Keywords.pod index ebdf02623..a070d720a 100644 --- a/lib/Dancer2/Manual/Keywords.pod +++ b/lib/Dancer2/Manual/Keywords.pod @@ -1182,7 +1182,7 @@ URL encoding via a third parameter: =head2 uri_for_route -An enhanced version of C that utilizes their names. +An enhanced version of C that utilizes routes' names. get 'view_entry' => '/entry/view/:id' => sub {...}; @@ -1267,19 +1267,35 @@ second argument: (Technically, only C requests should include query parameters, but C does not enforce this.) -=item * Escaping +=item * Disable URI escaping -The final parameter determines whether the URI will be URI-escaped: +The final parameter determines whether the URI will be URI-escaped or not: get 'show_entry' => '/view/:str_id' => sub {1}; # ... - $path = uri_for_route( 'show_entry' => { 'str_id' => '!£%^@' }, {}, 1 ); - # $path = http://localhost/view/!@%C3%82%C2%A3$% + $path = uri_for_route( + 'show_entry', + { 'str_id' => '...' }, + {}, + ); + # $path = http://localhost/view/%3Cjavascript%3E... This is useful when your ID is not HTML-safe and might include HTML tags and Javascript code or include characters that interfere with the URI request string (like a forward slash). +This is on by default, but you can disable it by setting this flag: + + get 'show_entry' => '/view/:str_id' => sub {1}; + # ... + $path = uri_for_route( + 'show_entry', + { 'str_id' => '...' }, + {}, + 1, + ); + # $path = http://localhost/view/... + =back =head2 var