From: Sebastian Riedel Date: Tue, 19 Apr 2005 18:02:33 +0000 (+0000) Subject: Added plugin() method for instant plugins X-Git-Tag: 5.7099_04~1467 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=872323814592a19623a6c72a348ed954659c291f Added plugin() method for instant plugins --- diff --git a/Changes b/Changes index 219aec1..71702c3 100644 --- a/Changes +++ b/Changes @@ -7,6 +7,8 @@ This file documents the revision history for Perl extension Catalyst. - Improved Dispatcher error messages. - Refactored so we don't need to include helper from Catalyst.pm - applied HTTP.pm patch from Andy Grundman + - added plugin() method for instant plugins + - FCGI is no more considered experimental 5.02 Mon Apr 18 10:00:00 2005 - fixed manifest diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index ac8b853..0f7cd81 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -171,9 +171,7 @@ sub import { . "Please update your scripts by regenerating the " . "application and copying over the new scripts." ) if ( $ENV{CATALYST_SCRIPT_GEN} - && ( - $ENV{CATALYST_SCRIPT_GEN} < $CATALYST_SCRIPT_GEN ) - ); + && ( $ENV{CATALYST_SCRIPT_GEN} < $CATALYST_SCRIPT_GEN ) ); # Process options my @plugins; @@ -258,15 +256,37 @@ C object. To use your own log class: Your log class should implement the methods described in the C man page. +=item $c->plugin( $name, $class, @args ) + +Instant plugins for Catalyst. +Classdata accessor/mutator will be created, class loaded and instantiated. + + MyApp->plugin( 'prototype', 'HTML::Prototype' ); + + $c->prototype->define_javascript_functions; + +=cut + +sub plugin { + my ( $class, $name, $plugin, @args ) = @_; + $plugin->require; + my $error = $UNIVERSAL::require::ERROR; + die qq/Couldn't load instant plugin "$plugin", "$error"/ if $error; + eval { $plugin->import }; + $class->mk_classdata($name); + my $obj; + eval { $obj = $plugin->new(@args) }; + die qq/Couldn't instantiate instant plugin "$plugin", "$@"/ if $@; + $class->$name($obj); + $class->log->debug(qq/Initialized instant plugin "$plugin" as "$name"/) + if $class->debug; +} =back =head1 LIMITATIONS -FCGI and mod_perl2 support are considered experimental and may contain bugs. - -You may encounter problems accessing the built in test server on public ip -addresses on the internet, thats because of a bug in HTTP::Daemon. +mod_perl2 support are considered experimental and may contain bugs. =head1 SUPPORT