2 use Maypole::Application;
3 use Class::DBI::Loader::Relationship;
5 sub debug { $ENV{BEERDB_DEBUG} || 0 }
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';
11 BeerDB->config->model('BeerDB::Base');
14 my $dbi_driver = DBI_DRIVER;
15 if ($dbi_driver =~ /^SQLite/) {
16 unless -e (DATASOURCE) {
17 die sprintf("SQLite datasource '%s' not found, correct the path or recreate the database by running Makefile.PL", DATASOURCE), "\n";
19 eval "require DBD::SQLite";
21 eval "require DBD::SQLite2" and $dbi_driver = 'SQLite2';
24 BeerDB->setup(join ':', "dbi", $dbi_driver, DATASOURCE);
28 BeerDB->config->application_name('The Beer Database');
30 # Change this to the root of the web site for your maypole application.
31 BeerDB->config->uri_base( $ENV{BEERDB_BASE} || "http://localhost/beerdb/" );
33 # Change this to the htdoc root for your maypole application.
34 my @root= ('t/templates');
35 push @root,$ENV{BEERDB_TEMPLATE_ROOT} if ($ENV{BEERDB_TEMPLATE_ROOT});
36 BeerDB->config->template_root( [@root] );
37 # Specify the rows per page in search results, lists, etc : 10 is a nice round number
38 BeerDB->config->rows_per_page(10);
40 # Let TT templates recursively include themselves
41 BeerDB->config->{view_options} = { RECURSION => 1, };
43 # Handpumps should not show up.
44 BeerDB->config->display_tables([qw[beer brewery pub style drinker pint person]]);
45 # Access handpumps if want
46 BeerDB->config->ok_tables([ @{BeerDB->config->display_tables}, qw[handpump]]);
48 BeerDB::Brewery->untaint_columns( printable => [qw/name notes url/] );
49 BeerDB::Style->untaint_columns( printable => [qw/name notes/] );
50 BeerDB::Beer->untaint_columns(
51 printable => [qw/abv name price notes/],
52 integer => [qw/style brewery score/],
55 BeerDB::Pub->untaint_columns(printable => [qw/name notes url/]);
56 BeerDB::Drinker->untaint_columns( printable => [qw/handle created/] );
57 BeerDB::Pint->untaint_columns( printable => [qw/date_and_time/]);
61 BeerDB->config->{brewery}{required_cols} = [qw/name/];
62 BeerDB->config->{style}{required_cols} = [qw/name/];
63 BeerDB->config->{beer}{required_cols} = [qw/brewery name price/];
64 BeerDB->config->{pub}{required_cols} = [qw/name/];
65 BeerDB->config->{drinker}{required_cols} = [qw/handle person/];
66 BeerDB->config->{pint}{required_cols} = [qw/drinker handpump/];
67 BeerDB->config->{person}{required_cols} = [qw/first_name sur_name dob email/];
70 sub BeerDB::Handpump::display_columns { qw/pub beer/ }
72 BeerDB->config->{loader}->relationship($_) for (
73 "a brewery produces beers",
74 "a style defines beers",
75 "a pub has beers on handpumps",
76 "a handpump defines pints",
77 "a drinker drinks pints",);
79 # For testing classmetadata
80 #sub BeerDB::Beer::classdata :Exported {};
81 sub BeerDB::Beer::list_columns { return qw/score name price style brewery/};
83 sub BeerDB::Handpump::stringify_self {
85 return $self->beer . " @ " . $self->pub;