fix plugin loading
Matt S Trout [Tue, 21 Aug 2007 22:25:23 +0000 (22:25 +0000)]
Changes
lib/Catalyst.pm
lib/Catalyst/Utils.pm

diff --git a/Changes b/Changes
index e8ad042..f48fa5a 100644 (file)
--- a/Changes
+++ b/Changes
@@ -4,6 +4,8 @@ This file documents the revision history for Perl extension Catalyst.
         - Moved Manual.pod to Manual.pm and clarified status of 
           Catalyst-Manual dist
         - Doc patches to Catalyst::Controller
+        - remove ignore_loaded from plugin load, commenting why
+        - document the ignore_loaded feature in Catalyst::Utils
 
 5.7008  2007-08-13 08:40:00
         - Added $c->request->query_keywords for getting the keywords
index 41b54eb..53110e6 100644 (file)
@@ -1872,6 +1872,11 @@ sub setup_components {
     my %comps = map { $_ => 1 } @comps;
     
     for my $component ( @comps ) {
+
+        # We pass ignore_loaded here so that overlay files for (e.g.)
+        # Model::DBI::Schema sub-classes are loaded - if it's in @comps
+        # we know M::P::O found a file on disk so this is safe
+
         Catalyst::Utils::ensure_class_loaded( $component, { ignore_loaded => 1 } );
 
         my $module  = $class->setup_component( $component );
@@ -2149,7 +2154,10 @@ the plugin name does not begin with C<Catalyst::Plugin::>.
         my ( $proto, $plugin, $instant ) = @_;
         my $class = ref $proto || $proto;
 
-        Catalyst::Utils::ensure_class_loaded( $plugin, { ignore_loaded => 1 } );
+        # no ignore_loaded here, the plugin may already have been
+        # defined in memory and we don't want to error on "no file" if so
+
+        Catalyst::Utils::ensure_class_loaded( $plugin );
 
         $proto->_plugins->{$plugin} = 1;
         unless ($instant) {
index 0598f53..62b8446 100644 (file)
@@ -233,10 +233,15 @@ sub request {
     return $request;
 }
 
-=head2 ensure_class_loaded($class_name)
+=head2 ensure_class_loaded($class_name, \%opts)
 
 Loads the class unless it already has been loaded.
 
+If $opts{ignore_loaded} is true always tries the require whether the package
+already exists or not. Only pass this if you're either (a) sure you know the
+file exists on disk or (b) have code to catch the file not found exception
+that will result if it doesn't.
+
 =cut
 
 sub ensure_class_loaded {