Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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).

Replies are listed 'Best First'.
Re^2: Multiple routes that execute the same action
by perl_help26 (Beadle) 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 browsing the Monastery: (10)
As of 2016-09-27 16:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (507 votes). Check out past polls.