From: John Napiorkowski Date: Thu, 29 Oct 2015 15:22:19 +0000 (-0500) Subject: Merge branch '104-path_empty_brackets' of https://github.com/grim8634/catalyst-runtim... X-Git-Tag: 5.90102~3^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=161710a39409d2afd256463471b8014a1c69adf4;hp=b8373df33c55813aeee1cc09c8fa0056846a7a6e Merge branch '104-path_empty_brackets' of https://github.com/grim8634/catalyst-runtime into grim8634-104-path_empty_brackets --- diff --git a/lib/Catalyst/Action.pm b/lib/Catalyst/Action.pm index 3497e21..ea3e3e4 100644 --- a/lib/Catalyst/Action.pm +++ b/lib/Catalyst/Action.pm @@ -52,7 +52,9 @@ has number_of_args => ( if( ! exists $self->attributes->{Args} ) { # When 'Args' does not exist, that means we want 'any number of args'. return undef; - } elsif(!defined($self->attributes->{Args}[0])) { + } elsif( + !defined($self->attributes->{Args}[0]) || + $self->attributes->{Args}[0] eq '' ) { # When its 'Args' that internal cue for 'unlimited' return undef; } elsif( @@ -138,6 +140,7 @@ has args_constraints => ( return [] unless scalar(@arg_protos); return [] unless defined($arg_protos[0]); + return [] if ($arg_protos[0] eq '' && scalar(@arg_protos) == 1); # If there is only one arg and it looks like a number # we assume its 'classic' and the number is the number of diff --git a/lib/Catalyst/Controller.pm b/lib/Catalyst/Controller.pm index b1a9bef..b50a2ff 100644 --- a/lib/Catalyst/Controller.pm +++ b/lib/Catalyst/Controller.pm @@ -389,7 +389,7 @@ sub _parse_attrs { # Parse out :Foo(bar) into Foo => bar etc (and arrayify) - if ( my ( $key, $value ) = ( $attr =~ /^(.*?)(?:\(\s*(.+?)\s*\))?$/ ) ) + if ( my ( $key, $value ) = ( $attr =~ /^(.*?)(?:\(\s*(.*?)\s*\))?$/ ) ) { if ( defined $value ) { diff --git a/t/lib/TestPath.pm b/t/lib/TestPath.pm new file mode 100644 index 0000000..ae14557 --- /dev/null +++ b/t/lib/TestPath.pm @@ -0,0 +1,8 @@ +package TestPath; +use strict; +use warnings; +use Catalyst; + +__PACKAGE__->setup; + +1; diff --git a/t/lib/TestPath/Controller/Four.pm b/t/lib/TestPath/Controller/Four.pm new file mode 100644 index 0000000..b7426b5 --- /dev/null +++ b/t/lib/TestPath/Controller/Four.pm @@ -0,0 +1,12 @@ +package TestPath::Controller::Four; +use Moose; +use namespace::autoclean; + +BEGIN { extends 'Catalyst::Controller' } + +sub four :Path('') :Args() { + my ( $self, $c ) = @_; + $c->response->body( 'OK' ); +} + +__PACKAGE__->meta->make_immutable; \ No newline at end of file diff --git a/t/lib/TestPath/Controller/One.pm b/t/lib/TestPath/Controller/One.pm new file mode 100644 index 0000000..5c23b23 --- /dev/null +++ b/t/lib/TestPath/Controller/One.pm @@ -0,0 +1,12 @@ +package TestPath::Controller::One; +use Moose; +use namespace::autoclean; + +BEGIN { extends 'Catalyst::Controller' } + +sub one :Path { + my ( $self, $c ) = @_; + $c->response->body( 'OK' ); +} + +__PACKAGE__->meta->make_immutable; \ No newline at end of file diff --git a/t/lib/TestPath/Controller/Three.pm b/t/lib/TestPath/Controller/Three.pm new file mode 100644 index 0000000..09f5a5d --- /dev/null +++ b/t/lib/TestPath/Controller/Three.pm @@ -0,0 +1,12 @@ +package TestPath::Controller::Three; +use Moose; +use namespace::autoclean; + +BEGIN { extends 'Catalyst::Controller' } + +sub three :Path('') { + my ( $self, $c ) = @_; + $c->response->body( 'OK' ); +} + +__PACKAGE__->meta->make_immutable; \ No newline at end of file diff --git a/t/lib/TestPath/Controller/Two.pm b/t/lib/TestPath/Controller/Two.pm new file mode 100644 index 0000000..b5373df --- /dev/null +++ b/t/lib/TestPath/Controller/Two.pm @@ -0,0 +1,12 @@ +package TestPath::Controller::Two; +use Moose; +use namespace::autoclean; + +BEGIN { extends 'Catalyst::Controller' } + +sub two :Path() { + my ( $self, $c ) = @_; + $c->response->body( 'OK' ); +} + +__PACKAGE__->meta->make_immutable; \ No newline at end of file diff --git a/t/path_action_empty_brackets.t b/t/path_action_empty_brackets.t new file mode 100644 index 0000000..5d100d5 --- /dev/null +++ b/t/path_action_empty_brackets.t @@ -0,0 +1,30 @@ +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/lib"; + +use Test::More tests => 12; +use Catalyst::Test 'TestPath'; + + +{ + ok( my $response = request('http://localhost/one'), 'Request' ); + ok( $response->is_success, '"Path" - Response Successful 2xx' ); + is( $response->content, 'OK', '"Path" - Body okay' ); +} +{ + ok( my $response = request('http://localhost/two'), 'Request' ); + ok( $response->is_success, '"Path()" - Response Successful 2xx' ); + is( $response->content, 'OK', '"Path()" - Body okay' ); +} +{ + ok( my $response = request('http://localhost/three'), 'Request' ); + ok( $response->is_success, '"Path(\'\')" - Response Successful 2xx' ); + is( $response->content, 'OK', '"Path(\'\')" - Body okay' ); +} +{ + ok( my $response = request('http://localhost/four'), 'Request' ); + ok( $response->is_success, '"Path(\'\')" - Response Successful 2xx' ); + is( $response->content, 'OK', '"Path() Args()" - Body okay' ); +} \ No newline at end of file