in reply to Re: Re: Easy dispatch tables.
in thread Easy dispatch tables.
You could also define an AUTOLOAD in TestPkg and forget about it entirely.use CGI qw(:all); my $op = param('operation'); TestPkg->$dispatch('Hello!') if UNIVERSAL::can('TestPkg', $dispatch);
Or maybemy $input = <>; $_->($input) for map /^_/ ? () : *{$TestPkg::{$_}}{CODE} || (), keys %TestPkg::;
Any way you turn it though, I don't see the advantage ofmy $input = <>; my $sub; !/^_/ && *$sub{CODE} && *$sub{CODE}->($input) while ($_, $sub) = each %TestPkg::;
overpackage Foo; use Dispatch; sub bar { ... } sub baz { ... } package main; my $t = Foo->create_dptable; $t->{bar}->($quux);
my $t = { bar => sub { ... }, baz => sub { ... }, }; $t->{bar}->($quux);
If anything, the latter keeps together things that belong together and is quicker to grasp the purpose of.
Fixed minor errors thanks to jryan
Makeshifts last the longest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re^3: Easy dispatch tables.
by jryan (Vicar) on Apr 03, 2003 at 06:57 UTC | |
by Aristotle (Chancellor) on Apr 03, 2003 at 08:25 UTC | |
by jryan (Vicar) on Apr 03, 2003 at 21:59 UTC | |
by Aristotle (Chancellor) on Apr 04, 2003 at 15:25 UTC |