Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Mapping URLs to code - in search of perlish dispatch schemes

by rhesa (Vicar)
on Jul 20, 2006 at 20:12 UTC ( [id://562701]=note: print w/replies, xml ) Need Help??


in reply to Mapping URLs to code - in search of perlish dispatch schemes

CGI::Application::Dispatch is another data point. It uses a Rails-like dispatch table definition, which feels pretty comfortable to me. There's also a CGI::Application::Dispatch::Regexp, but I haven't used that one.

As far as I know, there are no dispatchers based on query parameters. There may be a good reason for that.

My first impression is that I'd rather keep parameter validation close to the handler code for a particular url. And I can't see a clear way to handle POST requests either, which to me implies you'd be doing the same thing in two places.

  • Comment on Re: Mapping URLs to code - in search of perlish dispatch schemes

Replies are listed 'Best First'.
Re^2: Mapping URLs to code - in search of perlish dispatch schemes
by Corion (Patriarch) on Jul 20, 2006 at 20:28 UTC

    Thanks for CGI::Application::Dispatch - I'll add that to my above roundup table. I don't quite understand the finer points of the dispatch interface, but some longer study of the documentation will hopefully tell me ;-)

    My idea would work transparently for GET and POST queries because CGI (as an example) abstracts both into the ->param() function and even mixes and mashes the parameters together if I tell it to.

    To me, the query path and the query parameters are more or less the same, except that the query path has no name, while the query parameters are name-value pairs. The functional programming languages (I'm thinking of Haskell) also have value-based function signatures, and my approach would be similar to that.

      Gotcha. I thought you were just looking at throwing regexes at the request URI, but you're going one further. At the risk of over-stretching the analogy, it looks to me like you're going to do compile-time method dispatching and type checking, instead of at run-time. I can see value in that, although we could debate endlessly whether that is the perlish way ;)

      I'm interested to see what you come up with. I suppose I always felt that the uri-path is similar to a method name, while the query parameters are similar to its input parameters. Although CA::Dispatch's named captures muddles the water there, and that's also quite a useful feature. I'm still mostly using old-fashioned urls like /book/edit?id=1 instead of the more modern /book/edit/1, but I'm slowly catching up :)

Re^2: Mapping URLs to code - in search of perlish dispatch schemes
by geektron (Curate) on Jul 20, 2006 at 20:46 UTC
    As far as I know, there are no dispatchers based on query parameters. There may be a good reason for that.

    Something similar can be accomplished by passing a coderef to mode_param() in CGI::Application. the executed code could then examine query parameters to enhance the dispatch mechanism.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://562701]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-19 01:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found