Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Multiple routes that execute the same action

by moritz (Cardinal)
on Mar 28, 2014 at 10:28 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1080061]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-16 23:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found