Data-Hash-Diff-Smart
view release on metacpan or search on metacpan
### Options
- ignore => \[ '/path', qr{^/debug}, '/foo/\*/bar' \]
Ignore specific paths. Supports exact paths, regexes, and wildcard
segments.
- compare => { '/price' => sub { abs($\_\[0\] - $\_\[1\]) < 0.01 } }
Custom comparator callbacks for specific paths.
- array\_mode => 'index' | 'lcs' | 'unordered'
Choose how arrays are diffed:
- index - compare by index (default)
- lcs - minimal diff using Longest Common Subsequence
- unordered - treat arrays as multisets (order ignored)
- array\_key => 'id'
lib/Data/Hash/Diff/Smart.pm view on Meta::CPAN
=over 4
=item * ignore => [ '/path', qr{^/debug}, '/foo/*/bar' ]
Ignore specific paths. Supports exact paths, regexes, and wildcard
segments.
=item * compare => { '/price' => sub { abs($_[0] - $_[1]) < 0.01 } }
Custom comparator callbacks for specific paths.
=item * array_mode => 'index' | 'lcs' | 'unordered'
Choose how arrays are diffed:
=over 4
=item * index - compare by index (default)
=item * lcs - minimal diff using Longest Common Subsequence
t/edge_cases.t view on Meta::CPAN
subtest 'ignore undef element' => sub {
# Must not die if ignore list contains undef somehow â or just confirm
# that a valid list with one rule works when other value is changed
my $r = diff({a => 1, b => 2}, {a => 9, b => 2}, ignore => ['/a']);
is_deeply($r, [], 'valid single ignore rule works correctly');
};
};
# ===========================================================================
# 13. Adversarial compare callbacks
# ===========================================================================
subtest 'Adversarial compare callbacks' => sub {
subtest 'comparator that always returns true: no changes ever' => sub {
my $r = diff(
{a => 1, b => 'hello'},
{a => 2, b => 'world'},
compare => {
'/a' => sub { 1 },
'/b' => sub { 1 },
},
);
);
is_deeply($r, [], 'both ignored paths suppressed');
};
};
# ===========================================================================
# diff() â option: compare
#
# POD: "compare => { '/price' => sub { abs($_[0] - $_[1]) < 0.01 } }"
# POD: "Custom comparator callbacks for specific paths"
# ===========================================================================
subtest 'diff() - compare option' => sub {
subtest 'custom comparator: within tolerance, no change' => sub {
my $r = diff(
{price => 1.001},
{price => 1.002},
compare => { '/price' => sub { abs($_[0] - $_[1]) < 0.01 } },
);
( run in 0.783 second using v1.01-cache-2.11-cpan-140bd7fdf52 )