/usr/share/perl5/Text/WordDiff/HTMLTwoLines.pm is in libtext-worddiff-perl 0.08-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | package Text::WordDiff::HTMLTwoLines;
use strict;
use HTML::Entities qw(encode_entities);
use vars qw($VERSION @ISA);
$VERSION = '0.08';
@ISA = qw(Text::WordDiff::Base);
sub file_header {
my $self = shift;
my $fn1 = $self->filename_a;
my $fn2 = $self->filename_b;
if (defined $fn1 && defined $fn2)
{ my $p1 = $self->filename_prefix_a;
my $t1 = $self->mtime_a;
my $p2 = $self->filename_prefix_b;
my $t2 = $self->mtime_b;
$self->{__str1} = '<div class="file"><span class="fileheader">'
. "$p1 $fn1" . (defined $t1 ? " " . localtime $t1 : '') . '</span>';
$self->{__str2} = '<div class="file"><span class="fileheader">'
. "$p2 $fn2" . (defined $t2 ? " " . localtime $t2 : '') . '</span>';
}
else
{ $self->{__str1} = $self->{__str2} = '<div class="file">';
}
return '';
}
sub hunk_header {
my $self = shift;
$self->{__str1} .= '<span class="hunk">';
$self->{__str2} .= '<span class="hunk">';
return '';
}
sub hunk_footer {
my $self = shift;
$self->{__str1} .= '</span>';
$self->{__str2} .= '</span>';
return '';
}
sub file_footer {
my $self = shift;
return $self->{__str1} . "</div>\n" . $self->{__str2} . "</div>\n";
}
sub same_items {
my $self = shift;
$self->{__str1} .= encode_entities( join '', @_ );
$self->{__str2} .= encode_entities( join '', @_ );
return '';
}
sub delete_items {
my $self = shift;
$self->{__str1} .= '<del>' . encode_entities( join '', @_ ) . '</del>';
return '';
}
sub insert_items {
my $self = shift;
$self->{__str2} .= '<ins>' . encode_entities( join '', @_ ) . '</ins>';
return '';
}
1;
__END__
=head1 Name
Text::WordDiff::HTMLTwoLines - XHTML formatting for Text::WordDiff with content on two lines
=head1 Synopsis
use Text::WordDiff;
my $diff = word_diff 'file1.txt', 'file2.txt'; { STYLE => 'HTMLTwoLines' };
my $diff = word_diff \$string1, \$string2, { STYLE => 'HTMLTwoLines' };
my $diff = word_diff \*FH1, \*FH2, { STYLE => 'HTMLTwoLines' };
my $diff = word_diff \&reader1, \&reader2, { STYLE => 'HTMLTwoLines' };
my $diff = word_diff \@records1, \@records2, { STYLE => 'HTMLTwoLines' };
# May also mix input types:
my $diff = word_diff \@records1, 'file_B.txt', { STYLE => 'HTMLTwoLines' };
=head1 Description
This class subclasses Text::WordDiff::Base to provide a XHTML formatting for
Text::WordDiff. See L<Term::WordDiff|Term::WordDiff> for usage details. This
class should never be used directly.
Text::WordDiff::HTMLTwoLines formats word diffs for viewing in a Web browser.
The output is similar to that produced by
L<Term::WordDiff::HTML|Term::WordDiff::HTML> but the two lines (or files,
records, etc.) are shown separately, with deleted items highlighted in the
first line and inserted items highlighted in the second. HTMLTwoLines puts a
span tag around each word or set of words in the diff.
The diff content is highlighted as follows:
=over
=item * C<< <div class="file"> >>
The inputs to C<word_diff()> are each contained in a div element of class
"file". All the following results are subsumed by these elements.
=over
=item * C<< <span class="fileheader"> >>
The header section for the files being C<diff>ed, usually something like:
--- in.txt Thu Sep 1 12:51:03 2005
for the first file, and
+++ out.txt Thu Sep 1 12:52:12 2005
for the second.
This element immediately follows the opening "file" C<< <div> >> element, but
will not be present if Text::WordDiff cannot determine the file names for both
files being compared.
=item * C<< <span class="hunk"> >>
This element contains a single diff "hunk". Each hunk may contain the
following elements:
=over
=item * C<< <ins> >>
Inserted content.
=item * C<< <del> >>
Deleted content.
=back
=back
=back
You may do whatever you like with these elements and classes; I highly
recommend that you style them using CSS. You'll find an example CSS file in
the F<eg> directory in the Text-WordDiff distribution.
=head1 See Also
=over
=item L<Text::WordDiff|Text::WordDiff>
=item L<Text::WordDiff::ANSIColor|Text::WordDiff::HTML>
=item L<Text::WordDiff::ANSIColor|Text::WordDiff::ANSIColor>
=back
=head1 Author
Amelia Ireland <join(".", $firstname, $lastname) . "@gmail.com">
=head1 Copyright and License
Copyright (c) 2011 Amelia Ireland. Some Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the
same terms as Perl itself.
=cut
|