The following (somewhat ugly) code works:

  return $Quizzer::Attempt::{$name}->($self)
    if $Quizzer::Attempt::{$name} && \&{$Quizzer::Attempt::{$name}};

Any way to make it prettier?  I'm especially offended by the \&{}.

In case it isn't self-documenting, this:
1) Has the user's requested action in $name.
2) Checks the package stash to see if
   a) there's a typeglob by that name, and
   b) the function slot of the typeglob is filled
3) If so, invokes the function on the $self object.

(If I wait for Perl6, I think I'll end up with something like

  return %Quizzer::Attempt::{'&'_$name}.($self)
    if %Quizzer::Attempt::{'&'_$name};

Maybe.)

--kag (who is overly fond of dispatch tables)

Reply via email to