Algorithm-Diff-Callback

 view release on metacpan or  search on metacpan

Build.PL  view on Meta::CPAN



my %module_build_args = (
  "build_requires" => {
    "Module::Build" => "0.28"
  },
  "configure_requires" => {
    "ExtUtils::MakeMaker" => 0,
    "Module::Build" => "0.28"
  },
  "dist_abstract" => "Use callbacks on computed differences",
  "dist_author" => [
    "Sawyer X <xsawyerx\@cpan.org>"
  ],
  "dist_name" => "Algorithm-Diff-Callback",
  "dist_version" => "0.111",
  "license" => "perl",
  "module_name" => "Algorithm::Diff::Callback",
  "recursive_test_files" => 1,
  "requires" => {
    "Algorithm::Diff" => 0,

META.json  view on Meta::CPAN

{
   "abstract" : "Use callbacks on computed differences",
   "author" : [
      "Sawyer X <xsawyerx@cpan.org>"
   ],
   "dynamic_config" : 0,
   "generated_by" : "Dist::Zilla version 6.008, CPAN::Meta::Converter version 2.150001",
   "license" : [
      "perl_5"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",

META.yml  view on Meta::CPAN

---
abstract: 'Use callbacks on computed differences'
author:
  - 'Sawyer X <xsawyerx@cpan.org>'
build_requires:
  File::Spec: '0'
  IO::Handle: '0'
  IPC::Open3: '0'
  Module::Build: '0.28'
  Test::More: '0'
  blib: '1.01'
  perl: '5.006'

Makefile.PL  view on Meta::CPAN

# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.008.
use strict;
use warnings;

use 5.006;

use ExtUtils::MakeMaker;

my %WriteMakefileArgs = (
  "ABSTRACT" => "Use callbacks on computed differences",
  "AUTHOR" => "Sawyer X <xsawyerx\@cpan.org>",
  "BUILD_REQUIRES" => {
    "Module::Build" => "0.28"
  },
  "CONFIGURE_REQUIRES" => {
    "ExtUtils::MakeMaker" => 0,
    "Module::Build" => "0.28"
  },
  "DISTNAME" => "Algorithm-Diff-Callback",
  "LICENSE" => "perl",

lib/Algorithm/Diff/Callback.pm  view on Meta::CPAN

package Algorithm::Diff::Callback;
# ABSTRACT: Use callbacks on computed differences
$Algorithm::Diff::Callback::VERSION = '0.111';
use strict;
use warnings;
use parent          'Exporter';

use Carp            'croak';
use List::Util 1.45 'uniq';
use Algorithm::Diff 'diff';

our @EXPORT_OK = qw(diff_hashes diff_arrays);

lib/Algorithm/Diff/Callback.pm  view on Meta::CPAN

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Algorithm::Diff::Callback - Use callbacks on computed differences

=head1 VERSION

version 0.111

=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 },
    );

lib/Algorithm/Diff/Callback.pm  view on Meta::CPAN


=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.

L<Algorithm::Diff::Callback> let's you pick what you're going to diff (Arrays or
Hashes) and set callbacks for the diff process.

=head1 EXPORT

You'll need to declare to explicitly export these functions.

=head2 diff_arrays

=head2 diff_hashes

    use Algorithm::Diff::Callback qw<diff_arrays diff_hashes>;

=head1 SUBROUTINES/METHODS

=head2 diff_arrays(\@old, \@new, %callbacks)

The first two parameters are array 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_arrays(
        \@old, \@new,
        added => sub {
            my $value = shift;
            say "$value was added to the array";

lib/Algorithm/Diff/Callback.pm  view on Meta::CPAN

    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";



( run in 1.031 second using v1.01-cache-2.11-cpan-10033ea8487 )