aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/Page.pm25
-rwxr-xr-xweb/index.cgi51
2 files changed, 43 insertions, 33 deletions
diff --git a/perllib/Page.pm b/perllib/Page.pm
index 33e195fef..ba9c8abde 100644
--- a/perllib/Page.pm
+++ b/perllib/Page.pm
@@ -6,13 +6,36 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: Page.pm,v 1.2 2006-09-19 16:34:24 matthew Exp $
+# $Id: Page.pm,v 1.3 2006-09-19 16:57:44 francis Exp $
#
package Page;
use strict;
use Carp;
+use CGI::Fast qw(-no_xhtml);
+use Error qw(:try);
+
+sub do_fastcgi {
+ my $func = shift;
+
+ try {
+ while (my $q = new CGI::Fast()) {
+ &$func($q);
+ }
+ } catch Error::Simple with {
+ my $E = shift;
+ my $msg = sprintf('%s:%d: %s', $E->file(), $E->line(), $E->text());
+ warn "caught fatal exception: $msg";
+ warn "aborting";
+ encode_entities($msg);
+ print "Status: 500\nContent-Type: text/html; charset=iso-8859-1\n\n",
+ q(<p>Unfortunately, something went wrong. The text of the error
+ was:</p>),
+ qq(<blockquote class="errortext">$msg</blockquote>),
+ q(<p>Please try again later.);
+ };
+}
sub url {
my ($x, $y) = @_;
diff --git a/web/index.cgi b/web/index.cgi
index 33fdef575..06ef62d73 100755
--- a/web/index.cgi
+++ b/web/index.cgi
@@ -6,45 +6,32 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: index.cgi,v 1.4 2006-09-19 16:34:24 matthew Exp $
+# $Id: index.cgi,v 1.5 2006-09-19 16:57:44 francis Exp $
use strict;
-use CGI::Fast qw(-no_xhtml);
-use Error qw(:try);
use Page;
-my $q;
-
-try {
- while ($q = new CGI::Fast()) {
- my $out = '';
- if ($q->param('pc')) {
- $out = display($q);
- } elsif ($q->param('map')) {
- $out = map_clicked($q);
- } else {
- $out = front_page();
- }
-
- print $q->header(-charset=>'utf-8');
- print Page::header($q, '');
- print $out;
- print Page::footer($q);
+# Main code for index.cgi
+sub main {
+ my $q = shift;
+ my $out = '';
+ if ($q->param('pc')) {
+ $out = display($q);
+ } elsif ($q->param('map')) {
+ $out = map_clicked($q);
+ } else {
+ $out = front_page();
}
-} catch Error::Simple with {
- my $E = shift;
- my $msg = sprintf('%s:%d: %s', $E->file(), $E->line(), $E->text());
- warn "caught fatal exception: $msg";
- warn "aborting";
- encode_entities($msg);
- print "Status: 500\nContent-Type: text/html; charset=iso-8859-1\n\n",
- q(<p>Unfortunately, something went wrong. The text of the error
- was:</p>),
- qq(<blockquote class="errortext">$msg</blockquote>),
- q(<p>Please try again later.);
-};
+ print $q->header(-charset=>'utf-8');
+ print Page::header($q, '');
+ print $out;
+ print Page::footer($q);
+}
+Page::do_fastcgi(\&main);
+
+# Display front page
sub front_page {
return <<EOF;
<p>Welcome to Neighbourhood Fix-It.</p>