JSON::Patch (original) (raw)
NAME
JSON::Patch - JSON Patch (rfc6902) for perl structures
VERSION
Version 0.04
SYNOPSIS
use Test::More tests => 2;
use JSON::Patch qw(diff patch);
my $old = {foo => ['bar']};
my $new = {foo => ['bar', 'baz']};
my <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mi>a</mi><mi>t</mi><mi>c</mi><mi>h</mi><mo>=</mo><mi>d</mi><mi>i</mi><mi>f</mi><mi>f</mi><mo stretchy="false">(</mo></mrow><annotation encoding="application/x-tex">patch = diff(</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">p</span><span class="mord mathnormal">a</span><span class="mord mathnormal">t</span><span class="mord mathnormal">c</span><span class="mord mathnormal">h</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">d</span><span class="mord mathnormal">i</span><span class="mord mathnormal" style="margin-right:0.10764em;">ff</span><span class="mopen">(</span></span></span></span>old, $new);
is_deeply(
$patch,
[
{op => 'add', path => '/foo/1', value => 'baz'}
]
);
patch($old, $patch);
is_deeply($old, $new);
EXPORT
Nothing is exported by default.
SUBROUTINES
diff
Calculate patch for two arguments:
Convert Struct::Diff diff to JSON Patch when single arg passed:
require Struct::Diff; <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mi>a</mi><mi>t</mi><mi>c</mi><mi>h</mi><mo>=</mo><mi>d</mi><mi>i</mi><mi>f</mi><mi>f</mi><mo stretchy="false">(</mo><mi>S</mi><mi>t</mi><mi>r</mi><mi>u</mi><mi>c</mi><mi>t</mi><mo>:</mo><mo>:</mo><mi>D</mi><mi>i</mi><mi>f</mi><mi>f</mi><mo>:</mo><mo>:</mo><mi>d</mi><mi>i</mi><mi>f</mi><mi>f</mi><mo stretchy="false">(</mo></mrow><annotation encoding="application/x-tex">patch = diff(Struct::Diff::diff(</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">p</span><span class="mord mathnormal">a</span><span class="mord mathnormal">t</span><span class="mord mathnormal">c</span><span class="mord mathnormal">h</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">d</span><span class="mord mathnormal">i</span><span class="mord mathnormal" style="margin-right:0.10764em;">ff</span><span class="mopen">(</span><span class="mord mathnormal">St</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">u</span><span class="mord mathnormal">c</span><span class="mord mathnormal">t</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">::</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">D</span><span class="mord mathnormal">i</span><span class="mord mathnormal" style="margin-right:0.10764em;">ff</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">::</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">d</span><span class="mord mathnormal">i</span><span class="mord mathnormal" style="margin-right:0.10764em;">ff</span><span class="mopen">(</span></span></span></span>old, $new));
Apply patch.
patch($target, $patch);
Michael Samoglyadov, <mixas at cpan.org>
BUGS
Please report any bugs or feature requests to bug-json-patch at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=JSON-Patch. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc JSON::Patch
You can also look for information at:
- RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=JSON-Patch - AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/JSON-Patch - CPAN Ratings
http://cpanratings.perl.org/d/JSON-Patch - Search CPAN
http://search.cpan.org/dist/JSON-Patch/
SEE ALSO
rfc6902, Struct::Diff, Struct::Diff::MergePatch
LICENSE AND COPYRIGHT
Copyright 2018 Michael Samoglyadov.
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.