NAME
SynopsisDescription
This module allows you to convert a database schema into the corresponding set of Perl modules, all of which use Class::DBI. One module is generated for each table in the schema. This module uses HTML::Template, and templates compatible with that module, to generate the code. The demonstration program examples/generator.pl skips any table called 'sessions', since CGI::Session uses a table of that name, and such a table does not use the same convention I do to name columns. The dmeonstration program examples/reporter.pl prints out all records in a sample database. DistributionsThis module is available both as a Unix-style distro (*.tgz) and an ActiveState-style distro (*.ppd). The latter is shipped in a *.zip file. See http://savage.net.au/Perl-modules.html for details. See http://savage.net.au/Perl-modules/html/installing-a-module.html for help on unpacking and installing each type of distro. Which Database and What Defaults?This article: http://www.perl.com/pub/a/2003/07/15/nocode.html says: Our base class inherits from Class::DBI::mysql instead of plain Class::DBI, so we can save ourselves the trouble of directly specifying the table columns for each of our database tables--the database-specific base classes will auto-create a set_up_table method to handle all this for you. I did not test this feature, and do not use it, mainly because I have to ship and support systems which run identically under MySQL and Postgres. This latter constraint should explain the subs in parent-module.tmpl. Rather than
generating code based on a DSN containing 'mysql', and also generating code based on a DSN
containing 'Pg', I have included templates which have a Simply edit the templates to suit your environment. Constructor and initializationnew(...) returns a This is the class's contructor. Usage: Class::DBI::Schema2Code -> new(base_name => 'Local::Project', dbh => $dbh).
Method: generate_generic_module($table_name)Takes 1 parameter, the name of a table. This method uses the template 'generic-module.tmpl' (by default) to generate the Perl module for the given table. Method: generate_parent_module($username, $password)Takes 2 parameters, a username and a password. This method uses the template 'parent-module.tmpl' (by default) to generate the Perl module from which all the other generated modules will inherit. The username and password are injected into the output code in order to be passed to
Method: studly_caps($s)Takes 1 parameter, a string. Returns a StudlyCaps version of the given string. Eg: campus_type will be turned into CampusType. Good for converting database table names into Perl module names. Method: tables()Takes no parameters. Returns an array ref containing the names of the tables. Example codeThe directory examples/ contains sample code of various types:
Required ModulesDBI, DBIx::Admin::TableInfo, File::Path, HTML::Template; The tests require Test::More. The program examples/bootstrap.pl requires DBIx::Table2Hash. ResourcesThis article is still excellent, despite being slightly out-of-date: http://www.perl.com/pub/a/2003/07/15/nocode.html See AlsoSince the generated code uses Class::DBI, you really should investigate that module. The documentation for Class::DBI has a long section called 'See Also'. To install Class::DBI you will need to have installed, in this order:
Because of this complexity, you should install Class::DBI via the CPAN or CPANPLUS shell, if at all possible. Author
Home page: http://savage.net.au/index.html CopyrightAustralian copyright © 2004, Ron Savage. All rights reserved. All Programs of mine are 'OSI Certified Open Source Software'; you can redistribute them and/or modify them under the terms of The Artistic License, a copy of which is available at: http://www.opensource.org/licenses/index.html |
| Top of page |