carthag has asked for the wisdom of the Perl Monks concerning the following question:
I've been using CGI::Application for a while, and enjoy it because it makes coding most projects so much easier when you have a framework ready.
The problem I have is that I often end up with links that point to incredibly ugly urls, such as "http://www.site.com/script?op=do¶m1=this¶m2=and¶m3=this" or the like.
I've found a workaround that's working, and is pretty from the outside. The links now look like "http://www.site.com/script?walkfrom100to3" or "?jump40". This works fine, but is not internally pretty, as it puts a bunch of the code that really belongs in CGIApp into the index file that calls the CGIApp, like so:
use CGIApp; use CGI; ################################ my $q = CGI->new(); if ($q->query_string =~ /^keywords=walkfrom(\d+)to(\d+)$/) { $q->param(-name=>'op',-value=>'move'); $q->param(-name=>'mode',-value=>'walk'); $q->param(-name=>'location',-value=>$1); $q->param(-name=>'destination',-value=>$2); } elsif ($q->query_string =~ /^keywords=(walk|jump|run|fall)(\d+)?$/) { $q->param(-name=>'op',-value=>'move'); $q->param(-name=>'mode',-value=>$1); $q->param(-name=>'amount',-value=>$2||10); } elsif ($q->query_string =~ /^keywords=explode$/) { $q->param(-name=>'op',-value=>'explode'); } my $app = CGIApp->new(QUERY=>$q); $app->run();
Is there a way to make this prettier in the code without breaking all sorts of things?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pretty URLs in CGI::Application
by hardburn (Abbot) on Sep 16, 2003 at 18:42 UTC | |
by carthag (Scribe) on Sep 16, 2003 at 20:36 UTC |