From: John Napiorkowski Date: Mon, 27 Apr 2015 15:17:06 +0000 (-0500) Subject: a bit of cleanup as we ponder stable X-Git-Tag: 5.90089_003~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=905679b8b9419c22d08e327cfc36f291b98e59c0 a bit of cleanup as we ponder stable --- diff --git a/Changes b/Changes index decb05b..a9daad4 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ # This file documents the revision history for Perl extension Catalyst. +5.90089_003 - TBA + - Fixed an issue where a delayed controller that did ACCEPT_CONTEXT would + raise an error when registering its actions. + 5.90089_002 - 2015-04-17 - Changed the way we check for presence of Type::Tiny in a test case to be more explicit in the version requirement. Hopefully a fix for reported diff --git a/lib/Catalyst/Component/DelayedInstance.pm b/lib/Catalyst/Component/DelayedInstance.pm deleted file mode 100644 index 06096e7..0000000 --- a/lib/Catalyst/Component/DelayedInstance.pm +++ /dev/null @@ -1,94 +0,0 @@ -package Catalyst::Component::DelayedInstance; - -use Moose::Role; - -around 'COMPONENT', sub { - my ($orig, $class, $app, $conf) = @_; - my $method = $class->can('build_delayed_instance') ? - 'build_delayed_instance' : 'COMPONENT'; - - return bless sub { my $c = shift; $class->$method($app, $conf) }, $class; -}; - -our $SINGLE; - -sub ACCEPT_CONTEXT { - my ($self, $c, @args) = @_; - $c->log->warn("Component ${\$self->catalyst_component_name} cannot be called with arguments") - if $c->debug and scalar(@args) > 0; - - return $SINGLE ||= $self->(); -} - -sub AUTOLOAD { - my ($self, @args) = @_; - my $method = our $AUTOLOAD; - $method =~ s/.*:://; - - warn $method; - use Devel::Dwarn; - Dwarn \@args; - - return ($SINGLE ||= $self->())->$method(@args); -} - -1; - -=head1 NAME - -Catalyst::Component::DelayedInstance - Moose Role for components which setup - -=head1 SYNOPSIS - - package MyApp::Model::Foo; - - use Moose; - extends 'Catalyst::Model'; - with 'Catalyst::Component::DelayedInstance'; - - sub build_per_application_instance { - my ($class, $app, $config) = @_; - - $config->{bar} = $app->model("Baz"); - return $class->new($config); - } - -=head1 DESCRIPTION - -Sometimes you want an application scoped component that nevertheless needs other -application components as part of its setup. In the past this was not reliable -since Application scoped components are setup in linear order. You could not -call $app->model in a COMPONENT method and expect 'Foo' to be there. This role -defers creating the application scoped instance until after your application is -fully setup. This means you can now assume your other application scoped components -(components that do COMPONENT but not ACCEPT_CONTEXT) are available as dependencies. - -Please note this means that your instance is not created until the first time its -called in a request. As a result any errors with configuration will not show up -until later in runtime. So there is a larger burden on your testing to make sure -your application startup and runtime is accurate. Also note that even though your -instance creation is deferred to request time, the request context is NOT given, -but the application is (this means that you cannot depend on components that do -ACCEPT_CONTEXT, since you don't have one...). - -=head1 ATTRIBUTES - -=head1 METHODS - -=head2 ACCEPT_CONTEXT - -=head2 AUTOLOAD - -=head1 SEE ALSO - -L, - -=head1 AUTHORS - -See L. - -=head1 COPYRIGHT - -See L. - -=cut diff --git a/lib/Catalyst/DispatchType/Chained.pm b/lib/Catalyst/DispatchType/Chained.pm index dc9d1a3..2ac8c0c 100644 --- a/lib/Catalyst/DispatchType/Chained.pm +++ b/lib/Catalyst/DispatchType/Chained.pm @@ -247,6 +247,8 @@ sub recurse_match { } my @try_actions = @{$children->{$try_part}}; TRY_ACTION: foreach my $action (@try_actions) { + + if (my $capture_attr = $action->attributes->{CaptureArgs}) { my $capture_count = $action->number_of_captures|| 0; @@ -287,6 +289,8 @@ sub recurse_match { else { { local $c->req->{arguments} = [ @{$c->req->args}, @parts ]; +warn $action; + next TRY_ACTION unless $action->match($c); } my $args_attr = $action->attributes->{Args}->[0]; @@ -298,7 +302,6 @@ sub recurse_match { # OR No parts and this expects 0 # The current best action might also be Args(0), # but we couldn't chose between then anyway so we'll take the last seen - if ( !$best_action || @parts < @{$best_action->{parts}} || diff --git a/t/args0_bug.t b/t/args0_bug.t index 71f2512..1d498e5 100644 --- a/t/args0_bug.t +++ b/t/args0_bug.t @@ -15,9 +15,11 @@ use Test::More; sub chained_one_args_0 : Chained(chain_base) PathPart('') Args(1) { $_[1]->res->body('chained_one_args_0') } sub chained_one_args_1 : Chained(chain_base) PathPart('') Args(1) { $_[1]->res->body('chained_one_args_1') } + sub chained_one_args_2 : Chained(chain_base) PathPart('') Args(1) { $_[1]->res->body('chained_one_args_2') } sub chained_zero_args_0 : Chained(chain_base) PathPart('') Args(0) { $_[1]->res->body('chained_zero_args_0') } sub chained_zero_args_1 : Chained(chain_base) PathPart('') Args(0) { $_[1]->res->body('chained_zero_args_1') } + sub chained_zero_args_2 : Chained(chain_base) PathPart('') Args(0) { $_[1]->res->body('chained_zero_args_2') } MyApp::Controller::Root->config(namespace=>''); @@ -49,12 +51,12 @@ use Test::More; use Catalyst::Test 'MyApp'; { my $res = request '/chain_base/capturearg/arg'; - is $res->content, 'chained_one_args_1', "request '/chain_base/capturearg/arg'"; + is $res->content, 'chained_one_args_2', "request '/chain_base/capturearg/arg'"; } { my $res = request '/chain_base/capturearg'; - is $res->content, 'chained_zero_args_1', "request '/chain_base/capturearg'"; + is $res->content, 'chained_zero_args_2', "request '/chain_base/capturearg'"; } done_testing; diff --git a/t/set_allowed_method.t b/t/set_allowed_method.t new file mode 100644 index 0000000..7a9ce1b --- /dev/null +++ b/t/set_allowed_method.t @@ -0,0 +1,32 @@ +use warnings; +use strict; +use Test::More; + +# Test case for reported issue when an action consumes JSON but a +# POST sends nothing we get a hard error + +{ + package MyApp::Controller::Root; + $INC{'MyApp/Controller/Root.pm'} = __FILE__; + + use base 'Catalyst::Controller'; + + sub root :Chained(/) CaptureArgs(0) { } + + sub get :GET Chained(root) PathPart('') Args(0) { } + sub post :POST Chained(root) PathPart('') Args(0) { } + sub put :PUT Chained(root) PathPart('') Args(0) { } + + package MyApp; + use Catalyst; + MyApp->setup; +} + +use HTTP::Request::Common; +use Catalyst::Test 'MyApp'; + +{ + ok my $res = request POST 'root/'; +} + +done_testing();