Perl Monk, Perl Meditation | |
PerlMonks |
Re: UNIVERSAL::can() doesn't do what I need ...by Vynce (Friar) |
on Jun 14, 2001 at 18:18 UTC ( [id://88422]=note: print w/replies, xml ) | Need Help?? |
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.
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. . 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 .
In Section
Seekers of Perl Wisdom
|
|