Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #I clearly still don't quite get how to set up hierarchical routes. I've tried this:
- my $route = $r->route('/foo')->to('controller' => 'example');
- my $foo_route = $route->get->to(action => 'foo');
- my $bar_route = $route->post->to(action => 'bar');
- # This one works fine. Creates routes:
- # /foo *
- # +/ GET
- # +/ POST
- #But then, if I try to tack on a subroute:
- $bar_route->get('/baz')->to(action => 'bas');
- #then I tried to get fancy and chain my routes together like this:
- my $route = $r->route('/foo')->to('controller' => 'example')
- ->get->to(action => 'foo');
- ->post->to(action => 'bar');
- # This does not work. It creates these routes:
- # /foo *
- # +/ GET
- # +/ GET
- # +/baz GET
- #
- # And they don't work. GET to /foo is functional, but POST to /foo now fails, and GET to /foo/baz doesn't work.
- #
- # What gives? The initial stab of routing two methods to a single path worked, but doesn't allow me to
- # chain anything on.
- # This version works flawlessly:
- $r->get('/foo')->to('example#foo');
- $r->post('/foo')->to('example#bar');
- $r->get('/foo/baz')->to('example#baz');
- # But it's no good because of the redundant code - '/foo' is repeated in all 3 routes (2 of which have
- # identical paths!), and the controller is repeated across all three of them. I could resolve that by stuffing
- # the hardwired strings into variables, but before I do that I'm trying to see if I can get it going with just the
- # method calls. If it can't be done, then c'est le vie
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement