2005-07-19 dancing round the maypole: [http://maypole.perl.org/?HomePage Maypole] is a program that lets you create a database driven . . .

Maypole is a program that lets you create a database driven website in under 20 lines of code.

I’ll say that again just in case it didn’t sink in the first time.

Maypole is a program that lets you create a database driven website in under 20 lines of code.

I kid you not. Here’s proof all live and running on my dekstop machine right now.

http://home.greywulf.net/srddb_small.jpg

Here’s the code:
srd.cgi

 #!/usr/bin/perl
 use strict;
 use warnings;
 use SrdDB;
 SrdDB->run();

SrdDB.pm

 package SrdDB;
 use Maypole::Application;
 use Class::DBI::Loader::Relationship;
 SrdDB->setup( "dbi:mysql:srd;",'root','' );
 SrdDB->config->application_name('The SRD Database');
 SrdDB->config->{uri_base} = "http://localhost/cgi-bin/srd.cgi/";
 SrdDB->config->template_root("/var/www/htdocs/srddb");
 SrdDB->config->{rows_per_page} = 20;
 SrdDB->config->{display_tables} =
  [ qw[ monster  class feat skill spell equipment ] ];

 package SrdDB::Monster; sub list_columns{ "name","type","hit_dice",
 "challenge_rating","armor_class","full_attack", "saves" };
 sub display_columns{ "full_text"};
 package SrdDB::Class; sub list_columns{ "name","hit_die","skill_points",“proficiencies”,“spell_stat” };
sub display_columns{ "full_text"}; package SrdDB::Feat; sub list_columns{ "name","benefit","stack"}; sub display_columns{ "full_text"}; package SrdDB::Skill; sub list_columns{ "name","description","key_ability"}; sub display_columns{ "full_text"}; package SrdDB::Spell; sub list_columns{ "name","level","range","target", "duration",“short_description”,“saving_throw” };
sub display_columns{ "full_text"}; package SrdDB::Equipment; sub list_columns{ "name","cost","range_increment", "dmg_s","dmg_m","critical" };

The first file is just a wrapper cgi script. It’s the second file that contains the meat of the code. Apologies if this does not format correctly on your browser, btw; I’ve adjusted the line lengths to suit a 1024×786 size screen. If yours is a lower resolution, the code might look odd. Rest assured that it’s just 15 lines long in real life. The last five lines of that are just to control which columns are displayed.

Just for test purposes, I’ve used a copy of the D&D System Reference Document I’ve got in handy MySQL format.

So, that’s the good news; Maypole really, really does work. I’ve got a simple database front-end to a moderate sized database, complete with editing, filtering, search and sorting. It wouldn’t take much more effort to add in relationships, session handling, and advanced layout control (css, of course), all within Maypole’s framework.

Now, the (slightly) bad; Maypole is quite a royal pain in the ass to get up and running in the first place; it has a lot of depencencies that need installation and configuration. At least on this Slackware 10.0 box, that required a lot of trips to CPAN and installation. That said, now it’s done, it’s done for good. A little pain in the start, a lot fo gain in the end. In a production environment, that’s well worth it.

Maypole gets my vote!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *