Fixed a bug I introduced whereby registered_plugins would report wrong info.
Curtis "Ovid" Poe [Mon, 27 Feb 2006 21:20:17 +0000 (21:20 +0000)]
Basically, plugins are now registered with a Class::Data::Inheritable method
so that different classes can have different plugins.  In the future, if
someone wants different instances of the same class to have different plugins,
this method will have to be revisited.

lib/Catalyst.pm
lib/Catalyst/Component.pm
t/unit_core_plugin.t

index 54ff187..4e63635 100644 (file)
@@ -1892,14 +1892,13 @@ the plugin name does not begin with C<Catalyst::Plugin::>.
 =cut
 
 {
-    my %PLUGINS;
 
     sub registered_plugins {
         my $proto = shift;
-        return sort keys %PLUGINS unless @_;
+        return sort keys %{$proto->_plugins} unless @_;
         my $plugin = shift;
-        return 1 if exists $PLUGINS{$plugin};
-        return exists $PLUGINS{"Catalyst::Plugin::$plugin"};
+        return 1 if exists $proto->_plugins->{$plugin};
+        return exists $proto->_plugins->{"Catalyst::Plugin::$plugin"};
     }
 
     sub _register_plugin {
@@ -1914,7 +1913,7 @@ the plugin name does not begin with C<Catalyst::Plugin::>.
                 message => qq/Couldn't load ${type}plugin "$plugin", $error/ );
         }
 
-        $PLUGINS{$plugin} = 1;
+        $proto->_plugins->{$plugin} = 1;        
         unless ($instant) {
             no strict 'refs';
             unshift @{"$class\::ISA"}, $plugin;
@@ -1925,6 +1924,7 @@ the plugin name does not begin with C<Catalyst::Plugin::>.
     sub setup_plugins {
         my ( $class, $plugins ) = @_;
 
+        $class->_plugins( {} ) unless $class->_plugins;
         $plugins ||= [];
         for my $plugin ( reverse @$plugins ) {
 
index feab1cf..da40d5c 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use base qw/Class::Accessor::Fast Class::Data::Inheritable/;
 use NEXT;
 
-__PACKAGE__->mk_classdata($_) for qw/_config/;
+__PACKAGE__->mk_classdata($_) for qw/_config _plugins/;
 
 =head1 NAME
 
index 46647fb..e46797a 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 20;
+use Test::More tests => 22;
 
 use lib 't/lib';
 
@@ -91,3 +91,15 @@ use Catalyst::Test qw/PluginTestApp/;
 
 ok( get("/compile_time_plugins"), "get ok" );
 ok( get("/run_time_plugins"),     "get ok" );
+
+use_ok 'TestApp';
+my @expected = qw(
+  Catalyst::Plugin::Test::Errors
+  Catalyst::Plugin::Test::Headers
+  Catalyst::Plugin::Test::Plugin
+  TestApp::Plugin::FullyQualified
+);
+
+# Faux::Plugin is no longer reported
+is_deeply [ TestApp->registered_plugins ], \@expected,
+  'registered_plugins() should only report the plugins for the current class';