[Catalyst-commits] r10058 - in
Catalyst-Plugin-PluginLoader/1.000/trunk: .
lib/Catalyst/Plugin t t/lib t/lib/Catalyst/Plugin
t/lib/MyApp/Controller t/lib/MyApp/Plugin
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Sun May 10 05:15:37 GMT 2009
Author: caelum
Date: 2009-05-10 05:15:37 +0000 (Sun, 10 May 2009)
New Revision: 10058
Added:
Catalyst-Plugin-PluginLoader/1.000/trunk/Changes
Catalyst-Plugin-PluginLoader/1.000/trunk/Makefile.PL
Catalyst-Plugin-PluginLoader/1.000/trunk/t/02pod.t
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/Catalyst/Plugin/Three.pm
Modified:
Catalyst-Plugin-PluginLoader/1.000/trunk/MANIFEST.SKIP
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
Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Plugin/One.pm
Log:
C::P::PluginLoader - works, I think
Added: Catalyst-Plugin-PluginLoader/1.000/trunk/Changes
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/Changes (rev 0)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/Changes 2009-05-10 05:15:37 UTC (rev 10058)
@@ -0,0 +1,3 @@
+Revision history for Perl extension Catalyst::Plugin::PluginLoader
+
+ - seems to work
Modified: Catalyst-Plugin-PluginLoader/1.000/trunk/MANIFEST.SKIP
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/MANIFEST.SKIP 2009-05-09 13:59:34 UTC (rev 10057)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/MANIFEST.SKIP 2009-05-10 05:15:37 UTC (rev 10058)
@@ -1,38 +1,5 @@
-# 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$
+# stolen from Devel::REPL
+^(?!script/|examples/|lib/|inc/|t/|Makefile.PL$|README$|MANIFEST$|Changes$|META.yml$)
+.svn/
+.git/
+.swp$
Added: Catalyst-Plugin-PluginLoader/1.000/trunk/Makefile.PL
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/Makefile.PL (rev 0)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/Makefile.PL 2009-05-10 05:15:37 UTC (rev 10058)
@@ -0,0 +1,18 @@
+use inc::Module::Install 0.87;
+
+name 'Catalyst-Model-DBIC-Schema';
+all_from 'lib/Catalyst/Plugin/PluginLoader.pm';
+
+requires 'Catalyst::Runtime' => '5.80002';
+requires 'MRO::Compat';
+requires 'Scalar::Util';
+
+build_requires 'Test::More';
+
+if(-e 'MANIFEST.SKIP') {
+ system("pod2text lib/Catalyst/Plugin/PluginLoader.pm > README");
+}
+
+auto_provides;
+auto_install;
+WriteAll;
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-09 13:59:34 UTC (rev 10057)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/lib/Catalyst/Plugin/PluginLoader.pm 2009-05-10 05:15:37 UTC (rev 10058)
@@ -2,47 +2,137 @@
use strict;
use warnings;
-use Class::C3;
+use MRO::Compat ();
use Catalyst::Utils ();
+use Scalar::Util ();
+our $VERSION = '0.01';
+
+=head1 NAME
+
+Catalyst::Plugin::PluginLoader - Load Catalyst Plugins from Config
+
+=head1 SYNOPSIS
+
+ <Plugin::PluginLoader>
+ plugins Session
+ plugins Session::Store::FastMmap
+ plugins Session::State::Cookie
+ </Plugin::PluginLoader>
+
+ use Catalyst qw/ConfigLoader PluginLoader/;
+
+=head1 DESCRIPTION
+
+Allows you to load L<Catalyst> plugins from your app config file.
+
+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.
+
+Please report bugs at L<http://rt.cpan.org/>.
+
+=cut
+
sub setup {
- no strict 'refs';
- my ($class) = @_;
+ my $class = shift;
- if ($class->config->{plugins}) {
+ if (my $plugins = $class->config->{'Plugin::PluginLoader'}{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 ];
+ Catalyst::Exception->throw(
+ 'plugins must be an arrayref'
+ ) if Scalar::Util::reftype($plugins) ne 'ARRAY';
+
+ $plugins = [ map {
+ s/\A\+// ? $_ : "Catalyst::Plugin::$_"
+ } grep { !exists $old_plugins{$_} } @$plugins ];
+
+ my $isa = do { no strict 'refs'; \@{$class.'::ISA'}};
+
my $isa_idx = 0;
- $isa_idx++ while @{$class.'::ISA'}[$isa_idx] ne __PACKAGE__;
- $isa_idx++;
+ $isa_idx++ while $isa->[$isa_idx] ne __PACKAGE__;
for my $plugin (@$plugins) {
Catalyst::Utils::ensure_class_loaded($plugin);
$class->_plugins->{$plugin} = 1;
- splice @{$class.'::ISA'}, $isa_idx++, 0, $plugin;
+ splice @$isa, ++$isa_idx, 0, $plugin;
}
- Class::C3::reinitialize;
-
+ unshift @$isa, shift @$isa; # necessary to tell perl that @ISA changed
+ mro::invalidate_all_method_caches();
+
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" );
}
}
-
+
+ {
+# ->next::method won't work anymore, we have to do it ourselves
+ my @isa = @$isa;
+
+ for (0..$#isa) {
+ last if shift @isa eq __PACKAGE__;
+ }
+
+ my $old_next_method = *maybe::next::method{CODE};
+
+ my $next_method = sub {
+ if ((caller(1))[3] !~ /::setup\z/) {
+ goto &$old_next_method;
+ }
+
+ my $class = shift;
+
+ my $code;
+ while (my $next_class = shift @isa) {
+ $code = $next_class->can('setup');
+ last if $code;
+ }
+ return unless $code;
+
+ $class->$code(@_);
+ };
+
+ no warnings 'redefine';
+ local *next::method = $next_method;
+ local *maybe::next::method = $next_method;
+
+ return $class->next::method(@_);
+ }
}
-
- $DB::single = 1;
- $class->next::method();
+
+ return $class->next::method(@_);
}
+=head1 SEE ALSO
+L<Catalyst>, L<Catalyst::Plugin::ConfigLoader>,
+L<Catalyst::Manual::ExtendingCatalyst>
+
+=head1 TODO
+
+Better tests.
+
+=head1 AUTHOR
+
+Ash Berlin, C<ash at cpan.org>
+
+Rafael Kitover, C<rkitover at cpan.org>
+
+=head1 COPYRIGHT
+
+This program is free software, you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
1;
Modified: Catalyst-Plugin-PluginLoader/1.000/trunk/t/01_basic.t
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/t/01_basic.t 2009-05-09 13:59:34 UTC (rev 10057)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/t/01_basic.t 2009-05-10 05:15:37 UTC (rev 10058)
@@ -1,13 +1,14 @@
use strict;
use warnings;
-use Test::More tests => 3;
+use Test::More tests => 4;
use FindBin;
use lib "$FindBin::Bin/lib";
use Catalyst::Test "MyApp";
-is( get('/'), "MyApp::Plugin::One Catalyst::Plugin::Two");
+# 3 tests run from 3 plugins' setup methods
-warn "@MyApp::ISA";
+is(get('/'), "MyApp::Plugin::One Catalyst::Plugin::Two Catalyst::Plugin::Three",
+ 'plugin methods work');
Added: Catalyst-Plugin-PluginLoader/1.000/trunk/t/02pod.t
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/t/02pod.t (rev 0)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/t/02pod.t 2009-05-10 05:15:37 UTC (rev 10058)
@@ -0,0 +1,7 @@
+use Test::More;
+
+eval "use Test::Pod 1.14";
+plan skip_all => 'Test::Pod 1.14 required' if $@;
+plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
+
+all_pod_files_ok();
Added: Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/Catalyst/Plugin/Three.pm
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/Catalyst/Plugin/Three.pm (rev 0)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/Catalyst/Plugin/Three.pm 2009-05-10 05:15:37 UTC (rev 10058)
@@ -0,0 +1,14 @@
+package Catalyst::Plugin::Three;
+
+use strict;
+use warnings;
+
+sub setup {
+ Test::More::ok(1, "Catalyst::Plugin::Three->setup called");
+
+ shift->next::method(@_);
+}
+
+sub plugin_three { __PACKAGE__ };
+
+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-09 13:59:34 UTC (rev 10057)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Controller/Root.pm 2009-05-10 05:15:37 UTC (rev 10058)
@@ -9,7 +9,7 @@
sub root : Chained('/') PathPart('') {
my ($self, $c) = @_;
- $c->res->body($c->plugin_one . " " . $c->plugin_two);
+ $c->res->body($c->plugin_one . " " . $c->plugin_two . " " . $c->plugin_three);
}
1;
Modified: Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Plugin/One.pm
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Plugin/One.pm 2009-05-09 13:59:34 UTC (rev 10057)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp/Plugin/One.pm 2009-05-10 05:15:37 UTC (rev 10058)
@@ -6,7 +6,7 @@
sub setup {
Test::More::ok(1, "MyApp::Plugin::One->setup called");
- shift->NEXT::setup(@_);
+ shift->next::method(@_);
}
sub plugin_one { __PACKAGE__ };
Modified: Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp.pm
===================================================================
--- Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp.pm 2009-05-09 13:59:34 UTC (rev 10057)
+++ Catalyst-Plugin-PluginLoader/1.000/trunk/t/lib/MyApp.pm 2009-05-10 05:15:37 UTC (rev 10058)
@@ -3,16 +3,14 @@
use strict;
use warnings;
-use Catalyst::Runtime '5.7014';
+use Catalyst qw/PluginLoader Three/;
-use Catalyst qw/PluginLoader/;
-
__PACKAGE__->config(
- name => 'MyApp',
- plugins => [qw/+MyApp::Plugin::One Two/]
+ 'Plugin::PluginLoader' => {
+ plugins => [qw/+MyApp::Plugin::One Two/]
+ }
);
-# Start the application
__PACKAGE__->setup;
1;
More information about the Catalyst-commits
mailing list