in reply to UNIVERSAL::can() doesn't do what I need ...
actually, while the method itself might insist on a class name rather than an object, can() won't know that. so $self->can('do_something'); will correctly determine whether or not you can do it.
your situation is made messier if you need to know which of its parents can do it; but that's OK, because you can call ->can() on a string that is the name of a class. Here's a one-liner to prove it.
perl -e 'package It; sub doit{return pop}; $foo="It"; print($foo->can( +"doit")?"y":"n")'
incidentally, i would recommend re-writing the method so that, if given an object rather than a class name, it gets the class name by ref'ing the object. e.g.,
because there is almost never a reason not to. .sub class_method { my $proto = shift; $class = ref($proto) || $proto; # do stuff ... }
update (about perldoc UNIVERSAL: yes, I saw that too; and i almost let it stop me from trying. But then i tried it anyway.
and it is OK to doubt me, brother; doubt builds faith, and besides, i am only a man, after all
.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: UNIVERSAL::can() doesn't do what I need ...
by dragonchild (Archbishop) on Jun 14, 2001 at 18:29 UTC |