);
for my $component ( sort { length $a <=> length $b } $locator->plugins ) {
- Catalyst::Utils::ensure_class_loaded( $component );
+ Catalyst::Utils::ensure_class_loaded( $component, { ignore_loaded => 1 } );
my $module = $class->setup_component( $component );
my %modules = (
sub ensure_class_loaded {
my $class = shift;
+ my $opts = shift;
- return if Class::Inspector->loaded( $class ); # if a symbol entry exists we don't load again
+ return if !$opts->{ ignore_loaded }
+ && Class::Inspector->loaded( $class ); # if a symbol entry exists we don't load again
# this hack is so we don't overwrite $@ if the load did not generate an error
my $error;
--- /dev/null
+package TestApp::Model::Foo;
+
+use strict;
+use warnings;
+
+use base qw/ Catalyst::Model /;
+
+sub model_foo_method { 1 }
+
+package TestApp::Model::Foo::Bar;
+sub model_foo_bar_method_from_foo { 1 }
+
+package TestApp::Model::Foo;
+sub bar { "TestApp::Model::Foo::Bar" }
+
+1;
--- /dev/null
+package TestApp::Model::Foo::Bar;
+
+sub model_foo_bar_method_from_foo_bar { "model_foo_bar_method_from_foo_bar" }
+
+1;
--- /dev/null
+use Test::More tests => 5;
+use strict;
+use warnings;
+use lib 't/lib';
+
+# This tests that we actually load the physical
+# copy of Model::Foo::Bar, in the case that Model::Foo
+# defines the Model::Foo::Bar namespace in memory,
+# but does not load the corresponding file.
+
+use_ok 'TestApp';
+
+my $model_foo = TestApp->model('Foo');
+
+can_ok($model_foo, 'model_foo_method');
+can_ok($model_foo, 'bar');
+
+my $model_foo_bar = $model_foo->bar;
+
+can_ok($model_foo_bar, 'model_foo_bar_method_from_foo');
+can_ok($model_foo_bar, 'model_foo_bar_method_from_foo_bar');