Re: prestore hook
[email protected] (Joshua N Pritikin) Sun, 15 May 2005 15:18:57 +0530
| Newsgroups | perl.kwiki |
|---|---|
| Message-ID | <[email protected]> |
On Sat, 2005-05-14 at 23:19 -0700, Brian Ingerson wrote: > You may, but can't you attach these methods as a pre hook and a post hook to > page:store_content respectively? I don't think so. > Maybe send a patch of what you want, and I'll see if it might be possible > another way or not. OK, see the attached patch. I want to add a hook before store_content_commit or after store_content_prepare to run "diff -u file.new file | mail ...". -- If you are an American then support http://fairtax.org (Permanently replace 50,000+ pages of tax law with about 200 pages.)
spoon1
(text/plain, 1.2 KB)
--- .tilde/!usr!local!share!perl!5.8.4!Spoon!ContentObject.pm~ Thu Apr 7 09:07:14 2005
+++ /usr/local/share/perl/5.8.4/Spoon/ContentObject.pm Sun May 15 15:14:37 2005
@@ -72,25 +72,32 @@
sub store {
$self->assert_writable;
- $self->store_content or return;
+ $self->store_content_prepare or return;
+ $self->store_content_commit;
$self->store_metadata;
return if $self->force;
return $self;
}
-sub store_content {
+sub store_content_prepare {
my $content = $self->content;
if ($content) {
$content =~ s/\r//g;
$content =~ s/\n*\z/\n/;
}
- my $file = io->file($self->file_path)->utf8;
+ my $orig = io->file($self->file_path)->utf8;
unless ($self->force) {
- return if $file->exists and
- $content eq $file->all;
+ return if $orig->exists and
+ $content eq $orig->all;
}
- $file->print($content);
+ $content > io($self->file_path.'.new');
return $self;
+}
+
+sub store_content_commit {
+ my $fp = $self->file_path;
+ rename("$fp.new", $fp) or warn "rename $fp.new $fp: $!"; #die?
+ return $self;
}
sub store_metadata {
signature.asc
(application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQBChxsIqcqnlKSmC70RArnpAJ4lZpDJVcfeLseIyvIE1lraS5JRQACeIyJV OxuTmEiWs1Hy4S9I9DTQt+g= =zPyB -----END PGP SIGNATURE-----