Text-Diff-FormattedHTML-0.08/ 0000755 0001750 0001750 00000000000 13044115027 014266 5 ustar ambs ambs Text-Diff-FormattedHTML-0.08/MANIFEST 0000644 0001750 0001750 00000000445 13044115027 015422 0 ustar ambs ambs Changes
lib/Text/Diff/FormattedHTML.pm
Makefile.PL
MANIFEST This list of files
README
t/00-load.t
t/pod-coverage.t
t/pod.t
META.yml Module YAML meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
Text-Diff-FormattedHTML-0.08/META.yml 0000644 0001750 0001750 00000001216 13044115027 015537 0 ustar ambs ambs ---
abstract: 'Generate a colorful HTML diff of strings/files.'
author:
- 'Alberto Simoes '
build_requires:
ExtUtils::MakeMaker: '0'
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: Text-Diff-FormattedHTML
no_index:
directory:
- t
- inc
requires:
Algorithm::Diff: '1.1900'
File::Slurp: '0'
String::Diff: '0.04'
Test::More: '0'
version: '0.08'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
Text-Diff-FormattedHTML-0.08/t/ 0000755 0001750 0001750 00000000000 13044115027 014531 5 ustar ambs ambs Text-Diff-FormattedHTML-0.08/t/00-load.t 0000644 0001750 0001750 00000000546 11614266524 016071 0 ustar ambs ambs #!perl
use Test::More tests => 1;
BEGIN {
use_ok( 'Text::Diff::FormattedHTML' ) || print "Bail out!\n";
}
diag( "Testing Text::Diff::FormattedHTML $Text::Diff::FormattedHTML::VERSION, Perl $], $^X" );
# open OUT, ">_.html";
# print OUT "\n";
# print OUT diff_files('t/fileA', 't/fileB');
# close OUT;
Text-Diff-FormattedHTML-0.08/t/pod-coverage.t 0000644 0001750 0001750 00000001047 11612553177 017306 0 ustar ambs ambs use strict;
use warnings;
use Test::More;
# Ensure a recent version of Test::Pod::Coverage
my $min_tpc = 1.08;
eval "use Test::Pod::Coverage $min_tpc";
plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage"
if $@;
# Test::Pod::Coverage doesn't require a minimum Pod::Coverage version,
# but older versions don't recognize some common documentation styles
my $min_pc = 0.18;
eval "use Pod::Coverage $min_pc";
plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage"
if $@;
all_pod_coverage_ok();
Text-Diff-FormattedHTML-0.08/t/pod.t 0000644 0001750 0001750 00000000350 11612553177 015511 0 ustar ambs ambs #!perl -T
use strict;
use warnings;
use Test::More;
# Ensure a recent version of Test::Pod
my $min_tp = 1.22;
eval "use Test::Pod $min_tp";
plan skip_all => "Test::Pod $min_tp required for testing POD" if $@;
all_pod_files_ok();
Text-Diff-FormattedHTML-0.08/lib/ 0000755 0001750 0001750 00000000000 13044115027 015034 5 ustar ambs ambs Text-Diff-FormattedHTML-0.08/lib/Text/ 0000755 0001750 0001750 00000000000 13044115027 015760 5 ustar ambs ambs Text-Diff-FormattedHTML-0.08/lib/Text/Diff/ 0000755 0001750 0001750 00000000000 13044115027 016630 5 ustar ambs ambs Text-Diff-FormattedHTML-0.08/lib/Text/Diff/FormattedHTML.pm 0000644 0001750 0001750 00000020607 13044114046 021605 0 ustar ambs ambs package Text::Diff::FormattedHTML;
use 5.006;
use strict;
use warnings;
use File::Slurp;
use Algorithm::Diff 'traverse_balanced';
use String::Diff 'diff';
use base 'Exporter';
our @EXPORT = (qw'diff_files diff_strings diff_css');
=head1 NAME
Text::Diff::FormattedHTML - Generate a colorful HTML diff of strings/files.
=head1 VERSION
Version 0.08
=cut
our $VERSION = '0.08';
=head1 SYNOPSIS
use Text::Diff::FormattedHTML;
my $output = diff_files($file1, $file2);
# for strings
my $output = diff_strings( { vertical => 1 }, $file1, $file2);
# as you might want some CSS:
open OUT, ">diff.html";
print OUT "\n";
print OUT diff_files('fileA', 'fileB');
close OUT;
=head1 DESCRIPTION
Presents in a (nice?) HTML table the difference between two files or strings.
Inspired on GitHub diff view.
=head1 SUBROUTINES
=head2 diff_files
my $html = diff_files("filename1", "filename2");
C and C support a first optional argument
(an hash reference) where options can be set.
Valid options are:
=over 4
=item C
Can be set to a true value, for a more compact table.
=item C
Makes tables look nicer when there is a side with too many new lines.
=back
=cut
sub diff_files {
my $settings = {};
$settings = shift if ref($_[0]) eq "HASH";
my ($f1, $f2) = @_;
die "$f1 not available" unless -f $f1;
die "$f2 not available" unless -f $f2;
my @f1 = read_file $f1;
my @f2 = read_file $f2;
_internal_diff($settings, \@f1, \@f2);
}
=head2 diff_strings
my $html = diff_strings("string1", "string2");
Compare strings. First split by newline, and then treat them as file
content (see function above).
=cut
sub diff_strings {
my $settings = {};
$settings = shift if ref($_[0]) eq "HASH";
my ($s1, $s2) = @_;
my @f1 = split /\n/, $s1;
my @f2 = split /\n/, $s2;
_internal_diff($settings, \@f1, \@f2);
}
=head2 diff_css
my $css = diff_css;
Return the default css. You are invited to override it.
=cut
sub diff_css {
return <<'EOCSS';
table.diff {
border-collapse: collapse;
border-top: solid 1px #999999;
border-left: solid 1px #999999;
}
table.diff td {
padding: 2px;
padding-left: 5px;
padding-right: 5px;
border-right: solid 1px #999999;
border-bottom: solid 1px #999999;
}
table.diff td:nth-child(1),
table.diff td:nth-child(2) {
background-color: #deedff;
}
table.diff tr.change,
table.diff tr.disc_a,
table.diff tr.disc_b {
background-color: #ffffdd;
}
table.diff tr.del {
background-color: #ffeeee;
}
table.diff tr.ins {
background-color: #eeffee;
}
table.diff td:nth-child(3),
table.diff td:nth-child(4) {
font-family: monospace;
white-space: pre;
}
table.diff td ins {
padding: 2px;
color: #009900;
background-color: #ccffcc;
text-decoration: none;
font-weight: bold;
}
table.diff td del {
padding: 2px;
color: #990000;
background-color: #ffcccc;
text-decoration: none;
font-weight: bold;
}
EOCSS
}
sub _protect {
my $x = shift;
if ($x) {
$x =~ s/&/&/g;
$x =~ s/</g;
$x =~ s/>/>/g;
}
return $x;
}
sub _internal_diff {
my ($settings, $sq1, $sq2) = @_;
my $get = sub {
my ($l, $r) = @_;
$l = $sq1->[$l];
$r = $sq2->[$r];
chomp($l) if $l;
chomp($r) if $r;
return ($l,$r);
};
my ($ll, $rl);
my $line = sub {
sprintf("
%s
%s
%s
%s
\n", @_);
};
if ($settings->{limit_onesided}) {
# Prevent really long lists where we just go on showing
# all of the values that one side does not have
if($settings->{vertical}){
die "Option: [vertical] is incompatible with [limit_empty]";
}
my ($am_skipping, $num_since_lc, $num_since_rc) = (0, 0, 0);
$line = sub {
my ($class, $ln, $rn, $l, $r) = @_;
my $out = '';
if(
($class ne 'disc_a') &&
($class ne 'disc_b')
){
if($am_skipping){
$out .= "($num_since_lc, $num_since_rc)\n";
}
($am_skipping, $num_since_lc, $num_since_rc) = (0, 0, 0);
}elsif($class ne 'disc_a'){
$num_since_lc++;
}elsif($class ne 'disc_b'){
$num_since_rc++;
}
if(
($num_since_lc > $settings->{limit_onesided}) ||
($num_since_rc > $settings->{limit_onesided})
){
if(!$am_skipping){
$out = '
\n";
}
sub _retag {
my $x = shift;
$x =~ s/#(.?(?:del|ins))#/<$1>/g;
return $x;
}
=head1 AUTHOR
Alberto Simoes, C<< >>
=head1 BUGS
Please report any bugs or feature requests to
C, or through the web
interface at
L.
I will be notified, and then you'll automatically be notified of
progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Text::Diff::FormattedHTML
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker (report bugs here)
L
=item * AnnoCPAN: Annotated CPAN documentation
L
=item * CPAN Ratings
L
=item * Search CPAN
L
=back
=head1 ACKNOWLEDGEMENTS
=head1 LICENSE AND COPYRIGHT
Copyright 2011 Alberto Simoes.
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
=cut
1; # End of Text::Diff::FormattedHTML
Text-Diff-FormattedHTML-0.08/META.json 0000644 0001750 0001750 00000002066 13044115027 015713 0 ustar ambs ambs {
"abstract" : "Generate a colorful HTML diff of strings/files.",
"author" : [
"Alberto Simoes "
],
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "Text-Diff-FormattedHTML",
"no_index" : {
"directory" : [
"t",
"inc"
]
},
"prereqs" : {
"build" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"runtime" : {
"requires" : {
"Algorithm::Diff" : "1.1900",
"File::Slurp" : "0",
"String::Diff" : "0.04",
"Test::More" : "0"
}
}
},
"release_status" : "stable",
"version" : "0.08",
"x_serialization_backend" : "JSON::PP version 2.27400_02"
}
Text-Diff-FormattedHTML-0.08/Changes 0000644 0001750 0001750 00000001747 13044103442 015570 0 ustar ambs ambs Revision history for Text-Diff-FormattedHTML
0.08 Tue Jan 31 12:45:07 WET 2017
- add option 'limit_onesided' (thanks to Carl Eklof)
0.07 Sun Sep 11 14:14:30 WEST 2011
- fix 0.05 change, that tried to fix 0.04 change. Great!
0.06 Sun Sep 11 13:27:30 WEST 2011
- It was dark, I was tired, and forgot to run 'make test'
0.05 Sat Sep 10 21:09:25 WEST 2011
- fix the change added in the latest version;
0.04 Fri Aug 26 21:05:20 WEST 2011
- support different colors in vertical mode for "before" and "after";
0.03 Thu Jul 28 15:08:34 WEST 2011
- removing -T from 00_load :-/
0.02 Sat Jul 23 18:44:08 WEST 2011
- support vertical mode
- better CSS support by row type;
- use that CSS support for changed lines;
- make background green/red more noticiing;
0.01 Sat Jul 23 16:25:50 WEST 2011
First version, released on an unsuspecting world.
- basic functionality. patches