DESCRIPTION

This chapter of the tutorial provides supporting information relevant to the Catalyst tutorial.

APPENDIX 1: CUT AND PASTE FOR POD-BASED EXAMPLES

You may notice that Pod indents example code with four spaces. This section provides some quick advice to "un-indent" this text in common editors.

"Un-indenting" with Vi/Vim

When cutting and pasting multi-line text from Pod-based documents, the following vi/vim regexs can be helpful to "un-indent" the inserted text (do NOT type the quotes, they are only included to show spaces in the regex patterns). Note that all 3 of the regexs end in 4 spaces:

":0,$s/^ "

Removes four leading spaces from the entire file (from the first line, 0, to the last line, $).

"%s/^ "

A shortcut for the previous item (% specifies the entire file; so this removes four leading spaces from every line).

":.,$s/^ "

Removes the first four spaces from the line the cursor is on at the time the regex command is executed (".") to the last line of the file.

":.,44s/^ "

Removes four leading space from the current line through line 44 (obviously adjust the 44 to the appropriate value in your example).

"Un-indenting" with Emacs

Although the author has not used Emacs for many years (apologies to the Emacs fans out there), here is a quick hint to get you started. To replace the leading spaces of every line in a file, use:

M-x replace-regexp<RET>
Replace regexp: ^ <RET>
with: <RET>

All of that will occur on the single line at the bottom of your screen. Note that "<RET>" represents the return key/enter. Also, there are four spaces after the "^" on the "Replace regexp:" line and no spaces entered on the last line.

You can limit the replacement operation by selecting text first (depending on your version of Emacs, you can either use the mouse or experiment with commands such as C-SPC to set the mark at the cursor location and C-< and C-> to set the mark at the beginning and end of the file respectively.

Also, Stefan Kangas sent in the following tip about an alternate approach using the command indent-region to redo the indentation for the currently selected region (adhering to indent rules in the current major mode). You can run the command by typing M-x indent-region or pressing the default keybinding C-M-\ in cperl-mode. Additional details can be found here:

APPENDIX 2: USING POSTGRESQL AND MYSQL

The main database used in this tutorial is the very simple yet powerful SQLite. This section provides information that can be used to "convert" the tutorial to use PostgreSQL and MySQL. However, note that part of the beauty of the MVC architecture is that very little database-specific code is spread throughout the system (at least when MVC is "done right"). Consequently, converting from one database to another is relatively painless with most Catalyst applications. In general, you just need to adapt the schema definition .sql file you use to initialize your database and adjust a few configuration parameters.

Also note that the purpose of the data definition statements for this section are not designed to take maximum advantage of the various features in each database for issues such as referential integrity and field types/constraints.

PostgreSQL

Use the following steps to adapt the tutorial to PostgreSQL. Thanks to Caelum (Rafael Kitover) for assistance with the most recent updates, and Louis Moore, Marcello Romani and Tom Lanyon for help with earlier versions.

Chapter 3: More Catalyst Basics

Install the PostgreSQL server and client and DBD::Pg:

If you are following along in Debian 5, you can quickly install these items via this command:

To configure the permissions, you can open /etc/postgresql/8.3/main/pg_hba.conf and change this line (near the bottom):

# "local" is for Unix domain socket connections only
local all all ident sameuser

to:

# "local" is for Unix domain socket connections only
local all all trust

And then restart PostgreSQL:

sudo /etc/init.d/postgresql-8.3 restart

Create the database and a user for the database (note that we are using "<catalyst>" to represent the hidden password of "catalyst"):

$ sudo -u postgres createuser -P catappuser
Enter password for new role: <catalyst>
Enter it again: <catalyst>
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n
CREATE ROLE
$ sudo -u postgres createdb -O catappuser catappdb
CREATE DATABASE

As a valued partner and proud supporter of MetaCPAN, StickerYou is
happy to offer a 10% discount on all Custom Stickers,
Business Labels, Roll Labels,
Vinyl Lettering or Custom Decals. StickerYou.com
is your one-stop shop to make your business stick.
Use code METACPAN10 at checkout to apply your discount.