Algorithm-Diff-Callback
view release on metacpan or search on metacpan
lib/Algorithm/Diff/Callback.pm view on Meta::CPAN
=head1 SYNOPSIS
Use callbacks in your diff process to get better control over what will happen.
use Algorithm::Diff::Callback 'diff_arrays';
diff_arrays(
\@old_family_members,
\@new_family_members,
added => sub { say 'Happy to hear about ', shift },
deleted => sub { say 'Sorry to hear about ', shift },
);
Or using hashes:
use Algorithm::Diff::Callback 'diff_hashes';
diff_hashes(
\%old_details,
\%new_details,
added => sub { say 'Gained ', shift },
deleted => sub { say 'Lost ', shift },
changed => sub {
my ( $key, $before, $after ) = @_;
say "$key changed from $before to $after";
},
);
=head1 DESCRIPTION
One of the difficulties when using diff modules is that they assume they know
what you want the information for. Some give you formatted output, some give you
just the values that changes (but neglect to mention how each changed) and some
(such as L<Algorithm::Diff>) give you way too much information that you now have
to skim over and write long complex loops for.
lib/Algorithm/Diff/Callback.pm view on Meta::CPAN
corresponding callback. You can provide multiple callbacks. Supported keys are:
=over 4
=item * added
diff_arrays(
\@old, \@new,
added => sub {
my $value = shift;
say "$value was added to the array";
}
);
=item * deleted
diff_arrays(
\@old, \@new,
deleted => sub {
my $value = shift;
say "$value was deleted from the array";
}
);
=back
=head2 diff_hashes(\%old, \%new, %callbacks)
The first two parameters are hash references to compare.
The rest of the parameters are keys for the type of callback you want and the
corresponding callback. You can provide multiple callbacks. Supported keys are:
=over 4
=item * added
diff_hashes(
\%old, \%new,
added => sub {
my ( $key, $value ) = @_;
say "$key ($value) was added to the hash";
}
);
=item * deleted
diff_hashes(
\%old, \%new,
deleted => sub {
my ( $key, $value ) = @_;
say "$key ($value) was deleted from the hash";
}
);
=item * changed
diff_hashes(
\%old, \%new,
changed => sub {
my ( $key, $before, $after ) = @_;
say "$key in the hash was changed from $before to $after";
}
);
=back
=head1 BUGS
Please report bugs on the Github issues page at
L<http://github.com/xsawyerx/algorithm-diff-callback/issues>.
( run in 0.361 second using v1.01-cache-2.11-cpan-483215c6ad5 )