Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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 rifling through the Monastery: (13)
As of 2014-08-29 15:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (281 votes), past polls