Hash::Dispatch - Find CODE in a hash (hashlike)
version 0.0010
$dispatch = Hash::Dispatch->dispatch( 'xyzzy' => sub { return 'xyzzy'; }, qr/.../ => 'xyzzy', ... ); $result = $dispatch->dispatch( 'xyzzy' ); $result->value->( ... );
Hash::Dispatch is a tool for creating a hash-like lookup for returning a CODE reference
It is hash-like because a query against the dispatcher will only return once a CODE reference a found. If a key (a string or regular expression) maps to a string, then that will cause the lookup to begin again with the new value, recursing until a CODE reference is found or a deadend is reached:
a => CODE0 b => CODE1 c => CODE2 d => a qr/z/ => c query( a ) => CODE0 query( b ) => CODE1 query( d ) => CODE0 query( xyzzy ) => CODE2 query( j ) => undef
Hash::Dispatch will throw an exception if it is cycling:
a => b b => a query( a ) => {{{ Exception! }}}
Returns a new $dispatcher with the given mapping
$dispatcher
Search $dispatcher with <query>
<query>
Returns an object with a ->value method that contains the CODE reference
->value
Returns undef is nothing is found
Robert Krimen <robertkrimen@gmail.com>
This software is copyright (c) 2011 by Robert Krimen.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Hash::Dispatch, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Hash::Dispatch
CPAN shell
perl -MCPAN -e shell install Hash::Dispatch
For more information on module installation, please visit the detailed CPAN module installation guide.