Chapter 3. Building a Real Application

In this chapter, we're going to build our first real application—an address book. We'll start with a skeleton similar to the application from the last chapter, but then we'll add some real logic to create a CRUD (create, retrieve, update, delete) interface to a database. We'll learn how to define forms that automatically generate and validate themselves and how to design a database schema. We'll also use a View that generates common pages for us, so we won't have to worry about stylesheets or tricky HTML for now.

Environment setup

Before we start writing our new application, we'll need to create a skeleton again. We can create it using the following commands:

$ catalyst.pl AddressBook
$ cd AddressBook/

We'll also need two more CPAN modules for this chapter. These can be installed from CPAN using the following command:

$ cpan Catalyst::Controller::FormBuilder Catalyst::Controller::BindLex

Note

This should really use FormHandler, which is a Moose-based form handling framework that allows one to use nice object-oriented classes. FormHandler is actively maintained while FormBuilder hasn't been updated since 2007. BindLex has also been deprecated for a while, I think even by its author.

The previous command will ensure that the latest version of each module is installed on your system. After installing the modules, we'll add a special Template Toolkit View called TTSite to our application, using the following command:

$ perl script/addressbook_create.pl view HTML TTSite

TTSite will automatically generate some basic HTML for us, so our templates will only need to contain the text and markup that applies specifically to them. The header, footer, messages, and stylesheets will all be handled automatically and will be easy to customize later.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.22.160