Re: prestore hook
[email protected] (Carlos Escribano) Mon, 16 May 2005 03:17:32 +0200
| Newsgroups | perl.kwiki |
|---|---|
| Message-ID | <[email protected]> |
El Lunes 16 Mayo 2005 02:53, Brian Ingerson escribió:
> There is something about this patch that doesn't sit right with me...
>
> Why can't you just do a pre/page:store hook to grab the old content,
> save it in memory, and then diff it with current content in a
> post/page:store hook?
Or use data from archive and compare it with the new content. With this way I
can make the message body in a subscription to changes plugin [1]
my $revisions = $self->revision_numbers;
if ($#$revisions == 0) {
$subscription_obj->body($self->content);
} else {
my $revision_id = $#$revisions -1;
my $archive = $self->hub->archive;
# now the diff
my $current = [ split /\n/, $self->content ];
my $this_revision = [ split /\n/, $archive->fetch( $self,
$revision_id ) ];
my $body;
my @diff = Algorithm::Diff::diff( $this_revision, $current );
foreach my $chunk (@diff) {
foreach my $line (@$chunk) {
my ($sign, $lineno, $text) = @$line;
$body .= sprintf "%4d$sign %s\n", $lineno+1, $text;
}
$body .= "--------\n";
}
$subscription_obj->body($body);
}
[1]
https://barcelona.pm.org:8000/kwiki-subscription/trunk/lib/Kwiki/Subscription/Changes.pm
(in progress)
signature.asc
(application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQBCh/S0crdYjP8t0J0RAtN3AKCktpFQ8N76/pZ8EbkTydCdErHRQQCgyOlC Xm84eQRd0EYqOiEGbIN0nTE= =AMP9 -----END PGP SIGNATURE-----