NAME
Zoidberg::DispatchTable - Class to tie dispatch tables
SYNOPSIS
use Zoidberg::DispatchTable;
my $table = Zoidberg::DispatchTable->new($self, { cd => '->Commands->cd' });
# The same as $self->parent->{objects}{Commands}->cd('..') if# a module can('parent'), else the same as $self->Commands->cd('..')$$table{cd}->('..');
$$table{ls} = q{ls('-al')}
# The same as $self->ls('-al', '/data')$$table{ls}->('/data');
DESCRIPTION
This module provides a tie interface for converting config strings to CODE references. It takes an object references ($self) as starting point for resolving subroutines. If the object has a method "parent()" the refrence returned by this method is used as the root for resolving subroutines, else the object itself is used as root. The root is expected to contain a hash "{objects}" (possibly of the class Zoidberg::PluginHash) with references to "child" objects.
Strings are converted to CODE references at first use to save time at initialisation.
The following strings are supported:
String Interpretation---------- -----------------sub Sub of the reference object->sub Sub of the root object->sub(qw/f00 b4r/) Sub of the root object with arguments->object->sub Sub of a child object of the root->sub()->.. Sub of the root object
You can store either config strings or CODE references in the table.
The tables is transparent to CODE references, they are used as given. ( An earlier version of this module did currying .. this behaviour is altered. )
If you store an ARRAY ref it is expected to be of the form "[$value, $tag]", where $tag is an identifier used for handling selections of the table. The $value can again be a string or CODE ref.
If you store a HASH ref it will be tied recursively as a DispatchTable.
Keys are kept in the order they are first added, thus "keys(%table)" will always return the same order. This is to keep zoid's plugins in the order they are added. Also for each key a stack is used. Deleting a key only pops it's stack.
This modules doesn't check for security issues, it just runs arbitrary code.
EXPORT
This module can export the methods "wipe", "stack" and "tags".
- add
- pop
- "wipe(\%table, $tag, @keys)"
-
Wipes entries with tag
$tagfrom given set of kaeys or from the whole table.
- "stack(\%table, $key, $tags)"
-
Returns the whole stack for an given key, useful to loop trough stacks.
$tagsis a boolean, when true all items are returned as a sub array of CODE ref with tag.
- "tag(\%table, $key)"
-
Returns the tag for the given key.
- "tags(\%table, $key)"
-
Returns an array of all tags for given key.
AUTHOR
Jaap Karssenberg ⎪⎪ Pardus [Larus] <[email protected]>
Copyright (c) 2003 Jaap G Karssenberg. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
SEE ALSO
Zoidberg