Re: prestore hook

[email protected] (Joshua N Pritikin) Sun, 15 May 2005 15:47:20 +0530
Newsgroups perl.kwiki
Message-ID <[email protected]>
On Sun, 2005-05-15 at 15:18 +0530, Joshua N Pritikin wrote:
> I want to add a hook before store_content_commit or after
> store_content_prepare to run "diff -u file.new file | mail ...".

To make this concrete, here is a Kwiki::Notify::Mail patch.

-- 
If you are an American then support http://fairtax.org
 (Permanently replace 50,000+ pages of tax law with about 200 pages.)
mail (text/plain, 796 B)
--- Mail.pm	Wed Jan 26 02:19:23 2005
+++ /usr/local/share/perl/5.8.4/Kwiki/Notify/Mail.pm	Sun May 15 15:36:46 2005
@@ -21,9 +21,8 @@
 
 sub register {
     my $registry = shift;
-    $registry->add(hook => 'page:store',
-		   post => 'notify',
-		  );
+    $registry->add(hook => 'page:store_content_commit',
+		   pre => 'notify');
 }
 
 sub notify {
@@ -43,7 +42,10 @@
 			      $page_name,
 			      $edited_by)   || 'unknown';
 
-    my $body        = "$site_title page $page_name edited by $edited_by\n";
+    my $body        = "$site_title page $page_name edited by $edited_by\n\n";
+
+    my $file_path = $self->file_path;
+    $body .= `diff --text -bBiu $file_path $file_path.new`;
 
     $notify_mail_obj->mail_it($to,$from,$subject,$body);
     return $self;
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQBChyGvqcqnlKSmC70RAsYjAKDB+0+dtG5cGouuUtOENsFYwSJWAACfS4c3
muK6bNRxsYAYQ7ZehAQSIHU=
=MlRK
-----END PGP SIGNATURE-----