Added plugin() method for instant plugins
Sebastian Riedel [Tue, 19 Apr 2005 18:02:33 +0000 (18:02 +0000)]
Changes
lib/Catalyst.pm

diff --git a/Changes b/Changes
index 219aec1..71702c3 100644 (file)
--- 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 <andy@hybridized.org>
+        - added plugin() method for instant plugins
+        - FCGI is no more considered experimental
 
 5.02  Mon Apr 18 10:00:00 2005
         - fixed manifest
index ac8b853..0f7cd81 100644 (file)
@@ -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<Catalyst::Log> object.  To use your own log class:
 Your log class should implement the methods described in the C<Catalyst::Log>
 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