Tags:
create new tag
, view all tags

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

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

oh, Yes please.

-- SvenDowideit - 04 Dec 2007

As long as it is AFTER 4.2 I have no objections.

-- KennethLavrsen - 04 Dec 2007

I like the idea. The name is good too. Wondering if finishHandler is the most intuitive name? C++ calls it destructor, Java calls it finalize, it could be called cleanup or?

-- PeterThoeny - 06 Dec 2007

TWiki already uses sub finish() so it would be consistent.

-- SvenDowideit - 06 Dec 2007

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. Ready to be implemented on Georgetown.

-- KennethLavrsen - 25 Dec 2007

Useful feature for plugin developers. Anyone interested in driving this feature?

-- PeterThoeny - 2010-07-29

Edit | Attach | Watch | Print version | History: r9 < r8 < r7 < r6 < r5 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r9 - 2010-07-29 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.