Text-WordDiff-0.09000755000765000024 013336711241 13321 5ustar00timkstaff000000000000Text-WordDiff-0.09/Build.PL000444000765000024 156113336711241 14755 0ustar00timkstaff000000000000use Module::Build; my $build = Module::Build->new( module_name => 'Text::WordDiff', license => 'perl', create_makefile_pl => 'traditional', configure_requires => { 'Module::Build' => '0.2701' }, recommends => { 'Test::Pod' => '1.41' }, requires => { Algorithm::Diff => '1.19', Term::ANSIColor => '0', HTML::Entities => '0', }, build_requires => { 'Module::Build' => '0.2701', 'Test::More' => '0.17', 'File::Spec' => '0', }, meta_merge => { resources => { homepage => 'https://metacpan.org/release/Text-WordDiff', bugtracker => 'https://github.com/ThePerlShop/text-worddiff/issues', repository => 'https://github.com/ThePerlShop/text-worddiff', } }, ); $build->create_build_script; Text-WordDiff-0.09/Changes000444000765000024 365313336711241 14760 0ustar00timkstaff000000000000Revision history for Perl extension Text::WordDiff. 0.09 2018-08-21T03:21:47 - Fixed a typo, thanks to gregor herrmann of the Debian project. - Update project metadata: The Perl Shop is now project maintainer, distribution homepage is now on MetaCPAN, and the project now includes an appropriate LICENSE file. 0.08 2011-10-19T22:08:34Z - Control and punctuation characters are now treated as standalone chunks rather than as part of the words the preceed them. This makes for much more intuitive-looking diffs. Thanks to Artem Krivopolenov for the pull request. 0.07 2011-06-19T05:04:42 - Removed `.gitignore` file. - Added proper links to the GitHub repository. - Added bug reporting and repository metadata. 0.06 2011-06-18T22:20:53 - Moved repository to GitHub. - Added Text::WordDiff::HTMLTwoLines by Amelia Ireland. 0.05 2009-04-06T18:34:42 - Fixed documentation typo in Search::WordDiff::ANSIColor. Patch from Jeff Lavallee (Ticket #40509). 0.04 2008-05-06T17:24:36 - Fixed a pasto in the "Support" section of the documentation. - Fixed an encoding-related test failure on Perl 5.6.2. Thanks to David Cantrell for the usual QA. 0.03 2008-05-05T03:27:04 - Added the "configure_requires" and "recommends" parameters to Build.PL. - Added a link to the Subversion repository. 0.02 2005-09-16T01:19:16 - Fixed example CSS so that insert is green and delete is red, instead of vice-versa. - Added code to split strings into words based on the Unicode \p{IsWord} character class in Perl 5.6.0 and later. - Expanded on the "What is a Word?" documentation section with some examples and more details based on the discussion at http://www.justatheory.com/computers/programming/perl/split_words.html. 0.01 2005-09-07T19:05:08 - Initial public release. Text-WordDiff-0.09/LICENSE000444000765000024 5332513336711241 14513 0ustar00timkstaff000000000000This program is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself, that is to say, either: a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" which comes with this Kit. Both of these are provided in full below. ---------------------------------------------------------------------- GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! ---------------------------------------------------------------------- The Artistic License 2.0 Copyright (c) 2000-2006, The Perl Foundation. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble This license establishes the terms under which a given free software Package may be copied, modified, distributed, and/or redistributed. The intent is that the Copyright Holder maintains some artistic control over the development of that Package while still keeping the Package available as open source and free software. You are always permitted to make arrangements wholly outside of this license directly with the Copyright Holder of a given Package. If the terms of this license do not permit the full use that you propose to make of the Package, you should contact the Copyright Holder and seek a different licensing arrangement. Definitions "Copyright Holder" means the individual(s) or organization(s) named in the copyright notice for the entire Package. "Contributor" means any party that has contributed code or other material to the Package, in accordance with the Copyright Holder's procedures. "You" and "your" means any person who would like to copy, distribute, or modify the Package. "Package" means the collection of files distributed by the Copyright Holder, and derivatives of that collection and/or of those files. A given Package may consist of either the Standard Version, or a Modified Version. "Distribute" means providing a copy of the Package or making it accessible to anyone else, or in the case of a company or organization, to others outside of your company or organization. "Distributor Fee" means any fee that you charge for Distributing this Package or providing support for this Package to another party. It does not mean licensing fees. "Standard Version" refers to the Package if it has not been modified, or has been modified only in ways explicitly requested by the Copyright Holder. "Modified Version" means the Package, if it has been changed, and such changes were not explicitly requested by the Copyright Holder. "Original License" means this Artistic License as Distributed with the Standard Version of the Package, in its current version or as it may be modified by The Perl Foundation in the future. "Source" form means the source code, documentation source, and configuration files for the Package. "Compiled" form means the compiled bytecode, object code, binary, or any other form resulting from mechanical transformation or translation of the Source form. Permission for Use and Modification Without Distribution (1) You are permitted to use the Standard Version and create and use Modified Versions for any purpose without restriction, provided that you do not Distribute the Modified Version. Permissions for Redistribution of the Standard Version (2) You may Distribute verbatim copies of the Source form of the Standard Version of this Package in any medium without restriction, either gratis or for a Distributor Fee, provided that you duplicate all of the original copyright notices and associated disclaimers. At your discretion, such verbatim copies may or may not include a Compiled form of the Package. (3) You may apply any bug fixes, portability changes, and other modifications made available from the Copyright Holder. The resulting Package will still be considered the Standard Version, and as such will be subject to the Original License. Distribution of Modified Versions of the Package as Source (4) You may Distribute your Modified Version as Source (either gratis or for a Distributor Fee, and with or without a Compiled form of the Modified Version) provided that you clearly document how it differs from the Standard Version, including, but not limited to, documenting any non-standard features, executables, or modules, and provided that you do at least ONE of the following: (a) make the Modified Version available to the Copyright Holder of the Standard Version, under the Original License, so that the Copyright Holder may include your modifications in the Standard Version. (b) ensure that installation of your Modified Version does not prevent the user installing or running the Standard Version. In addition, the Modified Version must bear a name that is different from the name of the Standard Version. (c) allow anyone who receives a copy of the Modified Version to make the Source form of the Modified Version available to others under (i) the Original License or (ii) a license that permits the licensee to freely copy, modify and redistribute the Modified Version using the same licensing terms that apply to the copy that the licensee received, and requires that the Source form of the Modified Version, and of any works derived from it, be made freely available in that license fees are prohibited but Distributor Fees are allowed. Distribution of Compiled Forms of the Standard Version or Modified Versions without the Source (5) You may Distribute Compiled forms of the Standard Version without the Source, provided that you include complete instructions on how to get the Source of the Standard Version. Such instructions must be valid at the time of your distribution. If these instructions, at any time while you are carrying out such distribution, become invalid, you must provide new instructions on demand or cease further distribution. If you provide valid instructions or cease distribution within thirty days after you become aware that the instructions are invalid, then you do not forfeit any of your rights under this license. (6) You may Distribute a Modified Version in Compiled form without the Source, provided that you comply with Section 4 with respect to the Source of the Modified Version. Aggregating or Linking the Package (7) You may aggregate the Package (either the Standard Version or Modified Version) with other packages and Distribute the resulting aggregation provided that you do not charge a licensing fee for the Package. Distributor Fees are permitted, and licensing fees for other components in the aggregation are permitted. The terms of this license apply to the use and Distribution of the Standard or Modified Versions as included in the aggregation. (8) You are permitted to link Modified and Standard Versions with other works, to embed the Package in a larger work of your own, or to build stand-alone binary or bytecode versions of applications that include the Package, and Distribute the result without restriction, provided the result does not expose a direct interface to the Package. Items That are Not Considered Part of a Modified Version (9) Works (including, but not limited to, modules and scripts) that merely extend or make use of the Package, do not, by themselves, cause the Package to be a Modified Version. In addition, such works are not considered parts of the Package itself, and are not subject to the terms of this license. General Provisions (10) Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license. (11) If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license. (12) This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder. (13) This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed. (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------- Text-WordDiff-0.09/MANIFEST000444000765000024 47313336711241 14573 0ustar00timkstaff000000000000Build.PL Changes eg/word_diff.css lib/Text/WordDiff.pm lib/Text/WordDiff/ANSIColor.pm lib/Text/WordDiff/HTML.pm lib/Text/WordDiff/HTMLTwoLines.pm LICENSE MANIFEST This list of files README.md t/ansicolor.t t/base.t t/data/left.txt t/data/right.txt t/html.t t/htmltwolines.t t/pod.t Makefile.PL META.yml META.json Text-WordDiff-0.09/META.json000444000765000024 401713336711241 15101 0ustar00timkstaff000000000000{ "abstract" : "Track changes between documents", "author" : [ "David E. Wheeler ", "Currently maintained by the developers of The Perl Shop ." ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.4224", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Text-WordDiff", "prereqs" : { "build" : { "requires" : { "File::Spec" : "0", "Module::Build" : "0.2701", "Test::More" : "0.17" } }, "configure" : { "requires" : { "Module::Build" : "0.2701" } }, "runtime" : { "recommends" : { "Test::Pod" : "1.41" }, "requires" : { "Algorithm::Diff" : "1.19", "HTML::Entities" : "0", "Term::ANSIColor" : "0" } } }, "provides" : { "Text::WordDiff" : { "file" : "lib/Text/WordDiff.pm", "version" : "0.09" }, "Text::WordDiff::ANSIColor" : { "file" : "lib/Text/WordDiff/ANSIColor.pm", "version" : "0.09" }, "Text::WordDiff::Base" : { "file" : "lib/Text/WordDiff.pm" }, "Text::WordDiff::HTML" : { "file" : "lib/Text/WordDiff/HTML.pm", "version" : "0.09" }, "Text::WordDiff::HTMLTwoLines" : { "file" : "lib/Text/WordDiff/HTMLTwoLines.pm", "version" : "0.09" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/ThePerlShop/text-worddiff/issues" }, "homepage" : "https://metacpan.org/release/Text-WordDiff", "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "url" : "https://github.com/ThePerlShop/text-worddiff" } }, "version" : "0.09", "x_serialization_backend" : "JSON::PP version 2.97001" } Text-WordDiff-0.09/META.yml000444000765000024 251313336711241 14730 0ustar00timkstaff000000000000--- abstract: 'Track changes between documents' author: - 'David E. Wheeler ' - 'Currently maintained by the developers of The Perl Shop .' build_requires: File::Spec: '0' Module::Build: '0.2701' Test::More: '0.17' configure_requires: Module::Build: '0.2701' dynamic_config: 1 generated_by: 'Module::Build version 0.4224, 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-WordDiff provides: Text::WordDiff: file: lib/Text/WordDiff.pm version: '0.09' Text::WordDiff::ANSIColor: file: lib/Text/WordDiff/ANSIColor.pm version: '0.09' Text::WordDiff::Base: file: lib/Text/WordDiff.pm Text::WordDiff::HTML: file: lib/Text/WordDiff/HTML.pm version: '0.09' Text::WordDiff::HTMLTwoLines: file: lib/Text/WordDiff/HTMLTwoLines.pm version: '0.09' recommends: Test::Pod: '1.41' requires: Algorithm::Diff: '1.19' HTML::Entities: '0' Term::ANSIColor: '0' resources: bugtracker: https://github.com/ThePerlShop/text-worddiff/issues homepage: https://metacpan.org/release/Text-WordDiff license: http://dev.perl.org/licenses/ repository: https://github.com/ThePerlShop/text-worddiff version: '0.09' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Text-WordDiff-0.09/Makefile.PL000444000765000024 106713336711241 15434 0ustar00timkstaff000000000000# Note: this file was auto-generated by Module::Build::Compat version 0.4224 use ExtUtils::MakeMaker; WriteMakefile ( 'PREREQ_PM' => { 'Test::More' => '0.17', 'Algorithm::Diff' => '1.19', 'Module::Build' => '0.2701', 'HTML::Entities' => '0', 'Term::ANSIColor' => '0', 'File::Spec' => 0 }, 'PL_FILES' => {}, 'VERSION_FROM' => 'lib/Text/WordDiff.pm', 'NAME' => 'Text::WordDiff', 'EXE_FILES' => [], 'INSTALLDIRS' => 'site' ) ; Text-WordDiff-0.09/README.md000444000765000024 224513336711241 14740 0ustar00timkstaff000000000000Text/WordDiff version 0.09 ========================== This library's module, Text::WordDiff, is a variation on the lovely [Text::Diff](http://search.cpan.org/perldoc?Text::Diff) module. Rather than generating traditional line-oriented diffs, however, it generates word-oriented diffs. This can be useful for tracking changes in narrative documents or documents with very long lines. To diff source code, one is still best off using Text::Diff. But if you want to see how a short story changed from one version to the next, this module will do the job very nicely. INSTALLATION To install this module, type the following: perl Build.PL ./Build ./Build test ./Build install Or, if you don't have Module::Build installed, type the following: perl Makefile.PL make make test make install Dependencies ------------ Text::WordDiff requires the following modules: * Algorithm::Diff '1.19', * Term::ANSIColor '0', * HTML::Entities '0', Copyright and License --------------------- Copyright (c) 2005-2011 David E. Wheeler. Some Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Text-WordDiff-0.09/eg000755000765000024 013336711241 13714 5ustar00timkstaff000000000000Text-WordDiff-0.09/eg/word_diff.css000444000765000024 21713336711241 16506 0ustar00timkstaff000000000000.file .fileheader { color: #888; } .file .hunk ins { color: #060; font-weight: bold; } .file .hunk del { color: #b22; font-weight: bold; } Text-WordDiff-0.09/lib000755000765000024 013336711241 14067 5ustar00timkstaff000000000000Text-WordDiff-0.09/lib/Text000755000765000024 013336711241 15013 5ustar00timkstaff000000000000Text-WordDiff-0.09/lib/Text/WordDiff.pm000444000765000024 4461313336711241 17242 0ustar00timkstaff000000000000package Text::WordDiff; use strict; use vars qw(@ISA $VERSION); use Algorithm::Diff (); use IO::File; use Carp; $VERSION = '0.09'; # _Mastering Regular Expressions_, p. 132. my $BEGIN_WORD = $] >= 5.006 ? qr/(?:(? undef, HTML => undef, HTMLTwoLines => undef, ); sub import { my $caller = caller; no strict 'refs'; *{"$caller\::word_diff"} = \&word_diff; } sub word_diff ($$;$) { my @seqs = ( shift, shift ); my $opts = $_[0] ? { %{ +shift } } : {}; $opts->{FILENAME_PREFIX_A} ||= '---'; $opts->{FILENAME_PREFIX_B} ||= '+++'; my $AorB = 'A'; for my $seq (@seqs) { my $type = ref $seq; while ( $type eq 'CODE' ) { $seq = $seq->( $opts ); $type = ref $seq; } # Get a handle on options. my $filename = \$opts->{"FILENAME_$AorB"}; my $mtime = \$opts->{"MTIME_$AorB"}; if ( $type eq 'ARRAY' ) { # The work has already been done for us. } elsif ( $type eq 'SCALAR' ) { # Parse the words from the string. $seq = [ split $BEGIN_WORD, $$seq ]; } elsif ( !$type ) { # Assume that it's a raw file name. $$filename = $seq unless defined $$filename; $$mtime = (stat $seq)[9] unless defined $$mtime; # Parse the words from the file. my $seq_fh = IO::File->new($seq, '<'); $seq = do { local $/; [ split $BEGIN_WORD, <$seq_fh> ] }; $seq_fh->close; } elsif ( $type eq "GLOB" || UNIVERSAL::isa( $seq, "IO::Handle" ) ) { # Parse the words from the file. $seq = do { local $/; [ split $BEGIN_WORD, <$seq> ] }; } else { # Damn. confess "Can't handle input of type $type"; } $AorB++; } # Set up the output handler. my $output; my $out_handler = delete $opts->{OUTPUT}; my $type = ref $out_handler ; if ( ! defined $out_handler ) { # Default to concatenating a string. $output = ''; $out_handler = sub { $output .= shift }; } elsif ( $type eq 'CODE' ) { # We'll just use the handler. } elsif ( $type eq 'SCALAR' ) { # Append to the scalar reference. my $out_ref = $out_handler; $out_handler = sub { $$out_ref .= shift }; } elsif ( $type eq 'ARRAY' ) { # Push each item onto the array. my $out_ref = $out_handler; $out_handler = sub { push @$out_ref, shift }; } elsif ( $type eq 'GLOB' || UNIVERSAL::isa( $out_handler, 'IO::Handle' )) { # print to the file handle. my $output_handle = $out_handler; $out_handler = sub { print $output_handle shift }; } else { # D'oh! croak "Unrecognized output type: $type"; } # Instantiate the diff object, along with any options. my $diff = Algorithm::Diff->new(@seqs, delete $opts->{DIFF_OPTS}); # Load the style class and instantiate an instance. my $style = delete $opts->{STYLE} || 'ANSIColor'; $style = __PACKAGE__ . "::$style" if exists $styles{$style}; eval "require $style" or die $@ unless $style->can('new'); $style = $style->new($opts) if !ref $style; # Run the diff. my $hunks = 0; $out_handler->($style->file_header()); while ($diff->Next) { $hunks++; $out_handler->( $style->hunk_header() ); # Output unchanged items. if (my @same = $diff->Same) { $out_handler->( $style->same_items(@same) ); } # Output deleted and inserted items. else { if (my @del = $diff->Items(1)) { $out_handler->( $style->delete_items(@del) ); } if (my @ins = $diff->Items(2)) { $out_handler->( $style->insert_items(@ins) ); } } $out_handler->( $style->hunk_footer() ); } $out_handler->( $style->file_footer() ); return defined $output ? $output : $hunks; } package Text::WordDiff::Base; sub new { my ($class, $opts) = @_; return bless { %{$opts} } => $class; } sub file_header { my $self = shift; my $fn1 = $self->filename_a; my $fn2 = $self->filename_b; return '' unless 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; return "$p1 $fn1" . (defined $t1 ? "\t" . localtime $t1 : '') . "\n" . "$p2 $fn2" . (defined $t2 ? "\t" . localtime $t2 : '') . "\n" ; } sub hunk_header { return '' } sub same_items { return '' } sub insert_items { return '' } sub delete_items { return '' } sub hunk_footer { return '' } sub file_footer { return '' } sub filename_a { return shift->{FILENAME_A} } sub filename_b { return shift->{FILENAME_B} } sub mtime_a { return shift->{MTIME_A} } sub mtime_b { return shift->{MTIME_B} } sub filename_prefix_a { return shift->{FILENAME_PREFIX_A} } sub filename_prefix_b { return shift->{FILENAME_PREFIX_B} } 1; __END__ ############################################################################## =head1 Name Text::WordDiff - Track changes between documents =head1 Synopsis use Text::WordDiff; my $diff = word_diff 'file1.txt', 'file2.txt', { STYLE => 'HTML' }; my $diff = word_diff \$string1, \$string2, { STYLE => 'ANSIColor' }; my $diff = word_diff \*FH1, \*FH2; \%options; my $diff = word_diff \&reader1, \&reader2; my $diff = word_diff \@records1, \@records2; # May also mix input types: my $diff = word_diff \@records1, 'file_B.txt'; =head1 Description This module is a variation on the lovely L module. Rather than generating traditional line-oriented diffs, however, it generates word-oriented diffs. This can be useful for tracking changes in narrative documents or documents with very long lines. To diff source code, one is still best off using L. But if you want to see how a short story changed from one version to the next, this module will do the job very nicely. =head2 What is a Word? I'm glad you asked! Well, sort of. It's a really hard question to answer. I consulted a number of sources, but really just did my best to punt on the question by reformulating it as, "How do I split text up into individual words?" The short answer is to split on word boundaries. However, every word has two boundaries, one at the beginning and one at the end. So splitting on C didn't work so well. What I really wanted to do was to split on the I of every word. Fortunately, _Mastering Regular Expressions_ has a recipe for that: C<< /(?>. I've borrowed this regular expression for use in Perls before 5.6.x, but go for the Unicode variant in 5.6.0 and newer: C<< /(?>. Adding some additional controls for punctuation and control characters, this sentence, for example, would be split up into the following tokens: my @words = ( "Adding ", "some ", "additional ", "controls", "\n", "for ", "punctuation ", "and ", "control ", "characters", ", ", "this ", "sentence", ", ", "for ", "example", ", ", "would ", "be", "\n", "split ", "up ", "into ", "the ", "following ", "tokens", ":", ); So it's not just comparing words, but word-like tokens and control/punctuation tokens. This makes sense to me, at least, as the diff is between these tokens, and thus leads to a nice word-and-space-and-punctuation type diff. It's not unlike what a word processor might do (although a lot of them are character-based, but that seemed a bit extreme--feel free to dupe this module into Text::CharDiff!). Now, I acknowledge that there are localization issues with this approach. In particular, it will fail with Chinese, Japanese, and Korean text, as these languages don't put non-word characters between words. Ideally, Test::WordDiff would then split on every character (since a single character often equals a word), but such is not the case when the C flag is set on a string. For example, This simple script: =encoding utf8 use strict; use utf8; use Data::Dumper; my $string = '뼈뼉뼘뼙뼛뼜뼝뽀뽁뽄뽈뽐뽑뽕뾔뾰뿅뿌뿍뿐뿔뿜뿟뿡쀼쁑쁘쁜쁠쁨쁩삐'; my @tokens = split /(? line is commented out, in which case we get: $VAR1 = [ '뼈', '뼉', '뼘', '뼙', '뼛', '뼜', '뼝', '뽀', '뽁', '뽄', '뽈', '뽐', '뽑', '뽕', '뾔', '뾰', '뿅', '뿌', '뿍', '뿐', '뿔', '뿜', '뿟', '뿡', '?', '?쁑', '쁘', '쁜', '쁠', '쁨', '쁩', '삐' ]; Someone whose more familiar with non-space-using languages will have to explain to me how I might be able to duplicate this pattern within the scope of C, seing as it may very well be important to have it on in order to ensure proper character semantics. However, if my word tokenization approach is just too naive, and you decide that you need to take a different approach (maybe use L or similar module), you can still use this module; you'll just have to tokenize your strings into words yourself, and pass them to word_diff() as array references: word_diff \@my_words1, \@my_words2; =head1 Options word_diff() takes two arguments from which to draw input and an optional hash reference of options to control its output. The first two arguments contain the data to be diffed, and each may be in the form of any of the following (that is, they can be in two different formats): =over =item * String A bare scalar will be assumed to be a file name. The file will be opened and split up into words. word_diff() will also C the file to get the last modified time for use in the header, unless the relevant option (C or C) has been specified explicitly. =item * Scalar Reference A scalar reference will be assumed to refer to a string. That string will be split up into words. =item * Array Reference An array reference will be assumed to be a list of words. =item * File Handle A glob or IO::Handle-derived object will be read from and split up into its constituent words. =back The optional hash reference may contain the following options. Additional options may be specified by the formattting class; see the specific class for details. =over =item * STYLE "ANSIColor", "HTML" or an object or class name for a class providing C, C, C, C, C, C and C methods. Defaults to "ANSIColor" for nice display of diffs in an ANSI Color-supporting terminal. If the package indicated by the C