0

I'm making an application in perl for the first time, and wanted to use a front controller approach where all requests go through one script which delegates what pages to load based on the uri.

what my script looks like:

use LWP::UserAgent;
use Template;

my $base_url = 'project.local/';
my $ua = LWP::UserAgent->new;

if ($ua->get($base_url . 'reports'))
{
        my $reports_tt = Template->new(\%options);
        $reports_tt->process('reports.tt', \%varz, 'reports.html') or die $reports_tt->error;
}

So on my home.html page, there is a link that points to 'project.local/reports'. I want to load the 'reports.html' page when this link is clicked. Using this approach I can keep all my routes in one place.

But this doesn't load the reports.html page, am I using LWP::UserAgent->get() the wrong way? I think I need a way to route all requests to my script in the .htaccess file, but I'm not at all sure how to do that. Could someone kindly assist?

a7omiton
  • 1,597
  • 4
  • 34
  • 61

1 Answers1

2

You are using the wrong tool entirely. LWP::UserAgent is an HTTP client library — it is used to create and send HTTP requests to other web servers. It cannot be used to respond to HTTP requests, or to write a web server.

Explaining fully how to write a web application in Perl is more than I can reasonably do here, but you may want to take a look at existing Perl web development frameworks like Catalyst, Dancer, and Mojolicious.