Wiki::...n::Diff(3pm)

πŸ“¦
version 0.12 Β· 3 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– Wiki::Toolkit::Plugin::Diff β€” the full tea πŸ’–

okay so bestie, welcome to Wiki::Toolkit::Plugin::Diff, a little Perl module in the User Contributed Perl Documentation family that formats the differences between two Wiki::Toolkit pages. it's giving "spot the change" but make it cute. ✨


🌸 SYNOPSIS 🌸

use Wiki::Toolkit::Plugin::Diff;
my $plugin = Wiki::Toolkit::Plugin::Diff->new;
$wiki->register_plugin( plugin => $plugin );   # called before any node reads
my %diff = $plugin->differences( node => 'Imperial College',
                              left_version => 3,
                              right_version => 5);

πŸ¦‹ DESCRIPTION πŸ¦‹

so basically it's a plug-in for Wiki::Toolkit sites, and it hands you a nice little extract of the differences between two versions of a node. that's it, that's the vibe. no cap. πŸ’…


πŸŽ€ BASIC USAGE πŸŽ€

differences

my %diff_vars = $plugin->differences(
    node          => "Home Page",
    left_version  => 3,
    right_version => 5
);

it takes a lil series of key/value pairs, bestie:

  • left_version β€” the node version whose content we're considering canonical. πŸ‘‘ the main character, if you will.
  • right_version β€” the node version that we're showing the differences from. the comparison girlie.
  • meta_include β€” filters the list of metadata fields so you only get a certain list in the diff output. the default? include literally all the metadata fields. slay.
  • meta_exclude β€” filters the list of metadata fields so certain ones get excluded from the diff output. the default is this exact list, kept around to match previous version (OpenGuides) behaviour:
"qw(
username
comment
__categories__checksum
__locales__checksum )"

ngl, the module itself says this list is hopelessly inadequate, especially for OpenGuides 😭. hopefully future wiki designers will use the meta_include parameter to specify exactly what metadata they want showing up on the diff. periodt.

the differences method returns a list of key/value pairs, which you can assign straight to a hash:

  • left_version β€” the node version whose content we're considering canonical. (yes, again. iconic of her.)
  • right_version β€” the node version that we're showing the differences from.
  • content β€” the (formatted) contents of the Left version of the node. ✨
  • diff β€” an array of hashrefs of "hunks" of differences between the versions. it's assumed that the display will be rendered in HTML, and SPAN tags are inserted with a class of diff1 or diff2, to highlight which individual words have actually changed. display the contents of diff using a <table>, with each member of the array corresponding to a row <TR>, and keys {left} and {right} being two columns <TD>.

usually you're gonna want to feed this through a templating system, such as Template Toolkit, which makes iterating the AoH very easy. ate. πŸ”₯


🌈 ADVANCED 🌈

Wiki::Toolkit::Plugin::Diff allows for a more flexible approach than HTML-only rendering of pages. in particular, there are optional parameters to the constructor which control the fine detail of the resultant output. lowkey chef's kiss.

if that's still not enough, the module is also subclassable, and the programmer can supply alternative methods. go off, bestie. πŸ‘‘

🧚 METHODS 🧚

most of these are called internally by the plugin, but they provide hooks for alternative code if the module is subclassed. very demure, very mindful.

new

my $plugin = Wiki::Toolkit::Plugin::Diff->new( option => value, option => value...);

here, option can be one of the following:

  • metadata_separator β€” a string which is inserted between each metadata field, and also between the contents and the metadata. this defaults to "<br />\n", so as to render each metadata field on a new line. πŸŽ€
  • line_number_format β€” used to lay out the head line number for a difference hunk. the string is eval'ed with $_ containing the line number. default is "== Line \$_ ==".
  • word_matcher β€” is a regular expression, used to tokenize the input string. this is the way of grouping together atomic sequences, so as to give a readable result. the default is the following:
            &.+?;                   #HTML special characters e.g. &lt;
            |<br\s*/>               #Line breaks
            |\w+\s*                 #Word with trailing spaces
            |.                      #Any other single character

differences

see above. πŸ‘†

line_number

this method is called to format a line number into a suitable string. the supplied routine performs the necessary substitution of $self->{line_number_format} using eval.

serialise_metadata

the purpose of this method is to turn a metadata hash into a string suitable for diffing. glow up, metadata. ✨

content_escape

this method is used to apply the necessary quoting or escaping of characters that could appear in the content body, that could interfere with the rendering of the diff text. so like, safety first bb. 🫢

intradiff

this method turns an array of hunks as returned by VCS::Lite::Delta->hunks into a side by side diff listing, with highlights indicating different words and punctuation.

currently, this is hardcoded to present the differences with HTML tags. πŸ’€

this module is a prime candidate for migration into VCS::Lite, where this functionality really belongs.

get_token

this allows the "false positive" bug discovered by Earle Martin to be solved (rt.cpan.org #6284). effectively, the input strings (diff1 and diff2) are tokenised using the word_matcher regexp (see above), and turned into arrays of tokens.

the default regexp absorbs trailing whitespace, to give a more readable result. however, if a word is followed by differing whitespace or no whitespace at all, this was throwing up a diff. πŸ™ˆ

the get_token method supplied removes trailing whitespace from the key values before they are compared. iykyk.


πŸ’€ TODO πŸ’€

move intradiff functionality into VCS::Lite.


πŸ› BUGS AND ENHANCEMENTS πŸ›

please use rt.cpan.org to report any bugs in this module. if you have any ideas for how this module could be enhanced, please email the author, or post to the Wiki::Toolkit list (cgi (hyphen) wiki (hyphen) dev (at) earth (dot) li).


πŸ‘‘ AUTHOR πŸ‘‘

I. P. Williams (ivorw_openguides [at] xemaps {dot} com) The Wiki::Toolkit team (http://www.wiki-toolkit.org/)


     Copyright (C) 2003-2004 I. P. Williams (ivorw_openguides [at] xemaps {dot} com).
     Copyright (C) 2006 the Wiki::Toolkit team (http://www.wiki-toolkit.org/)
     All Rights Reserved.

this module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. fr fr. 🌸


🌟 SEE ALSO 🌟

  • VCS::Lite
  • Wiki::Toolkit
  • Wiki::Toolkit::Plugin
  • OpenGuides

okay bestie that's the whole page, and if you wanna know where this lil legend came from: it's perl v5.40.1, dated 2025-04-07. go forth and diff, you gorgeous creature πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from