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

I have a couple of methods that take a coderef, and I'd like to use the "prototype" trick to pass in a block instead of a sub as the first argument. The problem is, it's a method, so the first argument is $self.

Am I just out of luck?

Replies are listed 'Best First'.
Re: Using "prototype" tricks in methods
by bobn (Chaplain) on Jul 30, 2003 at 22:06 UTC

    Prototypes don't work at all for methods, so I'd say yes, you are SOL.

    --Bob Niederman, http://bob-n.com
Re: Using "prototype" tricks in methods
by adrianh (Chancellor) on Jul 30, 2003 at 23:25 UTC

    As everybody has already pointed out you're out of luck I'm afraid. Prototypes don't apply to methods. You'll just have to pass the subroutine explicitly like this:

    $object->method( sub { ... } );

    (Note: you are actually passing a subroutine with the prototype too - it just looks like a block).

Re: Using "prototype" tricks in methods
by diotalevi (Canon) on Jul 30, 2003 at 22:06 UTC

    Wait for perl6.

      lol or if your deadline is before 2005, redesign. =)

      -Waswas
Re: Using "prototype" tricks in methods
by Anonymous Monk on Jul 30, 2003 at 23:12 UTC
    Redesign. Forget prototypes. Shift off of the argument list and then use ref(), for example, to type-check the intended argument.