[dancer-users] Methods Of retrieving request parameters

Warren Young wyml at etr-usa.com
Tue Jul 12 16:38:51 BST 2016


On Jul 12, 2016, at 9:15 AM, Daniel Perrett <dp13 at sanger.ac.uk> wrote:
> 
>> Someone, please show me code that the new keywords makes better.
> 
> Here's one I prepared earlier:
> 
> https://github.com/PerlDancer/Dancer2/pull/1213/commits/0745c2797f477401bc9ef6ef1c387f4330e9e06b 

The first example is essentially the same as the second example in my previous post, which I called horrible coding style.  (Horrible API design style, actually.)  If your app is dependent on the path the data took to get to it, it is brittle.

Consider the design of cat(1).  Would it be better if it behaved differently when its input comes in via stdin vs when it comes from a named file on the command line?  Or, would its design be improved by denying one of the two input paths, forcing you to use stdin or the command line, not the other?

Your second example is simply contrived.  If create_song() expects a song name, you should call it as:

    find_artist(param('id'))->create_song(param('name'));

Using “params” in the second function call is no more justified than using it in the find_artist() call.

You should only be passing the params() hashref around to functions which you know in advance are capable of extracting any parameters they need and ignoring the rest.


More information about the dancer-users mailing list