]> git.decadent.org.uk Git - maypole.git/blob - examples/fancy_example/BeerDB.pm
cb72574e1b9af564784e01740198497f39d82f2a
[maypole.git] / examples / fancy_example / BeerDB.pm
1 package BeerDB;
2 use Maypole::Application;
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 => '/home/peter/Desktop/maypolebeer/beerdb'; 
10
11 BeerDB->config->model('BeerDB::Base'); 
12
13 BeerDB->setup("dbi:mysql:beerdb",'root', '');
14
15 # Give it a name.
16 BeerDB->config->application_name('The Beer Database');
17
18 # Change this to the root of the web site for your maypole application.
19 BeerDB->config->uri_base( $ENV{BEERDB_BASE} || "http://localhost/beerdb/" );
20
21 # Change this to the htdoc root for your maypole application.
22
23 my @root=  ('/home/peter/Desktop/maypolebeer/templates'); 
24 push @root,$ENV{BEERDB_TEMPLATE_ROOT} if ($ENV{BEERDB_TEMPLATE_ROOT});
25 BeerDB->config->template_root( [@root] ); 
26 # Specify the rows per page in search results, lists, etc : 10 is a nice round number
27 BeerDB->config->rows_per_page(10);
28
29 # Let TT templates recursively include  themselves
30 BeerDB->config->{view_options} = { RECURSION => 1, };
31
32 # Handpumps should not show up.
33 BeerDB->config->display_tables([qw[beer brewery pub style drinker pint person]]);
34 # Access handpumps if want
35 BeerDB->config->ok_tables([ @{BeerDB->config->display_tables}, qw[handpump]]);
36
37 BeerDB::Brewery->untaint_columns( printable => [qw/name notes url/] );
38 BeerDB::Style->untaint_columns( printable => [qw/name notes/] );
39 BeerDB::Beer->untaint_columns(
40     printable => [qw/abv name price notes/],
41     integer => [qw/style brewery score/],
42     date =>[ qw/tasted/],
43 );
44 BeerDB::Pub->untaint_columns(printable => [qw/name notes url/]);
45 BeerDB::Drinker->untaint_columns( printable => [qw/handle created/] );
46 BeerDB::Pint->untaint_columns( printable => [qw/date_and_time/]);
47
48
49 # Required Fields
50 BeerDB->config->{brewery}{required_cols} = [qw/name url/];
51 BeerDB->config->{style}{required_cols} = [qw/name/];
52 BeerDB->config->{beer}{required_cols} = [qw/brewery name price/];
53 BeerDB->config->{pub}{required_cols} = [qw/name/];
54 BeerDB->config->{drinker}{required_cols} = [qw/handle person/];
55 BeerDB->config->{pint}{required_cols} = [qw/drinker handpump/]; 
56 BeerDB->config->{person}{required_cols} = [qw/first_name sur_name dob email/];
57
58 # Columns to display 
59 sub BeerDB::Handpump::display_columns { qw/pub beer/ }
60
61 BeerDB->config->{loader}->relationship($_) for (
62     "a brewery produces beers",
63     "a style defines beers",
64     "a pub has beers on handpumps",
65     "a handpump defines pints",
66     "a drinker drinks pints",);
67
68 # For testing classmetadata
69 #sub BeerDB::Beer::classdata :Exported {};
70 sub BeerDB::Beer::list_columns  { return qw/score name price style brewery/};
71
72 sub BeerDB::Handpump::stringify_self { 
73         my $self = shift; 
74         return $self->beer . " @ " . $self->pub;
75 }
76
77
78 1;