[Catalyst-commits] r8103 - / Catalyst-Plugin-PluginLoader
Catalyst-Plugin-PluginLoader/1.000
Catalyst-Plugin-PluginLoader/1.000/trunk
Catalyst-Plugin-PluginLoader/1.000/trunk/lib
Catalyst-Plugin-PluginLoader/1.000/trunk/lib/Catalyst
Catalyst-Plugin-PluginLoader/1.000/trunk/lib/Catalyst/Plugin
Catalyst-Plugin-PluginLoader/1.000/trunk/t
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/Catalyst
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/Catalyst/Plugin
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Controller
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Plugin
ash at dev.catalyst.perl.org
ash at dev.catalyst.perl.org
Fri Jul 11 13:17:47 BST 2008
Author: ash
Date: 2008-07-11 13:17:47 +0100 (Fri, 11 Jul 2008)
New Revision: 8103
Added:
Catalyst-Plugin-PluginLoader/
Catalyst-Plugin-PluginLoader/1.000/
Catalyst-Plugin-PluginLoader/1.000/trunk/
Catalyst-Plugin-PluginLoader/1.000/trunk/MANIFEST.SKIP
Catalyst-Plugin-PluginLoader/1.000/trunk/lib/
Catalyst-Plugin-PluginLoader/1.000/trunk/lib/Catalyst/
Catalyst-Plugin-PluginLoader/1.000/trunk/lib/Catalyst/Plugin/
Catalyst-Plugin-PluginLoader/1.000/trunk/lib/Catalyst/Plugin/PluginLoader.pm
Catalyst-Plugin-PluginLoader/1.000/trunk/t/
Catalyst-Plugin-PluginLoader/1.000/trunk/t/01_basic.t
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/Catalyst/
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/Catalyst/Plugin/
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/Catalyst/Plugin/Two.pm
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp.pm
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Controller/
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Controller/Root.pm
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Plugin/
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Plugin/One.pm
Log:
Catalyst::Plugin::PluginLoader - load plugins from config. Needs more testing
Added: Catalyst-Plugin-PluginLoader/1.000/trunk/MANIFEST.SKIP
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/MANIFEST.SKIP (rev 0)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/MANIFEST.SKIP 2008-07-11 12:17:47 UTC (rev 8103)
@@ -0,0 +1,38 @@
+# Avoid version control files.
+\bRCS\b
+\bCVS\b
+,v$
+\B\.svn\b
+
+# Avoid Makemaker generated and utility files.
+\bMakefile$
+\bblib
+\bMakeMaker-\d
+\bpm_to_blib$
+\bblibdirs$
+^MANIFEST\.SKIP$
+
+# Avoid Module::Build generated and utility files.
+\bBuild$
+\b_build
+
+# Avoid temp and backup files.
+~$
+\.tmp$
+\.old$
+\.bak$
+\#$
+\b\.#
+^\.DS_Store$
+
+# Avoid Apache::Test files
+t/conf/apache_test_config.pm
+t/conf/extra.conf$
+t/conf/httpd.conf
+t/conf/mime.types
+t/htdocs
+t/logs
+t/var
+
+# No tarballs!
+\.gz$
Added: Catalyst-Plugin-PluginLoader/1.000/trunk/lib/Catalyst/Plugin/PluginLoader.pm
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/lib/Catalyst/Plugin/PluginLoader.pm (rev 0)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/lib/Catalyst/Plugin/PluginLoader.pm 2008-07-11 12:17:47 UTC (rev 8103)
@@ -0,0 +1,48 @@
+package Catalyst::Plugin::PluginLoader;
+
+use strict;
+use warnings;
+use Class::C3;
+use Catalyst::Utils ();
+
+sub setup {
+ no strict 'refs';
+ my ($class) = @_;
+
+ if ($class->config->{plugins}) {
+ my %old_plugins = %{ $class->_plugins };
+
+ my $plugins = $class->config->{plugins};
+ $plugins = [ $plugins ] unless ref $plugins;
+ $plugins = [ map { s/\A\+// ? $_ : "Catalyst::Plugin::$_" } grep { !exists $old_plugins{$_} } @$plugins ];
+
+ my $isa_idx = 0;
+ $isa_idx++ while @{$class.'::ISA'}[$isa_idx] ne __PACKAGE__;
+ $isa_idx++;
+
+ for my $plugin (@$plugins) {
+ Catalyst::Utils::ensure_class_loaded($plugin);
+ $class->_plugins->{$plugin} = 1;
+ splice @{$class.'::ISA'}, $isa_idx++, 0, $plugin;
+ }
+
+ Class::C3::reinitialize;
+
+ if ($class->debug) {
+ my @plugins = map { "$_ " . ( $_->VERSION || '' ) } @$plugins;
+
+ if (@plugins) {
+ my $t = Text::SimpleTable->new(74);
+ $t->row($_) for @plugins;
+ $class->log->debug( "Loaded plugins from config:\n" . $t->draw . "\n" );
+ }
+ }
+
+ }
+
+ $DB::single = 1;
+ $class->next::method();
+}
+
+
+1;
Added: Catalyst-Plugin-PluginLoader/1.000/trunk/t/01_basic.t
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/t/01_basic.t (rev 0)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/t/01_basic.t 2008-07-11 12:17:47 UTC (rev 8103)
@@ -0,0 +1,13 @@
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use Catalyst::Test "MyApp";
+
+is( get('/'), "MyApp::Plugin::One Catalyst::Plugin::Two");
+
+warn "@MyApp::ISA";
Added: Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/Catalyst/Plugin/Two.pm
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/Catalyst/Plugin/Two.pm (rev 0)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/Catalyst/Plugin/Two.pm 2008-07-11 12:17:47 UTC (rev 8103)
@@ -0,0 +1,14 @@
+package Catalyst::Plugin::Two;
+
+use strict;
+use warnings;
+
+sub setup {
+ Test::More::ok(1, "Catalyst::Plugin::Two->setup called");
+
+ shift->NEXT::setup(@_);
+}
+
+sub plugin_two { __PACKAGE__ };
+
+1;
Added: Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Controller/Root.pm
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Controller/Root.pm (rev 0)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Controller/Root.pm 2008-07-11 12:17:47 UTC (rev 8103)
@@ -0,0 +1,15 @@
+package MyApp::Controller::Root;
+
+use strict;
+use warnings;
+use base 'Catalyst::Controller';
+
+__PACKAGE__->config->{namespace} = '';
+
+sub root : Chained('/') PathPart('') {
+ my ($self, $c) = @_;
+
+ $c->res->body($c->plugin_one . " " . $c->plugin_two);
+}
+
+1;
Added: Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Plugin/One.pm
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Plugin/One.pm (rev 0)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Plugin/One.pm 2008-07-11 12:17:47 UTC (rev 8103)
@@ -0,0 +1,14 @@
+package MyApp::Plugin::One;
+
+use strict;
+use warnings;
+
+sub setup {
+ Test::More::ok(1, "MyApp::Plugin::One->setup called");
+
+ shift->NEXT::setup(@_);
+}
+
+sub plugin_one { __PACKAGE__ };
+
+1;
Added: Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp.pm
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp.pm (rev 0)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp.pm 2008-07-11 12:17:47 UTC (rev 8103)
@@ -0,0 +1,18 @@
+package MyApp;
+
+use strict;
+use warnings;
+
+use Catalyst::Runtime '5.7014';
+
+use Catalyst qw/PluginLoader/;
+
+__PACKAGE__->config(
+ name => 'MyApp',
+ plugins => [qw/+MyApp::Plugin::One Two/]
+);
+
+# Start the application
+__PACKAGE__->setup;
+
+1;
More information about the Catalyst-commits
mailing list