mod_perl friendly version of the index.

Note that this does not consitute a full mod_perl response handler, it just
ensures that the index.cgi will run properly inside mod_perl using
ModPerl::Registry.
This commit is contained in:
Chris 2013-01-29 15:58:35 +00:00
parent c07ce87a71
commit d08f185276

View File

@ -1,33 +1,47 @@
#!/usr/bin/perl -wT #!/usr/bin/perl -wT
# Note: above -w flag should be removed in production, as it will cause warnings in
# 3rd party modules to appear in the server error log
use strict;
use lib qw(/path/to/webperl);
use lib qw(modules);
use utf8; use utf8;
use v5.12;
use lib qw(/var/www/webperl);
# Work out where the script is, so module and config loading can work.
our $scriptpath;
BEGIN {
$scriptpath = "/path/to/your/webapp";
}
use CGI::Carp qw(fatalsToBrowser set_message); # Catch as many fatals as possible and send them to the user as well as stderr
use lib "$scriptpath/modules";
our $contact = 'contact@email.address'; # global contact address, for error messages
# System modules # System modules
use CGI::Carp qw(fatalsToBrowser set_message); # Catch as many fatals as possible and send them to the user as well as stderr use CGI::Carp qw(fatalsToBrowser set_message); # Catch as many fatals as possible and send them to the user as well as stderr
# Webperl modules # Webperl modules
use AppUser::YourApp; use Webperl::Application;
use Application;
my $contact = 'contact@email.address'; # global contact address, for error messages # Webapp modules
use YourApp::AppUser;
use YourApp::BlockSelector;
use YourApp::System;
delete @ENV{qw(PATH IFS CDPATH ENV BASH_ENV)}; # Clean up ENV
# install more useful error handling # install more useful error handling
BEGIN { sub handle_errors {
$ENV{"PATH"} = ""; # Force no path. my $msg = shift;
print "<h1>Software error</h1>\n";
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Clean up ENV print '<p>Server time: ',scalar(localtime()),'<br/>Error was:</p><pre>',$msg,'</pre>';
sub handle_errors { print '<p>Please report this error to ',$contact,' giving the text of this error and the time and date at which it occured</p>';
my $msg = shift;
print "<h1>Software error</h1>\n";
print '<p>Server time: ',scalar(localtime()),'<br/>Error was:</p><pre>',$msg,'</pre>';
print '<p>Please report this error to ',$contact,' giving the text of this error and the time and date at which it occured</p>';
}
set_message(\&handle_errors);
} }
set_message(\&handle_errors);
my $app = Application -> new(appuser => AppUser::YourApp -> new()) my $app = Webperl::Application -> new(config => "$scriptpath/config/site.cfg",
appuser => YourApp::AppUser -> new(),
system => YourApp::System -> new(),
block_selector => YourApp::BlockSelector -> new())
or die "Unable to create application"; or die "Unable to create application";
$app -> run(); $app -> run();