The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Zoidberg::DispatchTable - class to tie dispatch tables

SYNOPSIS

        use Zoidberg::DispatchTable;

        my %table;
        tie %table, q{Zoidberg::DispatchTable},
                $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.

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. If you store a HASH ref it will be tied recursively as a DispatchTable.

Also keys are kept in the order they are first added, and 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.

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, http://zoidberg.sourceforge.net