]> git.decadent.org.uk Git - maypole.git/blob - ex/BeerDB.pm
update to BeerDB.pm to use env var for DSN details if provided
[maypole.git] / ex / BeerDB.pm
1 package BeerDB;
2 use Maypole::Application;
3 use Class::DBI::Loader::Relationship;
4
5 sub debug { $ENV{BEERDB_DEBUG} }
6 # This is the sample application.  Change this to the path to your
7 # database. (or use mysql or something)
8 use constant DBI_DRIVER => 'SQLite';
9 use constant DATASOURCE => $ENV{BEERDB_DATASOURCE} || 't/beerdb.db';
10
11 BEGIN {
12     my $dbi_driver = DBI_DRIVER;
13     if ($dbi_driver =~ /^SQLite/) {
14         die sprintf "SQLite datasource '%s' not found, correct the path or "
15             . "recreate the database by running Makefile.PL", DATASOURCE
16             unless -e DATASOURCE;
17         eval "require DBD::SQLite";
18         if ($@) {
19             eval "require DBD::SQLite2" and $dbi_driver = 'SQLite2';
20         }
21     }
22     BeerDB->setup(join ':', "dbi", $dbi_driver, DATASOURCE);
23 }
24
25 # Give it a name.
26 BeerDB->config->application_name('The Beer Database');
27
28 # Change this to the root of the web space.
29 BeerDB->config->uri_base("http://localhost/beerdb/");
30 #BeerDB->config->uri_base("http://neo.trinity-house.org.uk/beerdb/");
31
32 BeerDB->config->rows_per_page(10);
33
34 # Handpumps should not show up.
35 BeerDB->config->display_tables([qw[beer brewery pub style]]);
36 BeerDB::Brewery->untaint_columns( printable => [qw/name notes url/] );
37 BeerDB::Style->untaint_columns( printable => [qw/name notes/] );
38 BeerDB::Beer->untaint_columns(
39     printable => [qw/abv name price notes url/],
40     integer => [qw/style brewery score/],
41     date =>[ qw/date/],
42 );
43 BeerDB->config->{loader}->relationship($_) for (
44     "a brewery produces beers",
45     "a style defines beers",
46     "a pub has beers on handpumps");
47
48 # For testing classmetadata
49 sub BeerDB::Beer::classdata :Exported {};
50 sub BeerDB::Beer::list_columns  { return qw/score name price style brewery url/};
51
52 1;