in reply to Double quoted string as method call

This is a bit ugly, but I'll post it anyway since no one has mentioned can().

Since you expect the method to exist, you can do

  $obj->can('...')->($obj => @args)

It works because can() returns a code reference to the subroutine it found (undef if none), and then you simply provide the object as the first argument.

ihb

Replies are listed 'Best First'.
Re: Re: Double quoted string as method call
by EvilSuggestions (Acolyte) on May 05, 2004 at 19:53 UTC

    I don't think that's ugly at all. In fact, it's my prefered method of dynamically calling methods. Seems to me it's the most official way of doing it (for timtowtdi definitions of "official").

    "There is a thin line between ignorance and arrogance, and only I have managed to erase that line." - Dr. Science

      I find it ugly because

      • you have to specify the object twice for one method call
      • if you're assumption about the existance of the method is wrong you get a very poor error message
      • it uses unnecessary dereferencing

      ihb