Konstrukt

 view release on metacpan or  search on metacpan

lib/Konstrukt/Plugin/diff.pm  view on Meta::CPAN

=head1 NAME

Konstrukt::Plugin::diff - Print out an XHTML table with the difference between two texts

=head1 SYNOPSIS

B<Usage:>

 	<& diff &>
		<$ left $>
		1
		2
		3
		<$ / $>
		<$ right $>
		1
		3
		<$ / $>
	<& / &>

or

	<!-- set another amount of "context" lines -->
	<& diff context="2" &>
		...
	<& / &>

or

	<!-- define a header for the columns -->
	<& diff left_header="text a" right_header="text b" &>
		...
	<& / &>
	
B<Result:>

A table showing the difference between the two texts.

=head1 DESCRIPTION

With this plugin you compare two texts and put out the difference as an XHTML table.

You may also use its Perl interface:

	my $diff = use_plugin 'diff';
	my $html = $diff->diff("1\n2\n3", "1\n3");

=head1 CONFIGURATION
	
You may configure the default behaviour of the diff plugin:

	#context: number of (equal) lines around a diff hunk
	diff/context 1048576

=cut

package Konstrukt::Plugin::diff;

use strict;
use warnings;

use Konstrukt::Debug;
use Konstrukt::Parser::Node;
use Text::Diff ();

use base qw/Konstrukt::Plugin Text::Diff::Base/; #inheritance


=head1 METHODS

=head2 init

Initialization.

=cut
sub init {
	my ($self) = @_;
	
	#set default settings
	$Konstrukt::Settings->default("diff/context", 1048576);
	
	return 1;
}
#= /init

=head2 prepare

We can do the work already in the prepare run if there is only static content
inside the tag.

B<Parameters>:

=over

=item * $tag - Reference to the tag (and its children) that shall be handled.

=back

=cut
sub prepare {
	my ($self, $tag) = @_;



( run in 0.500 second using v1.01-cache-2.11-cpan-2398b32b56e )