Reputation: 43
I know how to create slugs for my website, so instead of URLs like this:
www.site.com/index.cgi?article=12
I create URLs like this:
www.site.com/article/12
My question is what Perl modules exist, if any, to parse these? I've done this with WSGI in Python but have no idea where to begin in Perl.
Upvotes: 1
Views: 607
Reputation: 639
You're asking about parsing these URLs, but what I think you really mean is, "How do I create a web application that uses this style of URL, and easily dispatches URL calls to function calls with the right arguments?".
If you're using one of the popular web frameworks, this will be one of the core functionalities that the framework provides:
If you're not already using a framework, well, picking one, or even deciding if you need one at all, is a whole other question. Still, you could do worse that working through, say, the Mojolicious tutorial to see if it seems like something that would make your project easier to develop.
Upvotes: 1
Reputation: 126722
What you refer to as a slug is really a clean URL. The slug is the part of the URL that identifies the resource - in this case article/12
or perhaps just 12
.
A clean URL is just a URL, and rewrite rules on the HTTP server are usually used to translate it into a form that includes the necessary resource and query.
URLs can be parsed using the URI
module, but I am not clear what it is that you want to do. In this case you may as well just split the URL string on slashes. There is no general way of producing a clean URL from an unclean one, as the transformation depends entirely on the rewrite rules in place on the server.
Upvotes: 1