[Catalyst-commits] r10191 - in
Catalyst-Plugin-PluginLoader/1.000/trunk: .
lib/Catalyst/Plugin t t/lib t/lib/Catalyst/Plugin
t/lib/MyApp/Controller
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Sun May 17 21:45:11 GMT 2009
Author: caelum
Date: 2009-05-17 21:45:11 +0000 (Sun, 17 May 2009)
New Revision: 10191
Added:
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/Catalyst/Plugin/TestRole.pm
Modified:
Catalyst-Plugin-PluginLoader/1.000/trunk/Changes
Catalyst-Plugin-PluginLoader/1.000/trunk/Makefile.PL
Catalyst-Plugin-PluginLoader/1.000/trunk/lib/Catalyst/Plugin/PluginLoader.pm
Catalyst-Plugin-PluginLoader/1.000/trunk/t/01_basic.t
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp.pm
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Controller/Root.pm
Log:
pluginloader - initial role support
Modified: Catalyst-Plugin-PluginLoader/1.000/trunk/Changes
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/Changes 2009-05-17 02:50:42 UTC (rev 10190)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/Changes 2009-05-17 21:45:11 UTC (rev 10191)
@@ -1,4 +1,7 @@
Revision history for Perl extension Catalyst::Plugin::PluginLoader
+0.02 2009-05-17 21:44:05
+ - some initial role support
+
0.01 2009-05-12 12:30:33
- first release
Modified: Catalyst-Plugin-PluginLoader/1.000/trunk/Makefile.PL
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/Makefile.PL 2009-05-17 02:50:42 UTC (rev 10190)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/Makefile.PL 2009-05-17 21:45:11 UTC (rev 10191)
@@ -6,6 +6,7 @@
requires 'Catalyst::Runtime' => '5.80002';
requires 'MRO::Compat';
requires 'Scalar::Util';
+requires 'namespace::clean';
build_requires 'Test::More';
Modified: Catalyst-Plugin-PluginLoader/1.000/trunk/lib/Catalyst/Plugin/PluginLoader.pm
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/lib/Catalyst/Plugin/PluginLoader.pm 2009-05-17 02:50:42 UTC (rev 10190)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/lib/Catalyst/Plugin/PluginLoader.pm 2009-05-17 21:45:11 UTC (rev 10191)
@@ -4,10 +4,13 @@
use warnings;
use MRO::Compat ();
use Catalyst::Utils ();
-use Scalar::Util ();
+use Scalar::Util 'reftype';
+use Moose::Util qw/find_meta apply_all_roles/;
-our $VERSION = '0.01';
+use namespace::clean -except => 'meta';
+our $VERSION = '0.02';
+
=head1 NAME
Catalyst::Plugin::PluginLoader - Load Catalyst Plugins from Config
@@ -29,8 +32,10 @@
Plugin order is the same as if you put the plugins after PluginLoader in the
C<use Catalyst> line.
-This is a B<COLOSSAL HACK> and is not guaranteed to work.
+Roles will be loaded as well, however C<around 'setup'> will not work yet.
+This is a B<COLOSSAL HACK>, use at your own risk.
+
Please report bugs at L<http://rt.cpan.org/>.
=cut
@@ -45,7 +50,7 @@
Catalyst::Exception->throw(
'plugins must be an arrayref'
- ) if Scalar::Util::reftype($plugins) ne 'ARRAY';
+ ) if reftype $plugins ne 'ARRAY';
$plugins = [ map {
s/\A\+// ? $_ : "Catalyst::Plugin::$_"
@@ -59,7 +64,14 @@
for my $plugin (@$plugins) {
Catalyst::Utils::ensure_class_loaded($plugin);
$class->_plugins->{$plugin} = 1;
- splice @$isa, ++$isa_idx, 0, $plugin;
+
+ my $meta = find_meta($plugin);
+
+ if ($meta && blessed $meta && $meta->isa('Moose::Meta::Role')) {
+ apply_all_roles($class => $plugin);
+ } else {
+ splice @$isa, ++$isa_idx, 0, $plugin;
+ }
}
unshift @$isa, shift @$isa; # necessary to tell perl that @ISA changed
@@ -131,4 +143,5 @@
=cut
-1
+1;
+# vim:sw=2 sts=2:
Modified: Catalyst-Plugin-PluginLoader/1.000/trunk/t/01_basic.t
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/t/01_basic.t 2009-05-17 02:50:42 UTC (rev 10190)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/t/01_basic.t 2009-05-17 21:45:11 UTC (rev 10191)
@@ -1,7 +1,7 @@
use strict;
use warnings;
-use Test::More tests => 5;
+use Test::More tests => 6;
use FindBin;
use lib "$FindBin::Bin/lib";
@@ -12,3 +12,6 @@
is(get('/'), "MyApp::Plugin::One Catalyst::Plugin::Two Catalyst::Plugin::Three",
'plugin methods work');
+
+is(get('/test_role'), 'mtfnpy',
+ 'loading roles works');
Added: Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/Catalyst/Plugin/TestRole.pm
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/Catalyst/Plugin/TestRole.pm (rev 0)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/Catalyst/Plugin/TestRole.pm 2009-05-17 21:45:11 UTC (rev 10191)
@@ -0,0 +1,7 @@
+package Catalyst::Plugin::TestRole;
+
+use Moose::Role;
+
+sub hello_from_role { "mtfnpy" }
+
+1;
Modified: Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Controller/Root.pm
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Controller/Root.pm 2009-05-17 02:50:42 UTC (rev 10190)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Controller/Root.pm 2009-05-17 21:45:11 UTC (rev 10191)
@@ -12,4 +12,10 @@
$c->res->body($c->plugin_one . " " . $c->plugin_two . " " . $c->plugin_three);
}
+sub test_role : Local {
+ my ($self, $c) = @_;
+
+ $c->res->body($c->hello_from_role);
+}
+
1;
Modified: Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp.pm
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp.pm 2009-05-17 02:50:42 UTC (rev 10190)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp.pm 2009-05-17 21:45:11 UTC (rev 10191)
@@ -7,7 +7,7 @@
__PACKAGE__->config(
'Plugin::PluginLoader' => {
- plugins => [qw/+MyApp::Plugin::One Two/]
+ plugins => [qw/+MyApp::Plugin::One Two TestRole/]
}
);
More information about the Catalyst-commits
mailing list