Fix component_setup + tests
Brian Cassidy [Sat, 15 Jul 2006 03:04:50 +0000 (03:04 +0000)]
lib/Catalyst.pm
lib/Catalyst/Utils.pm
t/lib/TestApp/Model/Foo.pm [new file with mode: 0644]
t/lib/TestApp/Model/Foo/Bar.pm [new file with mode: 0644]
t/unit_core_component_layers.t [new file with mode: 0644]

index 9aec8c2..8c0fc7b 100644 (file)
@@ -1795,7 +1795,7 @@ sub setup_components {
     );
     
     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 = (
index 59b8ca0..9e389e3 100644 (file)
@@ -240,8 +240,10 @@ Loads the class unless it already has been loaded.
 
 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;
diff --git a/t/lib/TestApp/Model/Foo.pm b/t/lib/TestApp/Model/Foo.pm
new file mode 100644 (file)
index 0000000..b0418e8
--- /dev/null
@@ -0,0 +1,16 @@
+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;
diff --git a/t/lib/TestApp/Model/Foo/Bar.pm b/t/lib/TestApp/Model/Foo/Bar.pm
new file mode 100644 (file)
index 0000000..9d256bb
--- /dev/null
@@ -0,0 +1,5 @@
+package TestApp::Model::Foo::Bar;
+
+sub model_foo_bar_method_from_foo_bar { "model_foo_bar_method_from_foo_bar" }
+
+1;
diff --git a/t/unit_core_component_layers.t b/t/unit_core_component_layers.t
new file mode 100644 (file)
index 0000000..4261365
--- /dev/null
@@ -0,0 +1,21 @@
+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');