develooper Front page | perl.perl5.porters | Postings from March 2007

Re: [PATCH] Extend functionality of UNIVERSAL::DOES() so it handles additional roles, and works in subroutine form.

Thread Previous | Thread Next
From:
chromatic
Date:
March 11, 2007 10:00
Subject:
Re: [PATCH] Extend functionality of UNIVERSAL::DOES() so it handles additional roles, and works in subroutine form.
Message ID:
200703111000.40199.chromatic@wgz.org
On Sunday 11 March 2007 05:45, demerphq wrote:

> I have fixed this problem by making UNIVERSAL::DOES($item,$role) when
> used in subroutine form work in DWIM fashion. When $item is an
> unblessed reference, then it delegates to UNIVERSAL::isa() via
> subroutine call.

I support the idea of making ->DOES() work on internal "types" (ARRAY, REGEX, 
CODE, etc), but I think this idea is wrong.

1) ->DOES() is a method on purpose, for overridability purposes.

2) Things that are methods should look like methods -- not just for clarity of 
that feature's purpose, but to avoid confusion between other features.  For 
example, UNIVERSAL::isa() and UNIVERSAL::can() are still methods and not 
functions, and the documentation finally expresses that.  Adding yet 
another "is it a method or is it a function" confuses the issue yet again 
(and anyone who wants to maintain a whole pile of bug-free code that people 
using methods as functions carelessly in distributions such as Template 
Toolkit and DBI::Class is more than welcome).

3) Hiding method calls underneath function calls is a well-established 
practice in Perl 5 -- you can see it in such clean and easily maintained code 
as the magic system.  Adding a new feature to the core by the way of a hack 
seems to go against good design principles.

4) ->DOES() works as a class method as well as an instance method.  Delegating 
based on the blessedness of the invocant breaks this if the class has 
overridden DOES().

I believe the right approach to making ->DOES() work on built-in types is 
through autobox.  An alternate approach is to add a does() built-in, like 
ref() but actually useful.

-- c

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