package BeerDB;
-use base 'Maypole::Application';
+use Maypole::Application;
use Class::DBI::Loader::Relationship;
+BEGIN {
# This is the sample application. Change this to the path to your
# database. (or use mysql or something)
BeerDB->setup("dbi:SQLite:t/beerdb.db");
-#BeerDB->setup("dbi:mysql:beerdb");
+}
# Give it a name.
-BeerDB->config->{application_name} = 'The Beer Database';
+BeerDB->config->application_name('The Beer Database');
# Change this to the root of the web space.
-BeerDB->config->{uri_base} = "http://localhost/beerdb/";
+BeerDB->config->uri_base("http://localhost/beerdb/");
#BeerDB->config->{uri_base} = "http://neo.trinity-house.org.uk/beerdb/";
-BeerDB->config->{rows_per_page} = 10;
+BeerDB->config->rows_per_page(10);
# Handpumps should not show up.
BeerDB->config->{display_tables} = [qw[beer brewery pub style]];
"a brewery produces beers",
"a style defines beers",
"a pub has beers on handpumps");
+
+#package BeerDB::Beer;
+#our %remember;
+#sub MODIFY_CODE_ATTRIBUTES { $remember{ $_[1] } = $_[2]; () }
+#sub FETCH_CODE_ATTRIBUTES { $remember{ $_[1] } }
+
+sub BeerDB::Beer::classdata :Exported {};
+sub BeerDB::Beer::list_columns { return qw/score name price style brewery url/};
+
1;
use Test::More;
use lib 'ex'; # Where BeerDB should live
BEGIN { if (eval { require BeerDB }) {
- plan tests => 3;
+ plan tests => 12;
} else { Test::More->import(skip_all =>"SQLite not working or BeerDB module could not be loaded: $@") }
}
use Maypole::CLI qw(BeerDB);
like(BeerDB->call_url("http://localhost/beerdb/"), qr/frontpage/, "Got the front page");
like(BeerDB->call_url("http://localhost/beerdb/beer/list"), qr/Organic Best/, "Found a beer in the list");
+my (%classdata)=split /\n/, BeerDB->call_url("http://localhost/beerdb/beer/classdata");
+is ($classdata{plural},'beers','classdata.plural');
+is ($classdata{moniker},'beer','classdata.moniker');
+like ($classdata{cgi},qr/^HTML::Element/,'classdata.cgi');
+is ($classdata{table},'beer','classdata.table');
+is ($classdata{name},'BeerDB::Beer','classdata.name');
+is ($classdata{colnames},'Abv','classdata.colnames');
+is($classdata{columns}, 'abv brewery id name notes price score style url',
+ 'classdata.columns');
+is($classdata{list_columns}, 'score name price style brewery url',
+ 'classdata.list_columns');
+is ($classdata{related_accessors},'pubs','classdata.related_accessors');
+
--- /dev/null
+name
+[% classmetadata.name %]
+table
+[% classmetadata.table %]
+columns
+[% classmetadata.columns.join(' ')%]
+list_columns
+[% classmetadata.list_columns.join(' ') %]
+colnames
+[% classmetadata.colnames.abv %]
+related_accessors
+[% classmetadata.related_accessors.join(' ') %]
+moniker
+[% classmetadata.moniker %]
+plural
+[% classmetadata.plural %]
+cgi
+[% classmetadata.cgi.abv%]