Algorithm::Diff::JSON - find the differences between two lists and report on them in JSON
This perl code:
use Algorithm::Diff::JSON qw(json_diff); my $json = json_diff( [0, 1, 2, 3, 4, 5, 6], ['zero', 1, 2, 3, 5, 5.5, 6] );
will generate this JSON:
[ { "element": 0, "change": { "remove": 0, "add": "zero" } }, { "element": 4, "remove": 4 }, { "element": 5, "add": 5.5 } ]
(well, an ugly, minimised, equivalent version of that JSON anyway)
There is only one function, which is a simple wrapper around Algorithm::Diff's diff function:
diff
This takes two list-ref arguments. It returns a JSON array describing the changes needed to transform the first into the second.
This function may be exported. If you want to export it with a different name then you can do so:
use Algorithm::Diff::JSON 'json_diff' => { -as => 'something_else };
Each element in the returned array is a hash. Hashes always have:
The element number, as given to us by Algorithm::Diff
Algorithm::Diff
and will also have exactly one of the following keys:
The content to add at this location
The content to remove from this location
A hash of both ...
The content which that replaces at this location
I welcome feedback about my code, including constructive criticism, bug reports, documentation improvements, and feature requests. The best bug reports include files that I can add to the test suite, which fail with the current code in my git repo and will pass once I've fixed the bug
Feature requests are far more likely to get implemented if you submit a patch yourself.
git://github.com/DrHyde/perl-modules-Algorithm-Diff-JSON.git
Text::Diff
Copyright 2020 David Cantrell <david@cantrell.org.uk>
This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively.
This module is also free-as-in-mason software.
To install Algorithm::Diff::JSON, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Algorithm::Diff::JSON
CPAN shell
perl -MCPAN -e shell install Algorithm::Diff::JSON
For more information on module installation, please visit the detailed CPAN module installation guide.