]> git.decadent.org.uk Git - maypole.git/blob - ex/fancy_example/BeerDB.pm
Drinker uses add_to_from_cgi and other stuff. Now it is a nice working
[maypole.git] / ex / 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 BeerDB::Person->untaint_columns( printable => [qw/first_name sur_name dob username password email/]);
48
49
50 # Required Fields
51 BeerDB->config->{brewery}{required_cols} = [qw/name url/];
52 BeerDB->config->{style}{required_cols} = [qw/name/];
53 BeerDB->config->{beer}{required_cols} = [qw/brewery name price/];
54 BeerDB->config->{pub}{required_cols} = [qw/name/];
55 BeerDB->config->{drinker}{required_cols} = [qw/handle person/];
56 BeerDB->config->{pint}{required_cols} = [qw/drinker handpump/]; 
57 BeerDB->config->{person}{required_cols} = [qw/first_name sur_name dob email/];
58
59 # Columns to display 
60 sub BeerDB::Handpump::display_columns { qw/pub beer/ }
61 sub BeerDB::Person::display_columns { qw/first_name last_name dob email/ }
62
63 BeerDB->config->{loader}->relationship($_) for (
64     "a brewery produces beers",
65     "a style defines beers",
66     "a pub has beers on handpumps",
67     "a handpump defines pints",
68     "a drinker drinks pints",);
69
70 # For testing classmetadata
71 #sub BeerDB::Beer::classdata :Exported {};
72 sub BeerDB::Beer::list_columns  { return qw/score name price style brewery/};
73
74 sub BeerDB::Handpump::stringify_self { 
75         my $self = shift; 
76         return $self->beer . " @ " . $self->pub;
77 }
78
79 1;