Hash::Diff::Dispatch - execute code depending on difference between hashes
Execute code based on the difference between the saved version of a hash and a new one
my $hash_watcher = Hash::Diff::Dispatch->new( {}, # Sets the starting hash # The events will be called using the order returned # by calling 'keys' on these values... 'b' => \&bold, 'i' => \&italic, ); # Will call: bold('on', 5) $hash_watcher->update( { b => 5, a => 'la' } ); # Will call: bold('changed', 6) $hash_watcher->update( { b => 6 } ); # Will call: bold('changed', 0) $hash_watcher->update( { b => 0 } ); # Will call: bold('off') $hash_watcher->update( {} );
Accepts a starting hash-ref, and then a list of keys you want to watch, and the code to execute when they change. It will take a copy of the hash in the hash-ref you specify.
Accepts a hash-ref, which it'll take a copy of, and make it the 'saved' hash to check the next call to update again.
update
If a key's value has changed, it'll execute the code specified when you created the object. If the key exists where it didn't before, it'll pass 'on' as the first argument, and the new value as the second. If it's changed, 'changed' and the new value. If it's been deleted, it'll pass 'off'.
Pete Sergeant - pete@clueball.com
As Perl.
To install Hash::Diff::Dispatch, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Hash::Diff::Dispatch
CPAN shell
perl -MCPAN -e shell install Hash::Diff::Dispatch
For more information on module installation, please visit the detailed CPAN module installation guide.