From: Matt S Trout Date: Sun, 11 Jun 2006 14:43:36 +0000 (+0000) Subject: initial Module::Pluggable work X-Git-Tag: 5.7099_04~521 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=364d7324169f5562a0e1405413005ba2ac656e88 initial Module::Pluggable work r9819@cain (orig r4300): bricas | 2006-06-06 01:03:24 +0000 --- diff --git a/Changes b/Changes index 22b8ca1..4fb1336 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ This file documents the revision history for Perl extension Catalyst. + - removed Module::Pluggable::Fast hack in favor of + Module::Pluggable::Object - extended uri_for, added dispatcher->uri_for_action - added Catalyst::Base->action_for('methodname') - checked and tested :Args multimethod dispatch diff --git a/Makefile.PL b/Makefile.PL index 8a7218e..5095367 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -20,7 +20,7 @@ requires 'HTTP::Request'; requires 'HTTP::Response'; requires 'HTTP::Request::AsCGI' => '0.5'; requires 'LWP::UserAgent'; -requires 'Module::Pluggable::Fast' => 0.16; +requires 'Module::Pluggable' => '3.0'; requires 'NEXT'; requires 'Path::Class' => '0.09'; requires 'Scalar::Util'; @@ -43,7 +43,7 @@ WriteAll; print( '*' x 80, "\n" ); my $banner = (qw/andyg chansen draven fordmason mst naughton sri jester - nothingmuch LTJake/)[ int( rand(10) ) ] + nothingmuch LTjake/)[ int( rand(10) ) ] . " is the greatest and gabb is " . ( (localtime)[2] > 12 ? "drunk" : "hung over" ) . " again!"; diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 8cccb9a..0403b00 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -10,7 +10,9 @@ use Catalyst::Request::Upload; use Catalyst::Response; use Catalyst::Utils; use Catalyst::Controller; +use Devel::InnerPackage (); use File::stat; +use Module::Pluggable::Object; use NEXT; use Text::SimpleTable; use Path::Class::Dir; @@ -48,8 +50,6 @@ our $START = time; our $RECURSION = 1000; our $DETACH = "catalyst_detach\n"; -require Module::Pluggable::Fast; - __PACKAGE__->mk_classdata($_) for qw/components arguments dispatcher engine log dispatcher_class engine_class context_class request_class response_class setup_finished/; @@ -1808,57 +1808,60 @@ Sets up components. sub setup_components { my $class = shift; - my $callback = sub { - my ( $component, $context ) = @_; - - unless ( $component->can('COMPONENT') ) { - return $component; + my $locator = Module::Pluggable::Object->new( + search_path => [ + "${class}::Controller", "${class}::C", + "${class}::Model", "${class}::M", + "${class}::View", "${class}::V" + ], + ); + + for my $component ( sort { length $a <=> length $b } $locator->plugins ) { + require Class::Inspector->filename($component); + + my $module = $class->setup_component( $component ); + my %modules = ( + $component => $module, + map { + $_ => $class->setup_component( $_ ) + } Devel::InnerPackage::list_packages( $component ) + ); + + for my $key ( keys %modules ) { + $class->components->{ $key } = $modules{ $key }; } + } +} - my $suffix = Catalyst::Utils::class2classsuffix($component); - my $config = $class->config->{$suffix} || {}; - - my $instance; - - eval { $instance = $component->COMPONENT( $context, $config ); }; +=head2 $c->setup_component - if ( my $error = $@ ) { +=cut - chomp $error; +sub setup_component { + my( $class, $component ) = @_; - Catalyst::Exception->throw( message => - qq/Couldn't instantiate component "$component", "$error"/ ); - } + unless ( $component->can( 'COMPONENT' ) ) { + return $component; + } - Catalyst::Exception->throw( message => -qq/Couldn't instantiate component "$component", "COMPONENT() didn't return a object"/ - ) - unless ref $instance; - return $instance; - }; + my $suffix = Catalyst::Utils::class2classsuffix( $component ); + my $config = $class->config->{ $suffix } || {}; - eval "package $class;\n" . q!Module::Pluggable::Fast->import( - name => '_catalyst_components', - search => [ - "$class\::Controller", "$class\::C", - "$class\::Model", "$class\::M", - "$class\::View", "$class\::V" - ], - callback => $callback - ); - !; + my $instance = eval { $component->COMPONENT( $class, $config ); }; if ( my $error = $@ ) { - chomp $error; - Catalyst::Exception->throw( - message => qq/Couldn't load components "$error"/ ); + message => qq/Couldn't instantiate component "$component", "$error"/ + ); } - for my $component ( $class->_catalyst_components($class) ) { - $class->components->{ ref $component || $component } = $component; - } + Catalyst::Exception->throw( + message => + qq/Couldn't instantiate component "$component", "COMPONENT() didn't return an object-like value"/ + ) unless eval { $instance->can( 'can' ) }; + + return $instance; } =head2 $c->setup_dispatcher