gitpan / algorithm-diff-callback Goto Github PK
View Code? Open in Web Editor NEWRead-only release history for Algorithm-Diff-Callback
Home Page: http://metacpan.org/release/Algorithm-Diff-Callback
License: Other
Read-only release history for Algorithm-Diff-Callback
Home Page: http://metacpan.org/release/Algorithm-Diff-Callback
License: Other
NAME Algorithm::Diff::Callback - Use callbacks on computed differences VERSION version 0.100 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"; }, ); 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 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 (Arrays or Hashes) and set callbacks for the diff process. EXPORT You'll need to declare to explicitly export these functions. diff_arrays diff_hashes use Algorithm::Diff::Callback qw<diff_arrays diff_hashes>; SUBROUTINES/METHODS 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: * added diff_arrays( \@old, \@new, added => sub { my $value = shift; say "$value was added to the array"; } ); * deleted diff_arrays( \@old, \@new, deleted => sub { my $value = shift; say "$value was deleted from the array"; } ); 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: * added diff_hashes( \%old, \%new, added => sub { my ( $key, $value ) = @_; say "$key ($value) was added to the hash"; } ); * deleted diff_hashes( \%old, \%new, deleted => sub { my ( $key, $value ) = @_; say "$key ($value) was deleted from the hash"; } ); * changed diff_hashes( \%old, \%new, changed => sub { my ( $key, $before, $after ) = @_; say "$key in the hash was changed from $before to $after"; } ); 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 AUTHOR Sawyer X <[email protected]> COPYRIGHT AND LICENSE This software is copyright (c) 2012 by Sawyer X. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.