Rubberband - (Even more!) Extensible framework around Maypole
In Foo.pm:
package Foo; use Rubberband ( search_path => [ "Foo", "Foo::Plugin" ], dsn => "dbi:SQLite:foo.db", translate_sql_from => "MySQL", ); Foo->config->{uri_base} = "http://localhost/"; # Other Maypole configuration parameters
From the command line:
perl -MFoo -e 'Foo->setup_database_tables'
Or when adding a new plugin:
perl -MFoo -e 'Foo::Plugin::Magic->run_data_sql'
In Foo/Plugin/Magic.pm:
package Foo::Plugin::Magic; Foo::Plugin::Magic->table("magic"); Foo::Plugin::Magic->columns(...); sub conjure :Exported { my ($self, $r) = @_; $r->{objects} = [ Foo->call_plugins("collate_magic") ]; } __DATA__ CREATE TABLE magic ( id integer auto_increment NOT NULL PRIMARY KEY, name varchar(255), spell text );
Maypole as a web application framework is easy to extend "vertically" by adding new Exported methods, but not so easy to extend "horizontally" by adding new "concepts" (that is, classes and tables).
Exported
Rubberband, as its name implies, is designed to be stretched in both directions. It uses Module::Pluggable::Ordered to locate the classes which encapsulate the tables, and also to provide a callback functionality to allow extensions to "talk" to each other; it also uses Class::DBI::DATA::Schema to allow extension classes to declare the SQL to set up their tables. Further, it helps to set up your classes by creating a backend Foo::DBI class (given an application called Foo, of course...) which handles the connection information, and from which your plugin modules automatically inherit.
Module::Pluggable::Ordered
Class::DBI::DATA::Schema
Foo::DBI
Foo
The interface to the module is through options passed on the use line. The following options are available:
use
This is required - it is the DBI data source you will be using.
The package to set up. You almost never want to set this to anything other than the default, which is the calling package.
The Maypole front-end class in use; this defaults to Apache::MVC.
Apache::MVC
The Maypole back-end class; this defaults to Maypole::Model::CDBI::Plain.
Maypole::Model::CDBI::Plain
The Class::DBI base class; this defaults to Class::DBI::BaseDSN.
Class::DBI
Class::DBI::BaseDSN
This, and other Module::Pluggable::Ordered options, are passed on to that module.
When your DATA section contains the SQL to create your table, and someone uses the module with a different database from yours, they're going to need the SQL translated into the SQL variety spoken by their database. This can be done if you declare what SQL variety your SQL is in, by passing in a translate_sql_from option.
translate_sql_from
Maypole, Module::Pluggable::Ordered, Class::DBI::DATA::Schema.
Simon Cozens, <simon@cpan.org>
Copyright (C) 2004 by Simon Cozens
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6.0 or, at your option, any later version of Perl 5 you may have available.
To install Rubberband, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Rubberband
CPAN shell
perl -MCPAN -e shell install Rubberband
For more information on module installation, please visit the detailed CPAN module installation guide.