Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Use callbacks on computed differences
Perl
tree: 3be474d47b

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib/Algorithm/Diff
t
.gitignore
Build.PL
Changes
LICENSE
MANIFEST
MANIFEST.SKIP
META.yml
Makefile.PL
README

README

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

VERSION
    Version 0.01

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,
            sub { print 'Happy to hear about ', shift },
            sub { print 'Sorry to hear about ', shift },
        );

    Or using hashes:

        use Algorithm::Diff::Callback 'diff_hashes';

        diff_hashes(
            \%old_details,
            \%new_details,
            sub { print 'Lost ',   shift },
            sub { print 'Gained ', shift },
            sub {
                my ( $key, $before, $after ) = @_;
                print "$key changed from $before to $after\n";
            },
        );

    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 Algorithm::Diff) give you way too much
    information that you now have to skim over and write long complex loops
    for.

    Algorithm::Diff::Callback let's you pick what you're going to diff
    (Array, Hashes) and set callbacks for the diff process.

EXPORT
  diff_arrays
  diff_hashes
SUBROUTINES/METHODS
  diff_arrays(\@old, \@new, \&removed, \&added)
    The first two parameters are array references to compare.

    The second two parameters are subroutine references which will be called
    and given the value that was either removed or added during the diff
    process.

    The comparison is explicitly the second one against the first one.

    That means that if you give a *removed* subroutine, it really means that
    a value that existed in the first arrayref does not exist in the second
    arrayref.

    If you gave a *added* subroutine, it really means that a value that did
    not exist in the first arrayref now exists in the second one.

  diff_hashes(\%old, \%new, \&removed, \&added, \&change)
    The first two parameters are hash references to compare.

    The second two paramters are the subroutine references which will be
    called and given the key and value that was either removed or added
    during the diff process.

    The third parameter is a subroutine reference of information that
    changed between the first and second hashes. It will be given the key
    that was changed, the value it had before and the value it now has in
    the new reference.

AUTHOR
    Sawyer X, "<xsawyerx at cpan.org>"

BUGS
    Please report bugs on the Github issues page at
    <http://github.com/xsawyerx/algorithm-diff-callback/issues>.

SUPPORT
    This module sports 100% test coverage, but in case you have more
    issues...

    You can find documentation for this module with the perldoc command.

        perldoc Algorithm::Diff::Callback

    You can also look for information at:

    *   Github issues tracker

        <http://github.com/xsawyerx/algorithm-diff-callback/issues>

    *   RT: CPAN's request tracker

        <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Algorithm-Diff-Callback>

    *   AnnoCPAN: Annotated CPAN documentation

        <http://annocpan.org/dist/Algorithm-Diff-Callback>

    *   CPAN Ratings

        <http://cpanratings.perl.org/d/Algorithm-Diff-Callback>

    *   Search CPAN

        <http://search.cpan.org/dist/Algorithm-Diff-Callback/>

DEPENDENCIES
    Algorithm::Diff

    List::MoreUtils

    Carp

    Exporter

LICENSE AND COPYRIGHT
    Copyright 2010 Sawyer X.

    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.

Something went wrong with that request. Please try again.