Algorithm-Diff-JSON
view release on metacpan or search on metacpan
CHANGELOG
Makefile.PL
lib/Algorithm/Diff/JSON.pm
t/algorithm-diff-json-additions
t/algorithm-diff-json-all_changes-big
t/algorithm-diff-json-base
t/algorithm-diff-json-base-big
t/algorithm-diff-json-changes
t/algorithm-diff-json-removals
t/algorithm-diff-json.t
MANIFEST.SKIP
MANIFEST
t/pod-coverage.t
t/pod.t
ARTISTIC.txt
GPL2.txt
META.yml Module YAML meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010",
"license" : [
"unknown",
"open_source"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : 2
},
"name" : "Algorithm-Diff-JSON",
"no_index" : {
"directory" : [
"t",
"inc"
]
},
"prereqs" : {
"build" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"runtime" : {
"requires" : {
"Algorithm::Diff" : "0",
"Cpanel::JSON::XS" : "0",
"Sub::Exporter" : "0",
"Test::Differences" : "0",
"Test::More" : "0.88"
}
}
},
"release_status" : "stable",
"resources" : {
"bugtracker" : {
"web" : "https://github.com/DrHyde/perl-modules-Algorithm-Diff-JSON/issues"
},
"repository" : {
"url" : "https://github.com/DrHyde/perl-modules-Algorithm-Diff-JSON"
}
},
"version" : "1.000",
"x_serialization_backend" : "JSON::PP version 4.02"
}
build_requires:
ExtUtils::MakeMaker: '0'
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010'
license: unknown
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: Algorithm-Diff-JSON
no_index:
directory:
- t
- inc
requires:
Algorithm::Diff: '0'
Cpanel::JSON::XS: '0'
Sub::Exporter: '0'
Test::Differences: '0'
Test::More: '0.88'
resources:
bugtracker: https://github.com/DrHyde/perl-modules-Algorithm-Diff-JSON/issues
repository: https://github.com/DrHyde/perl-modules-Algorithm-Diff-JSON
version: '1.000'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
Makefile.PL view on Meta::CPAN
use ExtUtils::MakeMaker;
use Config;
WriteMakefile(
NAME => 'Algorithm::Diff::JSON',
META_MERGE => {
license => 'open_source',
resources => {
repository => 'https://github.com/DrHyde/perl-modules-Algorithm-Diff-JSON',
bugtracker => 'https://github.com/DrHyde/perl-modules-Algorithm-Diff-JSON/issues'
},
},
VERSION_FROM => 'lib/Algorithm/Diff/JSON.pm',
PREREQ_PM => {
'Algorithm::Diff' => 0,
'Cpanel::JSON::XS' => 0,
'Sub::Exporter' => 0,
'Test::Differences' => 0,
'Test::More' => 0.88, # done_testing
},
);
lib/Algorithm/Diff/JSON.pm view on Meta::CPAN
package Algorithm::Diff::JSON;
use strict;
use warnings;
use Algorithm::Diff qw(diff);
use Cpanel::JSON::XS qw(encode_json);
use Sub::Exporter -setup => { exports => [ 'json_diff' ] };
our $VERSION = '1.000';
sub json_diff {
my @changes = ();
foreach my $diff (map { @{$_} } diff(@_)) {
my($action, $this_line, $content) = @{$diff};
lib/Algorithm/Diff/JSON.pm view on Meta::CPAN
}
}
return encode_json([
map { defined($changes[$_]) ? { element => $_, %{$changes[$_]} } : () }
0 .. $#changes
]);
}
=head1 NAME
Algorithm::Diff::JSON - find the differences between two lists and report on them in JSON
=head1 SYNOPSIS
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)
=head1 FUNCTIONS
There is only one function, which is a simple wrapper around L<Algorithm::Diff>'s
C<diff> function:
=head2 json_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:
=over
=item element
The element number, as given to us by C<Algorithm::Diff>
=back
lib/Algorithm/Diff/JSON.pm view on Meta::CPAN
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.
=head1 SOURCE CODE REPOSITORY
L<git://github.com/DrHyde/perl-modules-Algorithm-Diff-JSON.git>
=head1 SEE ALSO
L<Text::Diff>
L<Algorithm::Diff>
=head1 AUTHOR, LICENCE and COPYRIGHT
Copyright 2020 David Cantrell E<lt>F<david@cantrell.org.uk>E<gt>
t/algorithm-diff-json.t view on Meta::CPAN
use strict;
use warnings;
use Algorithm::Diff::JSON 'json_diff' => { -as => 'jsondiff' };
use Cpanel::JSON::XS qw(decode_json);
use Test::Differences;
use Test::More;
eq_or_diff(
decode_json(jsondiff(
file_to_list('t/algorithm-diff-json-base'),
file_to_list('t/algorithm-diff-json-additions'),
)),
[
( run in 0.538 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )