Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Using "prototype" tricks in methods

by v_thunder (Scribe)
on Jul 30, 2003 at 22:02 UTC ( #279387=perlquestion: print w/replies, xml ) Need Help??
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,
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. =)

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://279387]
Approved by Paladin
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2018-01-22 00:47 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (230 votes). Check out past polls.