mosh has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks!

What the heck is $self->can($method) ?
How does it work ? the code I'm looking at, do not use UNIVERSAL::can module,
And somehow this command looks for a $method subroutine, HOW COME???

Mosh

Replies are listed 'Best First'.
Re: $self->can($method)
by Joost (Canon) on Jul 07, 2005 at 13:42 UTC
Re: $self->can($method)
by tphyahoo (Vicar) on Jul 07, 2005 at 13:57 UTC
    See also perltoot:

    "UNIVERSAL: The Root of All Objects

    Wouldn't it be convenient if all objects were rooted at some ultimate base class? That way you could give every object common methods without having to go and add it to each and every @ISA. Well, it turns out that you can. You don't see it, but Perl tacitly and irrevocably assumes that there's an extra element at the end of @ISA: the class UNIVERSAL. In version 5.003, there were no predefined methods there, but you could put whatever you felt like into it.

    However, as of version 5.004 (or some subversive releases, like 5.003_08), UNIVERSAL has some methods in it already. These are builtin to your Perl binary, so they don't take any extra time to load. Predefined methods include isa(), can(), and VERSION(). isa() tells you whether an object or class ``is'' another one without having to traverse the hierarchy yourself:......"

Re: $self->can($method)
by ysth (Canon) on Jul 08, 2005 at 06:06 UTC
    To expand on what others have said, the provided UNIVERSAL methods are compiled in; you don't need to use UNIVERSAL; to get them. UNVERSAL.pm is provided just for those that wish to import them.