X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=981b20fb339ea4c68f0ae81f5e360af0add7159b;hp=d93707fcd26f0c6c52b191687f125f150d1fedb0;hb=97b58e1798479e2df8d050e72e87453f6ad81668;hpb=8327e2e21fc9ea72c357e876f868001ad9712474 diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index d93707f..981b20f 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -58,7 +58,7 @@ __PACKAGE__->engine_class('Catalyst::Engine::CGI'); __PACKAGE__->request_class('Catalyst::Request'); __PACKAGE__->response_class('Catalyst::Response'); -our $VERSION = '5.64'; +our $VERSION = '5.66'; sub import { my ( $class, @arguments ) = @_; @@ -178,6 +178,14 @@ C. use Catalyst qw/My::Module/; +If your plugin starts with a name other than C, you can +fully qualify the name by using a unary plus: + + use Catalyst qw/ + My::Module + +Fully::Qualified::Plugin::Name + /; + Special flags like C<-Debug> and C<-Engine> can also be specified as arguments when Catalyst is loaded: @@ -534,12 +542,7 @@ loads and instantiates the given class. sub plugin { my ( $class, $name, $plugin, @args ) = @_; - $plugin->require; - - if ( my $error = $UNIVERSAL::require::ERROR ) { - Catalyst::Exception->throw( - message => qq/Couldn't load instant plugin "$plugin", "$error"/ ); - } + $class->_register_plugin( $plugin, 1 ); eval { $plugin->import }; $class->mk_classdata($name); @@ -698,7 +701,9 @@ EOF Merges path with C<$c-Erequest-Ebase> for absolute uri's and with C<$c-Enamespace> for relative uri's, then returns a normalized L object. If any args are passed, they are added at the -end of the path. +end of the path. If the last argument to uri_for is a hash reference, +it is assumed to contain GET parameter key/value pairs, which will be +appended to the URI in standard fashion. =cut @@ -717,7 +722,8 @@ sub uri_for { $namespace = '' if $path =~ /^\//; $path =~ s/^\///; - my $params = (scalar @args && ref $args[$#args] eq 'HASH' ? pop @args : {}); + my $params = + ( scalar @args && ref $args[$#args] eq 'HASH' ? pop @args : {} ); # join args with '/', or a blank string my $args = ( scalar @args ? '/' . join( '/', @args ) : '' ); @@ -1841,25 +1847,64 @@ Sets up plugins. =cut -sub setup_plugins { - my ( $class, $plugins ) = @_; +=head2 $c->registered_plugins + +Returns a sorted list of the plugins which have either been stated in the +import list or which have been added via C<< MyApp->plugin(@args); >>. - $plugins ||= []; - for my $plugin ( reverse @$plugins ) { +If passed a given plugin name, it will report a boolean value indicating +whether or not that plugin is loaded. A fully qualified name is required if +the plugin name does not begin with C. - $plugin = "Catalyst::Plugin::$plugin"; + if ($c->registered_plugins('Some::Plugin')) { + ... + } + +=cut + +{ + my %PLUGINS; + + sub registered_plugins { + my $proto = shift; + return sort keys %PLUGINS unless @_; + my $plugin = shift; + return 1 if exists $PLUGINS{$plugin}; + return exists $PLUGINS{"Catalyst::Plugin::$plugin"}; + } + + sub _register_plugin { + my ( $proto, $plugin, $instant ) = @_; + my $class = ref $proto || $proto; $plugin->require; - if ($@) { + if ( my $error = $@ ) { + my $type = $instant ? "instant " : ''; Catalyst::Exception->throw( - message => qq/Couldn't load plugin "$plugin", "$@"/ ); + message => qq/Couldn't load ${type}plugin "$plugin", $error/ ); } - { + $PLUGINS{$plugin} = 1; + unless ($instant) { no strict 'refs'; unshift @{"$class\::ISA"}, $plugin; } + return $class; + } + + sub setup_plugins { + my ( $class, $plugins ) = @_; + + $plugins ||= []; + for my $plugin ( reverse @$plugins ) { + + unless ( $plugin =~ s/\A\+// ) { + $plugin = "Catalyst::Plugin::$plugin"; + } + + $class->_register_plugin($plugin); + } } }