Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Multiple routes that execute the same action

by moritz (Cardinal)
on Mar 28, 2014 at 10:28 UTC ( #1080061=note: print w/ replies, xml ) Need Help??


in reply to Multiple routes that execute the same action

Sure. If you want to reuse code, you simply give it a name, and use that name twice.

sub handle_my_request { ... } for my $route ('/myaction1/:param1', '/myaction2/:param2') { get $route, \&handle_my_request; }

Most frameworks also allow you to write the code as methods in a controller class (see for example Mojolicious::Guides::Growing).


Comment on Re: Multiple routes that execute the same action
Download Code
Re^2: Multiple routes that execute the same action
by perl_help26 (Sexton) on Mar 28, 2014 at 13:21 UTC

    the use of the function reference is very neat thanks

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1080061]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (12)
As of 2014-09-23 19:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (239 votes), past polls