From: Tomas Doran Date: Thu, 14 May 2009 01:28:13 +0000 (+0000) Subject: Add support for applying Moose roles in the plugin list X-Git-Tag: 5.80004~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=e5210a95f78613a598abbfc7d29d92605d5bbad0 Add support for applying Moose roles in the plugin list --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index a994166..c131008 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -2479,9 +2479,6 @@ the plugin name does not begin with C. my ( $proto, $plugin, $instant ) = @_; my $class = ref $proto || $proto; - # 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 - Class::MOP::load_class( $plugin ); $proto->_plugins->{$plugin} = 1; @@ -2502,14 +2499,27 @@ the plugin name does not begin with C. $class->_plugins( {} ) unless $class->_plugins; $plugins ||= []; - for my $plugin ( reverse @$plugins ) { - unless ( $plugin =~ s/\A\+// ) { - $plugin = "Catalyst::Plugin::$plugin"; - } + my @plugins = map { s/\A\+// ? $_ : "Catalyst::Plugin::$_" } @$plugins; + + Class::MOP::load_class($_) for @plugins; + + for my $plugin ( reverse @plugins ) { + my $meta = find_meta($plugin); + next if $meta && $meta->isa('Moose::Meta::Role'); $class->_register_plugin($plugin); } + + my @roles = + map { $_->name } + grep { $_ && blessed($_) && $_->isa('Moose::Meta::Role') } + map { find_meta($_) } + @plugins; + + Moose::Util::apply_all_roles( + $class => @roles + ) if @roles; } } diff --git a/t/aggregate/unit_core_appclass_roles_in_plugin_list.t b/t/aggregate/unit_core_appclass_roles_in_plugin_list.t new file mode 100644 index 0000000..c1945df --- /dev/null +++ b/t/aggregate/unit_core_appclass_roles_in_plugin_list.t @@ -0,0 +1,14 @@ +use strict; +use warnings; + +use FindBin qw/$Bin/; +use lib "$Bin/../lib"; + +use Test::More tests => 2; + +use TestApp; +use TestApp::Role; + +is $TestApp::Role::SETUP_FINALIZE, 1, 'TestApp->setup_finalize modifier run once'; +is $TestApp::Role::SETUP_DISPATCHER, 1, 'TestApp->setup_dispacter modifier run once'; + diff --git a/t/lib/TestApp.pm b/t/lib/TestApp.pm index f5a7c56..4242c5a 100644 --- a/t/lib/TestApp.pm +++ b/t/lib/TestApp.pm @@ -8,6 +8,7 @@ use Catalyst qw/ Test::Inline +TestApp::Plugin::FullyQualified +TestApp::Plugin::AddDispatchTypes + +TestApp::Role /; use Catalyst::Utils; diff --git a/t/lib/TestApp/Role.pm b/t/lib/TestApp/Role.pm new file mode 100644 index 0000000..af02a21 --- /dev/null +++ b/t/lib/TestApp/Role.pm @@ -0,0 +1,15 @@ +package TestApp::Role; +use Moose::Role; +use namespace::clean -except => 'meta'; + +requires 'fully_qualified'; # Comes from TestApp::Plugin::FullyQualified + +our $SETUP_FINALIZE = 0; +our $SETUP_DISPATCHER = 0; + +before 'setup_finalize' => sub { $SETUP_FINALIZE++ }; + +before 'setup_dispatcher' => sub { $SETUP_DISPATCHER++ }; + +1; +