[Catalyst-commits] r10144 - in Catalyst-Runtime/5.80/trunk: lib
t/aggregate t/lib t/lib/TestApp
t0m at dev.catalyst.perl.org
t0m at dev.catalyst.perl.org
Thu May 14 01:28:14 GMT 2009
Author: t0m
Date: 2009-05-14 01:28:13 +0000 (Thu, 14 May 2009)
New Revision: 10144
Added:
Catalyst-Runtime/5.80/trunk/t/aggregate/unit_core_appclass_roles_in_plugin_list.t
Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Role.pm
Modified:
Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
Catalyst-Runtime/5.80/trunk/t/lib/TestApp.pm
Log:
Add support for applying Moose roles in the plugin list
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm 2009-05-14 01:21:43 UTC (rev 10143)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst.pm 2009-05-14 01:28:13 UTC (rev 10144)
@@ -2479,9 +2479,6 @@
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 @@
$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;
}
}
Added: Catalyst-Runtime/5.80/trunk/t/aggregate/unit_core_appclass_roles_in_plugin_list.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/aggregate/unit_core_appclass_roles_in_plugin_list.t (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/aggregate/unit_core_appclass_roles_in_plugin_list.t 2009-05-14 01:28:13 UTC (rev 10144)
@@ -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';
+
Added: Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Role.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Role.pm (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Role.pm 2009-05-14 01:28:13 UTC (rev 10144)
@@ -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;
+
Modified: Catalyst-Runtime/5.80/trunk/t/lib/TestApp.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/lib/TestApp.pm 2009-05-14 01:21:43 UTC (rev 10143)
+++ Catalyst-Runtime/5.80/trunk/t/lib/TestApp.pm 2009-05-14 01:28:13 UTC (rev 10144)
@@ -8,6 +8,7 @@
Test::Inline
+TestApp::Plugin::FullyQualified
+TestApp::Plugin::AddDispatchTypes
+ +TestApp::Role
/;
use Catalyst::Utils;
More information about the Catalyst-commits
mailing list