man Zoidberg::DispatchTable () - Class to tie dispatch tables

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 (CW$self) as starting point for resolving subroutines. If the object has a method CWparent() 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 CW{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 CW[$value, $tag], where CW$tag is an identifier used for handling selections of the table. The CW$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 CWkeys(%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 CWwipe, CWstack and CWtags.

add
pop
Wipes entries with tag CW$tag from given set of kaeys or from the whole table. Returns the whole stack for an given key, useful to loop trough stacks. CW$tags is a boolean, when true all items are returned as a sub array of CODE ref with tag. Returns the tag for the given key. Returns an array of all tags for given key.

AUTHOR

Jaap Karssenberg || Pardus [Larus] <pardus@cpan.org>

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