Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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?

Comment on Using "prototype" tricks in methods
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 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.
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).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://279387]
Approved by Paladin
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2014-09-18 03:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (105 votes), past polls