Merge branch 'master' into gsoc_breadboard
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_mvc.t
index 2905838..390c4c6 100644 (file)
@@ -20,7 +20,6 @@ foreach my $comp (@complist) {
     );
 }
 our $warnings = 0;
-our $loaded   = 0;
 
 Moose::Meta::Class->create('Some::Test::Object');
 
@@ -49,17 +48,18 @@ Moose::Meta::Class->create(
         );
     };
     local *Catalyst::Log::warn = sub { $warnings++ };
-    *Class::MOP::load_class = sub {
-        my $class = shift;
-        $loaded++
-            if Class::MOP::is_class_loaded($class) && $class =~ /^MyMVCTestApp/
-    };
 
     __PACKAGE__->setup;
 }
 
 ok( $warnings, 'Issues deprecated warnings' );
-is( $loaded, scalar @complist + 1, 'Loaded all components' );
+is( @{[ MyMVCTestApp->component_list ]}, scalar @complist + 1, 'Loaded all components' );
+
+{
+    package MyStringThing;
+
+    use overload '""' => sub { $_[0]->{string} }, fallback => 1;
+}
 
 is( MyMVCTestApp->view('View'), 'MyMVCTestApp::V::View', 'V::View ok' );
 
@@ -161,11 +161,6 @@ our @complist_default_view =
         );
     };
     local *Catalyst::Log::warn = sub { $warnings++ };
-    *Class::MOP::load_class = sub {
-        my $class = shift;
-        $loaded++
-            if Class::MOP::is_class_loaded($class) && $class =~ /^MyMVCTestAppDefaultView/
-    };
 
     __PACKAGE__->config( default_view => 'V' );
 
@@ -197,11 +192,6 @@ our @complist_default_model =
         );
     };
     local *Catalyst::Log::warn = sub { $warnings++ };
-    *Class::MOP::load_class = sub {
-        my $class = shift;
-        $loaded++
-            if Class::MOP::is_class_loaded($class) && $class =~ /^MyMVCTestAppDefaultModel/
-    };
 
     __PACKAGE__->config( default_model => 'M' );
 
@@ -221,6 +211,18 @@ is( MyMVCTestAppDefaultModel->model , 'MyMVCTestAppDefaultModel::Model::M', 'def
     # object w/ qr{}
     is_deeply( [ MyMVCTestApp->model( qr{Test} ) ], [ MyMVCTestApp->components->{'MyMVCTestApp::Model::Test::Object'} ], 'Object returned' );
 
+    is_deeply([ MyMVCTestApp->model( bless({ string => 'Model' }, 'MyStringThing') ) ], [ MyMVCTestApp->components->{'MyMVCTestApp::M::Model'} ], 'Explicit model search with overloaded object');
+
+    {
+        my $warnings = 0;
+        no warnings 'redefine';
+        local *Catalyst::Log::warn = sub { $warnings++ };
+
+        # object w/ regexp fallback
+        is_deeply( [ MyMVCTestApp->model( bless({ string => 'Test' }, 'MyStringThing') ) ], [ MyMVCTestApp->components->{'MyMVCTestApp::Model::Test::Object'} ], 'Object returned' );
+        ok( $warnings, 'regexp fallback warnings' );
+    }
+
     {
         my $warnings = 0;
         no warnings 'redefine';
@@ -290,10 +292,6 @@ is( MyMVCTestAppDefaultModel->model , 'MyMVCTestAppDefaultModel::Model::M', 'def
 
     no warnings 'redefine';
 
-    *Class::MOP::load_class = sub {
-        $loaded++;
-    };
-
     __PACKAGE__->config( { disable_component_resolution_regex_fallback => 1 } );
 
     __PACKAGE__->components( { map { ( ref($_)||$_ , $_ ) }