diff --git a/supportfiles/webapp/index.cgi b/supportfiles/webapp/index.cgi index 66bc0cb..50f6d15 100644 --- a/supportfiles/webapp/index.cgi +++ b/supportfiles/webapp/index.cgi @@ -1,33 +1,47 @@ #!/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 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 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 -use AppUser::YourApp; -use Application; +use Webperl::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 -BEGIN { - $ENV{"PATH"} = ""; # Force no path. - - delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Clean up ENV - sub handle_errors { - my $msg = shift; - print "

Software error

\n"; - print '

Server time: ',scalar(localtime()),'
Error was:

',$msg,'
'; - print '

Please report this error to ',$contact,' giving the text of this error and the time and date at which it occured

'; - } - set_message(\&handle_errors); +sub handle_errors { + my $msg = shift; + print "

Software error

\n"; + print '

Server time: ',scalar(localtime()),'
Error was:

',$msg,'
'; + print '

Please report this error to ',$contact,' giving the text of this error and the time and date at which it occured

'; } +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"; $app -> run();