[Catalyst] C:P::FormValidator::Simple and C:P:FillInForm
Matt S Trout
dbix-class at trout.me.uk
Sun Mar 19 16:57:40 CET 2006
Nilson Santos Figueiredo Junior wrote:
> On 3/19/06, Matt S Trout <dbix-class at trout.me.uk> wrote:
>> "Some authors call methods in the UNIVERSAL class on potential invocants as
>> functions, bypassing any possible overriding. This is wrong and you should not
>> do it. Unfortunately, not everyone heeds this warning and their bad code can
>> break your good code."
>
> Hmmm... thanks for the enlightment.
> I actually thought it was some kind of best practice to call it as a
> function. But I guess I'm to blame for not reading UNIVERSAL::can
> manpages.
>
>> "Some people argue that you must call UNIVERSAL::can() as a function because
>> you don't know if your proposed invocant is a valid invocant. That's silly.
>
> That's exactly the argument that made me switch over from
> $obj->can('method') to UNIVERSAL::can($obj, 'method'). I, admittedly,
> forgot about things such as isa() and can() overriding (I also use it
> when calling isa(), which is probably also wrong ).
Very, very wrong. There's a UNIVERSAL::isa to hack round this as well, which
Catalyst uses in some places (one day I may go through and clean these out -
volunteers welcome to help :).
The worst thing about this approach is it completely destroys any chance of
using a proxy/decorator for an object or a Test::MockObject or similar without
loading the hackaround modules - which can be a *complete* pain. Oh and of
course it fails to deal with modules that provide an AUTOLOAD plus a custom
can so not-yet-AUTOLOAD-ed routines work (e.g. Class::Classless)
Calling it as a function has become disturbingly common recently; I suspect
there were a bunch of examples of it somewhere and it proliferated from there.
I'm just a correctness psycho :)
--
Matt S Trout Offering custom development, consultancy and support
Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
More information about the Catalyst
mailing list