[dancer-users] Why do warnings cause Dancer to fail?

Robert Stone drzigman at drzigman.com
Mon May 5 23:51:09 BST 2014


Greetings,

I think the feedback shared has been fantastic.  In the same vein, this seemed like a good time to point out a little gotcha I've run into before.

     my $foo = params 'foo' || '';

This will work a lot of the time, but the problem is that if the value of params 'foo' is "falsey" then it will be replaced with ''.  This may or may not be what you want.

In cases when I want to specify a default value for a form field that is completely undefined I use:

     my $foo = params 'foo' // '';

This is especially useful when creating web services where it is actually possible for a developer to leave a field completely undefined.  Moreover, this could also be relevant for standard web usage especially if you are getting ajaxy.

Hope that saves you some time with the debugger :)

Best Regards,
Robert Stone

----- Original Message -----
From: "Warren Young" <warren at etr-usa.com>
To: "Perl Dancer users mailing list" <dancer-users at dancer.pm>
Sent: Monday, May 5, 2014 3:55:19 PM
Subject: Re: [dancer-users] Why do warnings cause Dancer to fail?

On 5/5/2014 11:39, Joel Roth wrote:
>
> And the following construction doesn't prevent it.
>
> my $foo;

It wouldn't.

You'd need to say something more like

     my $foo = params 'foo' || '';

_______________________________________________
dancer-users mailing list
dancer-users at dancer.pm
http://lists.preshweb.co.uk/mailman/listinfo/dancer-users


More information about the dancer-users mailing list