I wrote a little tool to help me command line test URLs in my mod_perl dev environment. It lets me pass ful URLs + query strings via the command line, and see, or more importantly, debug the output.

Apache is running with mod_perl and we are using the PerlHandler to forward requests to.

There's really nothing to the script, but I couldn't find a simple example on the Internet when I first needed it.

Book nowModern Universal React with Next.js

Stop worrying about configuration, and complex codebases: Next.js makes SSR with React easy. Book your masterclass today.

use strict;
use Apache::FakeRequest;
use URI;
my $uri = URI->new($ARGV[0]);
$ENV{'QUERY\_STRING'} = $uri->query;
my $r = Apache::FakeRequest->new(
    uri => $uri->as\_string, 
    args => $uri->query, 
    method => 'GET');

You need to import the Perl module that contains the 'handler' function from the command line during execution.

If you call the script 'test_url' you can run it from the command line like this:

perl -MControllers::MyURLHandler test_url "http://mywebsite.com/search?query=code&filter=recent"

Of course if you only have one handler, you can include this in test_url script itself and not need to bother with the '-M' part.

Hope this is of some help to anyone!

Want more?

Posts, web development learnings & insights, exclusive workshop and training discounts and more, direct to your inbox.

I won't send you any spam, and you can unsubscribe at any time. Powered by ConvertKit