Building Applications With Gantry

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 \

’company(name,phone,email) \


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:

cd Billing

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:

bigtop –pg_help

bigtop –mysql_help

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:

$ ./app.server

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:

Available urls:




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.

Comments on "Building Applications With Gantry"

Great goods from you, man. I’ve understand your stuff previous to and you are just too magnificent. I really like what you’ve acquired here, really like what you are stating and the way in which you say it. You make it enjoyable and you still care for to keep it wise. I cant wait to read far more from you. This is really a great web site.

I just want to say I am just new to weblog and certainly savored this web site. Probably I’m planning to bookmark your blog . You amazingly have amazing stories. Appreciate it for revealing your blog site.

Leave a Reply