From: Matt S Trout Date: Tue, 21 Aug 2007 22:25:23 +0000 (+0000) Subject: fix plugin loading X-Git-Tag: 5.7099_04~155 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=dd91afb57b7ab0cedad388f633dd0047c2290c1f fix plugin loading --- diff --git a/Changes b/Changes index e8ad042..f48fa5a 100644 --- 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 diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 41b54eb..53110e6 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -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. 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) { diff --git a/lib/Catalyst/Utils.pm b/lib/Catalyst/Utils.pm index 0598f53..62b8446 100644 --- a/lib/Catalyst/Utils.pm +++ b/lib/Catalyst/Utils.pm @@ -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 {