Created
May 31, 2013 11:01
-
-
Save hoehrmann/5684271 to your computer and use it in GitHub Desktop.
Perl script implementing "Comma tools" that can be chained. Originally http://lists.w3.org/Archives/Public/public-qa-dev/2004May/0023.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!perl -w | |
use strict; | |
use warnings; | |
use URI::Escape 'uri_escape'; | |
sub tool | |
{ | |
my $req = shift; | |
return unless defined $req; | |
my ($new, $tool, $param) = $req =~ /^(.*),(\w+)(?:=(.+?))?$/; | |
return unless defined $tool; | |
my %tools = map { split/\s+/ } <DATA> ; | |
my $dst = $tools{$tool}; | |
return unless defined $dst; | |
my $host = $ENV{HTTP_HOST} || $ENV{SERVER_NAME}; | |
return unless defined $host; | |
$host =~ s/:\d+$//; | |
$new = uri_escape("http://$host$new", "^A-Za-z0-9\-_.!~*'()"); | |
$param = uri_escape($param, "^A-Za-z0-9\-_.!~*'()"); | |
$dst =~ s:\$uri:$new:; | |
$dst =~ s:\$param:$param: if defined $param; | |
return $dst; | |
} | |
my $tool = tool $ENV{REQUEST_URI} ; | |
if (not defined $tool) | |
{ | |
print "Status: 404\n\n"; | |
} | |
else | |
{ | |
print "Status: 302\n"; | |
print "Location: $tool\n\n"; | |
} | |
__DATA__ | |
links http://www.google.com/search?q=link:$uri | |
text http://cgi.w3.org/cgi-bin/html2txt?url=$uri | |
xslt http://w3.org/2000/06/webdata/xslt?xslfile=$param&xmlfile=$uri | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment