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.

READER DISCOUNTSave $50 on terminal.training

I've published 38 videos for new developers, designers, UX, UI, product owners and anyone who needs to conquer the command line 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!