develooper Front page | perl.perl5.porters | Postings from August 2001

Re: marking can() coderef as a method

Thread Previous | Thread Next
From:
Michael G Schwern
Date:
August 24, 2001 01:11
Subject:
Re: marking can() coderef as a method
Message ID:
20010824041111.A16636@blackrider
On Fri, Aug 24, 2001 at 03:04:00AM -0400, Mark Mielke wrote:
> It is arguable that the '->can' should therefore fail.

You could argue it, but it's a pretty silly argument.


> Unfortunately, without enforcing ': method', such would be impossible
> with perl, without having existing code break.

Very, very little code uses ': method'.  Not the least of which reason
being it makes things gratuitously incompatible with anything older
than 5.6.0.

If you want a can() that only returns explicitly marked methods, you
can write it very easily.

    use attributes;

    sub can_meth {
        my($proto, $meth_name) = @_;

        if( my $method = $proto->can($meth_name) ) {
            return $method if 
                grep $_ eq 'method', attributes::get($method);
        }
        else {
            return;
        }
    }


> I have a few qualms about perl's "a method is just a function that gets
> invoked with a $this argument."

You might want to take this up on perl6-language (actually, you might
want to read the Perl 6 RFCs first, as I'm sure it's come up over and
over and over and over again).  

It's a little late to change this in perl 5.


-- 

Michael G. Schwern   <schwern@pobox.com>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <perl-qa@perl.org>	     Kwalitee Is Job One
Any sufficiently encapsulated hack is no longer a hack.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About