use strict; use warnings; I->can(print"Just Another Perl Hacker")


Replies are listed 'Best First'.
Re: I can
by jdalbec (Deacon) on Jul 01, 2006 at 21:31 UTC
    The funny thing is that even though I->can() doesn't return an error, I->can("can") returns undef. So I can can(), but I->cannot ("can").
    perldoc UNIVERSAL says:
    Perl magically makes these functions [isa, can, and VERSION] act as methods on all objects.
    so I guess that's just Perl magic at work.

    Update: in view of ikegami's reply, maybe this is a documentation bug as well. Perhaps s/these functions/all functions in package UNIVERSAL/?

      Not quite.

      There's nothing special about those functions. The magic is Perl acting as if UNIVERSAL was in @ISA when doing a method call. Apparently, can doesn't. Bug!
      >perl -wle "{ package UNIVERSAL; sub test { '!' } } print I->can('test +')?1:0;" 0 >perl -wle "{ package UNIVERSAL; sub test { '!' } } print I->test;" !

      The interesting part is

      that neither the argument nor the return value of can matters in that snippet.