Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Dispatchers for dummies

by sri (Vicar)
on Oct 14, 2008 at 16:10 UTC ( [id://717029]=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    /foo/bar/index      -> Foo::index()
    /test123.html       -> Bar::default()
    /cookies/list/fresh -> Cookies::list()
    
  2. or download this
    # /foo/bar/index
    package Foo::Bar;
    ...
    # /cookies/list/fresh
    package Cookies;
    sub list : Relative Args(1) { ... }
    
  3. or download this
    @Servlet(urlMappings={"/foo", "/bar"})
    public class ControllerWithAnnotations {
        @GET
        public void handleGet(HttpServletRequest req, HttpServletResponse 
    +res) { ... }
    }
    
  4. or download this
    # /foo/bar/index
    on 'foo/bar/index' => do { ... }
    ...
    
    # /cookies/list/fresh
    on '/cookies/list/*' => do { ... }
    
  5. or download this
    __PACKAGE__->action('/foo/bar/index' => sub { ... });
    
  6. or download this
    # /foo/bar/index
    map.connect 'foo/bar/index', :controller => "foo", :action => "index"
    ...
    # /cookies/list/fresh
    map.connect ':controller/:action/:quality', :controller => "cookies", 
    +:action => "list",
      :quality => "fresh", :requirements => { :quality => /\w+/ }
    
  7. or download this
    <%= link_to "Fresh Cookies", :controller => "cookies", :action => "lis
    +t", :quality => "fresh" %>
    
  8. or download this
    # /foo/bar/index
    r.match("/foo/bar/index").to(:controller => "foo", :action => "index")
    ...
    
    # /cookies/list/fresh
    r.match(%r[^/cookies/list/(\w+)$]).to(:controller => "cookies", :actio
    +n => "list", :quality => 'path[1]')
    
  9. or download this
    urlpatterns = patterns('',
        (r'^foo/bar/index$', 'foo.views.index'),
        (r'^test123\.html$', 'foo.views.test'),
        (r'^cookies/list/(\w+)$', 'cookies.views.list'),
    )
    
  10. or download this
    # /foo/bar/index
    $r->route('/foo/bar/index')->to(controller => 'foo', action => 'index'
    +);
    ...
      ->to(controller => 'cookies', action => 'list', quality => 'fresh');
    
    $c->url_for(controller => 'cookies', action => 'list', quality => 'fre
    +sh');
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://717029]
Approved by Corion
Front-paged by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (8)
As of 2024-03-29 15:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found