[Catalyst] C:P::FormValidator::Simple and C:P:FillInForm
Matt S Trout
dbix-class at trout.me.uk
Sun Mar 19 16:28:56 CET 2006
Nilson Santos Figueiredo Junior wrote:
> On 3/19/06, Bernhard Graf <catalyst at augensalat.de> wrote:
>> if ( $c->isa('Catalyst::Plugin::FormValidator') ) {
>> $c->fillform
>> if $c->form->has_missing
>> [...]
>> better
>> if ( my $form = eval { $c->form } ) {
>> $c->fillform
>> if $form->has_missing
>> [...]
>
> eval()ing a method call just to see if it exists (if that's really
> what you meant) is ugly.
> Instead, you should use:
>
> if ($c->can('form')) {
> # code here
> }
>
> If you're not sure whether $c is an object or not, you should use:
>
> if (UNIVERSAL::can($c, 'form')) {
> # code here
> }
>
> If I've missed your point, please, disregard this message.
Never. Ever. Do this. Seriously.
http://search.cpan.org/~chromatic/UNIVERSAL-can-1.11/lib/UNIVERSAL/can.pm
"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."
"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.
Use blessed() from Scalar::Util if you want to check that the potential
invocant is an object"
--
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