Book Image

Catalyst

By : Jonathan Rockway
Book Image

Catalyst

By: Jonathan Rockway

Overview of this book

<p>Many web applications are implemented in a way that makes developing them painful and repetitive. Catalyst is an open-source Perl-based Model-View-Controller framework that aims to solve this problem by reorganizing your web application to design and implement it in a natural, maintainable, and testable manner, making web development fun, fast, and rewarding.<br /><br />Everything that your web application needs to do is only written once; you connect to the database in one place, have configuration in one place, etc. Then, you just write actions for each URL that your application needs, without worrying about the database connections or HTML to produce. Catalyst will handle the details so you can worry about writing your application.<br /><br />Catalyst is designed to be reliable. There are hundreds of production applications and thousands of users. The code is well-tested, and new releases almost always maintain compatibility with applications written for older versions. You don't have to worry about Catalyst breaking your application and slowing down your development. It just works.<br /><br />Most importantly, Catalyst has a thriving community. You can ask a question on the IRC channel and get a response at almost any time of the day.<br />&nbsp;<br />This book embodies Catalyst's philosophies of Do It Yourself and Don't Repeat Yourself.</p>
Table of Contents (14 chapters)

Creating a Database Model from Scratch


In some cases, you'll have no use for any of DBIC's functionality. DBIC might not work with your database, or perhaps you're migrating a legacy application that has well-tested database queries that you don't want to rewrite. In this sort of situation, you can write the entire database model manually.

In the next example, we'll use Catalyst::Model::DBI to set up the basic DBI layer and the write methods (like we did above) to access the data in the model. As we have the AddressBook application working, we'll add a DBI model and write some queries against the AddressBook database.

First, we need to create the model. We'll call it AddressDBI:

$ perl script/addressbook_create.pl model AddressDBI DBI DBI:SQLite:database

When you open the generated AddressBook::Model::AddressDBI file, you should see something like this:

package AddressBook::Model::AddressDBI;
use strict;
use base 'Catalyst::Model::DBI';
__PACKAGE__->config(
dsn => 'DBI:SQLite:database...