(Hi Ken)

Hmmm. The following works for me:

sgr@calvin: cat /tmp/foo.pl
#!/usr/bin/perl -w

if (Foo->can('bar')) {
   print "Yep, can bar\n";
} else {
   print "Nope, can't bar\n";
}

if (Foo->can('foo')) {
   print "Yep, can foo\n";
} else {
   print "nope, can't foo\n";
}



package Foo;

sub bar {
    print "I'm bar\n";
}

sgr@calvin: perl -w /tmp/foo.pl
Yep, can bar
nope, can't foo

I think it's clearer than dealing with the typeglobs.

<Steve>


On Wed, 24 Jul 2002, Kenneth Graves wrote:

> 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)
>

-- 
Steve Reppucci                                       [EMAIL PROTECTED] |
Logical Choice Software                          http://logsoft.com/ |
=-=-=-=-=-=-=-=-=-=-  My God!  What have I done?  -=-=-=-=-=-=-=-=-=-=


Reply via email to