diff options
Diffstat (limited to 'lib/Dancer2/Core/DSL.pm')
-rw-r--r-- | lib/Dancer2/Core/DSL.pm | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/lib/Dancer2/Core/DSL.pm b/lib/Dancer2/Core/DSL.pm index 53dab17a..6b5dad6f 100644 --- a/lib/Dancer2/Core/DSL.pm +++ b/lib/Dancer2/Core/DSL.pm @@ -1,11 +1,11 @@ # ABSTRACT: Dancer2's Domain Specific Language (DSL) package Dancer2::Core::DSL; -$Dancer2::Core::DSL::VERSION = '1.0.0'; +$Dancer2::Core::DSL::VERSION = '1.1.0'; 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; @@ -122,6 +122,7 @@ sub dsl_keywords { true => { is_global => 1 }, upload => { is_global => 0 }, uri_for => { is_global => 0 }, + uri_for_route => { is_global => 0 }, var => { is_global => 0 }, vars => { is_global => 0 }, warning => { is_global => 1 }, @@ -241,11 +242,26 @@ sub _normalize_route { my $methods = shift; my %args; - # Options are optional, deduce their presence from arg length. - # @_ = ( REGEXP, OPTIONS, CODE ) - # or - # @_ = ( REGEXP, CODE ) - @args{qw/regexp options code/} = @_ == 3 ? @_ : ( $_[0], {}, $_[1] ); + # Options are optional, try to deduce their presence from arg length. + if ( @_ == 4 ) { + # @_ = ( NAME, REGEXP, OPTIONS, CODE ) + # get 'foo', '/foo', { 'user_agent' => '...' }, sub {...} + @args{qw<name regexp options code>} = @_; + } elsif ( @_ == 2 ) { + # @_ = ( REGEXP, CODE ) + # get '/foo', sub {...} + @args{qw<regexp code>} = @_; + } elsif ( @_ == 3 ) { + # @_ = ( REGEXP, OPTIONS, CODE ) + # get '/foo', { 'user_agent' => '...' }, sub {...} + # @_ = ( NAME, REGEXP, CODE ) + # get 'foo', '/foo',sub {...} + if ( is_hashref( $_[1] ) ) { + @args{qw<regexp options code>} = @_; + } else { + @args{qw<name regexp code>} = @_; + } + } return map $app->add_route( %args, method => $_ ), @{$methods}; } @@ -414,6 +430,8 @@ sub captures { $Dancer2::Core::Route::REQUEST->captures } sub uri_for { shift; $Dancer2::Core::Route::REQUEST->uri_for(@_); } +sub uri_for_route { shift->app->uri_for_route(@_); } + sub splat { $Dancer2::Core::Route::REQUEST->splat } sub params { shift; $Dancer2::Core::Route::REQUEST->params(@_); } @@ -515,7 +533,7 @@ Dancer2::Core::DSL - Dancer2's Domain Specific Language (DSL) =head1 VERSION -version 1.0.0 +version 1.1.0 =head1 FUNCTIONS |