Text-Diff-FormattedHTML-0.08/0000755000175000017500000000000013044115027014266 5ustar ambsambsText-Diff-FormattedHTML-0.08/MANIFEST0000644000175000017500000000044513044115027015422 0ustar ambsambsChanges 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.yml0000644000175000017500000000121613044115027015537 0ustar ambsambs--- 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/0000755000175000017500000000000013044115027014531 5ustar ambsambsText-Diff-FormattedHTML-0.08/t/00-load.t0000644000175000017500000000054611614266524016071 0ustar ambsambs#!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.t0000644000175000017500000000104711612553177017306 0ustar ambsambsuse 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.t0000644000175000017500000000035011612553177015511 0ustar ambsambs#!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/0000755000175000017500000000000013044115027015034 5ustar ambsambsText-Diff-FormattedHTML-0.08/lib/Text/0000755000175000017500000000000013044115027015760 5ustar ambsambsText-Diff-FormattedHTML-0.08/lib/Text/Diff/0000755000175000017500000000000013044115027016630 5ustar ambsambsText-Diff-FormattedHTML-0.08/lib/Text/Diff/FormattedHTML.pm0000644000175000017500000002060713044114046021605 0ustar ambsambspackage 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; } 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 = ''; $am_skipping = 1; } $out .= '. '; return $out; } $out .= sprintf("%s%s%s%s\n", @_); return $out; }; } if ($settings->{vertical}) { $line = sub { my $out = ""; my ($class, $ln, $rn, $l, $r) = @_; if ($l eq $r) { $out .= sprintf("%s%s%s\n", $class, $ln, $rn, $l); } else { $class eq "disc_a" && ($class = "disc_a del"); $class eq "disc_b" && ($class = "disc_b ins"); $class eq "change" && ($class = "change del"); $l and $out .= sprintf("%s%s\n", $class, $ln, $l); $class eq "change del" && ($class = "change ins"); $r and $out .= sprintf("%s%s\n", $class, $rn, $r); } $out } } my $out = "\n"; traverse_balanced $sq1, $sq2, { MATCH => sub { my ($l, $r) = $get->(@_); ++$ll; ++$rl; $out .= $line->('match', $ll, $rl, _protect($l), _protect($r)); }, DISCARD_A => sub { my ($l, $r) = $get->(@_); ++$ll; $out .= $line->('disc_a', $ll, '', _protect($l), ''); }, DISCARD_B => sub { my ($l, $r) = $get->(@_); ++$rl; $out .= $line->('disc_b', '', $rl, '', _protect($r)); }, CHANGE => sub { my ($l, $r) = $get->(@_); my $diff = diff($l, $r, remove_open => '#del#', remove_close => '#/del#', append_open => '#ins#', append_close => '#/ins#', ); ++$ll; ++$rl; $out .= $line->('change', $ll, $rl, _retag(_protect($diff->[0])), _retag(_protect($diff->[1]))); }, }; $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.json0000644000175000017500000000206613044115027015713 0ustar ambsambs{ "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/Changes0000644000175000017500000000174713044103442015570 0ustar ambsambsRevision 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 'Text::Diff::FormattedHTML', AUTHOR => q{Alberto Simoes }, VERSION_FROM => 'lib/Text/Diff/FormattedHTML.pm', ABSTRACT_FROM => 'lib/Text/Diff/FormattedHTML.pm', ($ExtUtils::MakeMaker::VERSION >= 6.3002 ? ('LICENSE'=> 'perl') : ()), PL_FILES => {}, PREREQ_PM => { 'Test::More' => '0', 'Algorithm::Diff' => '1.1900', 'File::Slurp' => '0', 'String::Diff' => '0.04', }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Text-Diff-FormattedHTML-*' }, ); Text-Diff-FormattedHTML-0.08/README0000644000175000017500000000211511612564111015146 0ustar ambsambsText-Diff-FormattedHTML Produces an HTML table with a nice diff of two strings/files. INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install SUPPORT AND DOCUMENTATION After installing, you can find documentation for this module with the perldoc command. perldoc Text::Diff::FormattedHTML You can also look for information at: RT, CPAN's request tracker (report bugs here) http://rt.cpan.org/NoAuth/Bugs.html?Dist=Text-Diff-FormattedHTML AnnoCPAN, Annotated CPAN documentation http://annocpan.org/dist/Text-Diff-FormattedHTML CPAN Ratings http://cpanratings.perl.org/d/Text-Diff-FormattedHTML Search CPAN http://search.cpan.org/dist/Text-Diff-FormattedHTML/ LICENSE AND COPYRIGHT Copyright (C) 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.