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

Re: marking can() coderef as a method

Thread Previous | Thread Next
Michael G Schwern
August 24, 2001 01:11
Re: marking can() coderef as a method
Message ID:
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 {

> 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   <>
Perl6 Quality Assurance     <>	     Kwalitee Is Job One
Any sufficiently encapsulated hack is no longer a hack.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About