From: Tomas Doran Date: Fri, 21 Aug 2009 19:54:58 +0000 (+0000) Subject: Fix and tests for big issue in 5.80008 X-Git-Tag: 5.80009~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=e7e4c4697a2a0f13fd8d250cb0b6b080013747b5 Fix and tests for big issue in 5.80008 --- diff --git a/Changes b/Changes index 84b0a2a..364e5ce 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,10 @@ # This file documents the revision history for Perl extension Catalyst. + Bug fixes: + - Fix and add tests for generating inner packages inside the COMPONENT + method, and those packages being correctly registered as components. + This fixes Catalyst::Model::DBIC among others. + 5.80008 2009-08-21 17:47:30 Bug fixes: diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 8c891e5..c5f8df5 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1175,7 +1175,7 @@ When used as a string, provides a textual URI. If the first argument is a string, it is taken as a public URI path relative to C<< $c->namespace >> (if it doesn't begin with a forward slash) or -relative to the application root (if it does). It is then merged with +relative to the application root (if it does). It is then merged with C<< $c->request->base >>; any C<@args> are appended as additional path components; and any C<%query_values> are appended as C parameters. @@ -1187,13 +1187,13 @@ once the path is resolved, C continues as though a path was provided, appending any arguments or parameters and creating an absolute URI. -The captures for the current request can be found in +The captures for the current request can be found in C<< $c->request->captures >>, and actions can be resolved using C<< Catalyst::Controller->action_for($name) >>. If you have a private action path, use C<< $c->uri_for_action >> instead. # Equivalent to $c->req->uri - $c->uri_for($c->action, $c->req->captures, + $c->uri_for($c->action, $c->req->captures, @{ $c->req->args }, $c->req->params); # For the Foo action in the Bar controller @@ -2172,9 +2172,12 @@ sub setup_components { $class->_controller_init_base_classes($component); } - for my $component (uniq map { $class->expand_component_module( $_, $config ) } @comps ) { - $class->_controller_init_base_classes($component); # Also cover inner packages + for my $component (@comps) { $class->components->{ $component } = $class->setup_component($component); + for my $component ($class->expand_component_module( $component, $config )) { + $class->_controller_init_base_classes($component); # Also cover inner packages + $class->components->{ $component } = $class->setup_component($component); + } } } @@ -2214,15 +2217,11 @@ sub locate_components { Components found by C will be passed to this method, which is expected to return a list of component (package) names to be set up. -By default, this method will return the component itself as well as any inner -packages found by L. - =cut sub expand_component_module { my ($class, $module) = @_; - my @inner = Devel::InnerPackage::list_packages( $module ); - return ($module, @inner); + Devel::InnerPackage::list_packages( $module ); } =head2 $c->setup_component diff --git a/t/unit_core_component_loading.t b/t/unit_core_component_loading.t index 42f1eac..55ecda0 100644 --- a/t/unit_core_component_loading.t +++ b/t/unit_core_component_loading.t @@ -2,7 +2,7 @@ # (do not forget to update the number of components in test 3 as well) # 5 extra tests for the loading options # One test for components in inner packages -use Test::More tests => 2 + 6 * 24 + 5 + 1; +use Test::More tests => 2 + 6 * 24 + 7 + 1; use strict; use warnings; @@ -175,6 +175,9 @@ sub COMPONENT { my \$self = shift->next::method(\@_); no strict 'refs'; *{\__PACKAGE__ . "::whoami"} = sub { return \__PACKAGE__; }; + *${appclass}::Model::TopLevel::GENERATED::ACCEPT_CONTEXT = sub { + return bless {}, 'FooBarBazQuux'; + }; \$self; } @@ -200,6 +203,10 @@ eval "package $appclass; use Catalyst; __PACKAGE__->setup"; is($@, '', "Didn't load component twice"); +ok($appclass->model('TopLevel::Generated'), 'Have generated model'); +is(ref($appclass->model('TopLevel::Generated')), 'FooBarBazQuux', + 'ACCEPT_CONTEXT in generated inner package fired as expected'); + $appclass = "InnerComponent"; {