View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Ivor Williams > CGI-Wiki-Plugin-Diff > CGI::Wiki::Plugin::Diff



Annotate this POD


Open  0
View/Report Bugs
Module Version: 0.09   Source  


CGI::Wiki::Plugin::Diff - format differences between two CGI::Wiki pages


  use CGI::Wiki::Plugin::Diff;
  my $plugin = CGI::Wiki::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);


A plug-in for CGI::Wiki sites, which provides a nice extract of differences between two versions of a node.



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

Takes a series of key/value pairs:

The differences method returns a list of key/value pairs, which can be assigned to a hash:


The node version whose content we're considering canonical.


The node version that we're showing the differences from.


The (formatted) contents of the Left version of the node.


An array of hashrefs of hunks of differences between the versions. It is 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 will want to feed this through a templating system, such as Template Toolkit, which makes iterating the AoH very easy.


CGI::Wiki::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 fine detail of the resultant output.

If this is not sufficient, the module is also subclassable, and the programmer can supply alternative methods.


Most of these are called internally by the plugin, but provide hooks for alternative code if the module is subclassed.

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

Here, option can be one of the following:


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.


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 \$_ ==" .


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

see above.


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.


The purpose of this method is to turn a metadata hash into a string suitable for diffing.


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.


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.


This allows the "false positive" bug discovered by Earle Martin to be solved ( #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.


Move intradiff functionality into VCS::Lite.


Please use 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 CGI::Wiki list (cgi (hyphen) wiki (hyphen) dev (at) earth (dot) li).


I. P. Williams (ivorw_openguides [at] xemaps {dot} com)


     Copyright (C) 2003-2004 I. P. Williams (ivorw_openguides [at] xemaps {dot} com).
     All Rights Reserved.

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


VCS::Lite, CGI::Wiki, CGI::Wiki::Plugin, OpenGuides

syntax highlighting: