| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package BeerDB; |
|
2
|
1
|
|
|
1
|
|
67199
|
use Maypole::Application; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use Class::DBI::Loader::Relationship; |
|
4
|
|
|
|
|
|
|
|
|
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'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
BEGIN { |
|
13
|
|
|
|
|
|
|
my $dbi_driver = DBI_DRIVER; |
|
14
|
|
|
|
|
|
|
if ($dbi_driver =~ /^SQLite/) { |
|
15
|
|
|
|
|
|
|
die sprintf "SQLite datasource '%s' not found, correct the path or " |
|
16
|
|
|
|
|
|
|
. "recreate the database by running Makefile.PL", DATASOURCE |
|
17
|
|
|
|
|
|
|
unless -e DATASOURCE; |
|
18
|
|
|
|
|
|
|
eval "require DBD::SQLite"; |
|
19
|
|
|
|
|
|
|
if ($@) { |
|
20
|
|
|
|
|
|
|
eval "require DBD::SQLite2" and $dbi_driver = 'SQLite2'; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
BeerDB->setup(join ':', "dbi", $dbi_driver, DATASOURCE); |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Give it a name. |
|
27
|
|
|
|
|
|
|
BeerDB->config->application_name('The Beer Database'); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Change this to the root of the web site for your maypole application. |
|
30
|
|
|
|
|
|
|
BeerDB->config->uri_base( $ENV{BEERDB_BASE} || "http://localhost/beerdb/" ); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Change this to the htdoc root for your maypole application. |
|
33
|
|
|
|
|
|
|
|
|
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); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Handpumps should not show up. |
|
41
|
|
|
|
|
|
|
BeerDB->config->display_tables([qw[beer brewery pub style]]); |
|
42
|
|
|
|
|
|
|
BeerDB::Brewery->untaint_columns( printable => [qw/name notes url/] ); |
|
43
|
|
|
|
|
|
|
BeerDB::Style->untaint_columns( printable => [qw/name notes/] ); |
|
44
|
|
|
|
|
|
|
BeerDB::Beer->untaint_columns( |
|
45
|
|
|
|
|
|
|
printable => [qw/abv name price notes url/], |
|
46
|
|
|
|
|
|
|
integer => [qw/style brewery score/], |
|
47
|
|
|
|
|
|
|
date =>[ qw/tasted/], |
|
48
|
|
|
|
|
|
|
); |
|
49
|
|
|
|
|
|
|
BeerDB::Pub->untaint_columns(printable => [qw/name notes url/]); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Required Fields |
|
52
|
|
|
|
|
|
|
BeerDB->config->{brewery}{required_cols} = [qw/name/]; |
|
53
|
|
|
|
|
|
|
BeerDB->config->{style}{required_cols} = [qw/name/]; |
|
54
|
|
|
|
|
|
|
BeerDB->config->{beer}{required_cols} = [qw/brewery name price/]; |
|
55
|
|
|
|
|
|
|
BeerDB->config->{pub}{required_cols} = [qw/name/]; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
BeerDB->config->{loader}->relationship($_) for ( |
|
58
|
|
|
|
|
|
|
"a brewery produces beers", |
|
59
|
|
|
|
|
|
|
"a style defines beers", |
|
60
|
|
|
|
|
|
|
"a pub has beers on handpumps"); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# For testing classmetadata |
|
63
|
|
|
|
|
|
|
sub BeerDB::Beer::classdata :Exported {}; |
|
64
|
|
|
|
|
|
|
sub BeerDB::Beer::list_columns { return qw/score name price style brewery url/}; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |