Gantry is a Perl-powered Web application framework that will help you jumpstart and simplify your next Web application.
Gantry is a Perl-powered Web application framework that started its life as a proprietary toolkit some 10 years ago. Gantry is now open source, so if you code in Perl and want to both jumpstart and simplify your next Web application, Gantry can give you a boost.
Gantry (http://www.usegantry.org) is a Perl- powered Web application framework. Started as a proprietary toolkit some ten years ago, Gantry has evolved through three major revisions. In mid-2005, Gantry was released as open source software under the same license as Perl itself, and maintenance and enhancement continue to this day. Like many other frameworks, Gantry implements the classic Model-View-Controller (MVC) pattern. However, Gantry allows you to use as much as or as little of the pattern as youâ€™d like. If you code in Perl and want to both jumpstart and simplify your next Web application, Gantry can give you a boost.
Letâ€™s build an application of moderate complexity from scratch using Gantry and its code generation framework, Bigtop. To keep things simple, this example uses Gantryâ€™s built-in Web server. Migration to mod_perl is straightforward, and the Gantry documentation provides examples of deployments.
The first step is to install the Gantry and Bigtop packages from the CPAN. If necessary, install HTML::Prototype, File::Copy::Recursive, and Data::FormValidator first and then install Gantry and Bigtop.
$ sudo cpan
cpan> install HTML::Prototype
cpan> install File::Copy::Recursive
cpan> install Data::FormValidator
cpan> install Gantry
cpan> install Bigtop
When you install Gantry and Bigtop, provide valid pathnames (or accept the defaults) and answer â€œyesâ€ to all of the prompts to install of the components and supplemental files. In addition to code and templates, the install adds two utilities, bigtop and tentmaker to /usr/local/bin.
Welcome to Consultants, Inc.
Suppose you are a high-powered consultant whose billing process is collapsing under the weight of an ever-expanding client list. You need a new invoicing system desperately, and it must be simple to use and easy to maintain.
After some thought, you define four tables for your new invoicing system: the company table maintains the names you do business as; customer lists the people who hire you and often owe you money; invoice enumerates bills from a company to a customer; and task represents a line item on an invoice.
Turning this data model into a working Gantry application is extremely simple. Bigtop generates (and re-generates) SQL and Perl code given a description of a table. To create company and customer, run:
$ bigtop â€“n Billing \
The â€“n Billing argument generates a brand new application named â€œBilling.â€ (â€œBillingâ€ is also the name of the base Controller module.) The remainder of the command-line creates the SQL for the two tables, with three columns each. By default, columns are strings and are required. (Later, youâ€™ll see how to make a column optional and how to change its type.)
As soon as bigtop finishes, you have a fresh Gantry application ready to track your companies and customers. bigtop even emits instructions to help you start your application from the command-line:
I have generated your â€™Billingâ€™ application. To run the application:
sqlite app.db < docs/schema.sqlite
./app.server [ port ]
The app.server runs on port 8080 by default.
Once the app.server starts, it will print a list of the urls it can serve.
Point your browser to one of those and enjoy.
If you prefer to run the app with PostgreSQL or MySQL type one of these:
Follow the instructions by changing to the new Billing directory. If you have sqlite (version 3 or higher) in your path, Bigtop has already created a database for you. Otherwise, youâ€™ll need to build a database before you can use your new application.
Bigtop supports three databases: SQLite, MySQL, and PostgreSQL, but it uses SQLite by default. If you donâ€™t want to use SQLite, build your database with one of the other SQL files found in the docs subdirectory of the build directory. (Gantry has no database engine limitations, except that you must have the proper DBD module for your database installed. However, bigtop can only generate SQL code for the three engines listed.)
Once the database is in place, you may start the application using the command-line Web server. If youâ€™re using SQLite, this reduces to typing:
Or, if youâ€™re using one of the other databases, add command-line flags for the database type, database name, username, and password. For instance you might need something like this to connect to PostgreSQL:
$ ./app.server â€“d Pg â€“n billing â€“u payable â€“p â€™$ecr3tâ€™
Of course, payable must be a valid PostgreSQL user on your system with the password shown. billing should exist, initialized with the SQL found in doc/scheme.postgres.
When you start the application, the server prints a list of URLs it can serve:
The â€¦/company and â€¦/customer URLs lead to basic CRUD (Create, Retrieve, Update, and Delete) management of those tables. The base URL displays a page of links to the other URLs.