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?


In reply to Pretty URLs in CGI::Application by carthag

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.