source: trunk/npemap.org.uk/scripts/content/update_stats.pl @ 220

Last change on this file since 220 was 220, checked in by Dominic Hargreaves, 14 years ago

Fix the module loading

  • Property svn:executable set to *
File size: 1.2 KB
RevLine 
[178]1#!/usr/bin/perl
2#
3# Copyright (c) 2006 Dominic Hargreaves
4# See accompanying file "LICENCE" for licence details
5
6use strict;
7use warnings;
8
[220]9use FindBin;
10use DBI;
[219]11
[220]12# Find our private perl libraries
13use lib "$FindBin::Bin/../../perllib";
[219]14use NPEMap::Postcodes;
[220]15
[178]16use vars qw($dbname $dbhost $dbuser $dbpass);
17
18sub print_err;
19sub setup_dbh;
20
21# Read in database config
22my $config = 'npemap.conf';
23do $config or die "Can't read $config!\n";
24
25
26# No point in handling errors here since they'll get handled by the request
27# handler
28my $dbh;
29
30
31    # In case the database went away, make sure we have a connection
32    unless (setup_dbh()) {
33        print_internal_err('Error setting up database connection');
34    }
35
[219]36build_home_stats($dbh);
[178]37
38
39# No more requests to serve, so tidy up
40$dbh->disconnect;
41
42# Helper routines
43sub print_err {
44    my $err = shift;
45    print header("text/plain", "400 $err");
46    print "Error: $err\n";
47}
48
49sub print_internal_err {
50    my $err = shift;
51    print header("text/plain", "500 $err");
52    print "Error: $err\n";
53}
54
55sub setup_dbh {
56    # $dbh is global
57    my $data_source = "dbi:Pg:dbname=$dbname";
58    $data_source .= ";host=$dbhost" if $dbhost;
59    return $dbh = DBI->connect_cached($data_source, $dbuser, $dbpass);
60}
Note: See TracBrowser for help on using the repository browser.