Feature Proposal: Add a finishHandler() for plugins

Motivation

We do have an initPlugin() that is called right at the beginning. However, there's a complementary finish handler missing, that can be used to clean up, e.g. closing database connections, flush caches to disk etc.

Description and Documentation

This will dispatch all finishHandler in all plugins before finishing any other object in the session. This change touches the files TWiki::Plugin(s).pm.

Examples

Impact

API
edit

Implementation

Index: Plugins.pm
===================================================================
--- Plugins.pm  (revision 15864)
+++ Plugins.pm  (working copy)
@@ -150,6 +150,9 @@
 # documentation" of the live fields in the object.
 sub finish {
     my $this = shift;
+
+    _dispatch( $this, 'finishHandler');
+
     undef $this->{registeredHandlers};
     foreach (@{$this->{plugins}}) {
         $_->finish();
www-data@michadaum:~/twiki/MAIN/lib/TWiki$ svn diff Plugins.pm Plugin.pm
Index: Plugins.pm
===================================================================
--- Plugins.pm  (revision 15864)
+++ Plugins.pm  (working copy)
@@ -150,6 +150,9 @@
 # documentation" of the live fields in the object.
 sub finish {
     my $this = shift;
+
+    _dispatch( $this, 'finishHandler');
+
     undef $this->{registeredHandlers};
     foreach (@{$this->{plugins}}) {
         $_->finish();
Index: Plugin.pm
===================================================================
--- Plugin.pm   (revision 15864)
+++ Plugin.pm   (working copy)
@@ -43,6 +43,7 @@
    'beforeSaveHandler',            # 1.010
    'commonTagsHandler',            # 1.000
    'completePageHandler',          # 1.100
+   'finishHandler',                     # 1.100
    'earlyInitPlugin',              # 1.020
    'endRenderingHandler',          # 1.000 DEPRECATED
    'initPlugin',                   # 1.000

-- Contributors: MichaelDaum - 04 Dec 2007

Discussion

Good idea. Gets my vote. BTW perl destructors are called DESTROY, but this isn't a destructor, it's different because in a mod_perl environment the DESTROY is never called for a lot of objects (hence the adoption of finish for cleanup methods that are not strictly destructors)

-- CrawfordCurrie - 07 Dec 2007

Accepted. Noone is against and the 14 days are over.

-- KennethLavrsen - 25 Dec 2007

Michael hadn't done this, so I did it.

-- CrawfordCurrie - 19 Mar 2009
Topic revision: r7 - 06 Dec 2010, GeorgeClark - This page was cached on 17 Dec 2017 - 01:29.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License