From: Ash Berlin Date: Mon, 21 May 2007 20:41:55 +0000 (+0000) Subject: Fix bug where a nested component would be setup twice X-Git-Tag: 5.7099_04~183 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=b94b200c22a5c08f9fa18db789914b3bd593f4b5;hp=500a16796a666045b3961eef7ceb3a2ed4ec0ca7 Fix bug where a nested component would be setup twice --- diff --git a/Changes b/Changes index f106eec..2e8fb42 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ This file documents the revision history for Perl extension Catalyst. + - Fix bug where a nested component would be setup twice + 5.7008 - Fixed a bug where Content-Length could be set to 0 if a filehandle object in $c->response->body did not report a size. diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 809d2a4..7bf9f6a 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1856,8 +1856,11 @@ sub setup_components { search_path => [ map { s/^(?=::)/$class/; $_; } @paths ], %$config ); + + my @comps = sort { length $a <=> length $b } $locator->plugins; + my %comps = map { $_ => 1 } @comps; - for my $component ( sort { length $a <=> length $b } $locator->plugins ) { + for my $component ( @comps ) { Catalyst::Utils::ensure_class_loaded( $component, { ignore_loaded => 1 } ); my $module = $class->setup_component( $component ); @@ -1865,6 +1868,8 @@ sub setup_components { $component => $module, map { $_ => $class->setup_component( $_ ) + } grep { + not exists $comps{$_} } Devel::InnerPackage::list_packages( $component ) ); diff --git a/t/unit_core_component_loading.t b/t/unit_core_component_loading.t index f0204ec..5b6a4a7 100644 --- a/t/unit_core_component_loading.t +++ b/t/unit_core_component_loading.t @@ -1,7 +1,7 @@ # 2 initial tests, and 6 per component in the loop below # (do not forget to update the number of components in test 3 as well) -# 4 extra tests for the loading options -use Test::More tests => 2 + 6 * 24 + 4; +# 5 extra tests for the loading options +use Test::More tests => 2 + 6 * 24 + 5; use strict; use warnings; @@ -40,6 +40,18 @@ my @components = ( { type => 'View', prefix => 'View', name => 'Foo' }, ); +sub write_component_file { + my ($dir_list, $module_name, $content) = @_; + + my $dir = File::Spec->catdir(@$dir_list); + my $file = File::Spec->catfile($dir, $module_name . '.pm'); + + mkpath(join(q{/}, @$dir_list) ); + open(my $fh, '>', $file) or die "Could not open file $file for writing: $!"; + print $fh $content; + close $fh; +} + sub make_component_file { my ($type, $prefix, $name) = @_; @@ -48,13 +60,8 @@ sub make_component_file { my @namedirs = split(/::/, $name); my $name_final = pop(@namedirs); my @dir_list = ($libdir, $appclass, $prefix, @namedirs); - my $dir_ux = join(q{/}, @dir_list); - my $dir = File::Spec->catdir(@dir_list); - my $file = File::Spec->catfile($dir, $name_final . '.pm'); - mkpath($dir_ux); # mkpath wants unix '/' seperators :p - open(my $fh, '>', $file) or die "Could not open file $file for writing: $!"; - print $fh <{ "${appclass}::Controller::Foo" }, 'Controller::Foo was skipped' ); ok( exists $complist->{ "${appclass}::Extra::Foo" }, 'Extra::Foo was loaded' ); -rmtree($libdir); \ No newline at end of file +rmtree($libdir); + +$appclass = "ComponentOnce"; + +write_component_file([$libdir, $appclass, 'Model'], 'TopLevel', <NEXT::COMPONENT(\@_); + no strict 'refs'; + *{\__PACKAGE__ . "::whoami"} = sub { return \__PACKAGE__; }; + \$self; +} + +package ${appclass}::Model::TopLevel::Nested; + +sub COMPONENT { die "COMPONENT called in the wrong order!"; } + +1; + +EOF + +write_component_file([$libdir, $appclass, 'Model', 'TopLevel'], 'Nested', <NEXT::COMPONENT(\@_); } +1; + +EOF + +eval "package $appclass; use Catalyst; __PACKAGE__->setup"; + +is($@, '', "Didn't load component twice"); + +rmtree($libdir);