Skip to main content.
home | support | download

Back to List Archive

Re: test_url query string and path

From: Bill Moseley <moseley(at)not-real.hank.org>
Date: Wed Jun 07 2006 - 20:48:41 GMT
On Wed, Jun 07, 2006 at 01:35:46PM -0700, Jes Constantine wrote:
> 
> my current test_url subroutine is:
> 
> test_url => sub { $_[0]->path !~ 
> /(cms|staff|techstaff|groupnotes|search|webstat|usage|print=yes)$/ }

Won't work.


> 
> after reading http://swish-e.org/archive/2004-12/8647.html and 
> http://swish-e.com/archive/2005-08/9883.html
> I learned that my pages made for print (with print=yes in a query 
> string) weren't being ignored because I was looking for print=yes in the 
> path and not the query.

(Use CSS for printing).



> So will putting $_[0]->query =~ /print=yes/ in my test_url subroutine  
> return  0 for something like: 
> http://humaniststudies.org/enews/index.php?id=142&showAll=true&print=yes
> 
> If so, can someone help me with the syntax for adding to the subroutine? 
> (I'm a swish-e & perl beginner)

Here's one hint that might be helpful:

    test_url => sub {
        my $uri = shift;

        warn "Path is [", $uri->path, "]\n";

    }

The $uri variable is a URI object.  So typing "perldoc URI" will explain the
details.

Path is the path, not the query part:

$ perl -MURI -wle '$uri = URI->new("http://swish-e.com/some/path?print=yes"); print $uri->path; '
/some/path


You have a few options:

$ perl -MURI -wle '$uri = URI->new("http://swish-e.com/some/path?print=yes"); print $uri->query'
print=yes

$ perl -MURI -wle '$uri = URI->new("http://swish-e.com/some/path?print=yes&foo=bar"); print $uri->query'
print=yes&foo=bar

$ perl -MURI -wle '$uri = URI->new("http://swish-e.com/some/path?print=yes&foo=bar"); %param = $uri->query_form; print $param{print}'
yes


But using CSS for print is probably the best solution. ;)



-- 
Bill Moseley
moseley@hank.org

Unsubscribe from or help with the swish-e list: 
   http://swish-e.org/Discussion/

Help with Swish-e:
   http://swish-e.org/current/docs
   swish-e@sunsite.berkeley.edu
Received on Wed Jun 7 13:48:41 2006