Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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: (9)
As of 2015-07-03 12:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (53 votes), past polls