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.

UK EVENTAttend ffconf.org 2024

The conference for people who are passionate about the web. 8 amazing speakers with real human interaction and content you can't just read in a blog post or watch on a tiktok!

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!