3 Catalyst::Manual::Tutorial::Intro - Catalyst Tutorial - Part 1: Introduction
9 This is B<Part 1 of 9> for the Catalyst tutorial.
11 L<Tutorial Overview|Catalyst::Manual::Tutorial>
21 L<Catalyst Basics|Catalyst::Manual::Tutorial::CatalystBasics>
25 L<Basic CRUD|Catalyst::Manual::Tutorial_BasicCRUD>
29 L<Authentication|Catalyst::Manual::Tutorial::Authentication>
33 L<Authorization|Catalyst::Manual::Tutorial::Authorization>
37 L<Debugging|Catalyst::Manual::Tutorial::Debugging>
41 L<Testing|Catalyst::Manual::Tutorial::Testing>
45 L<AdvancedCRUD|Catalyst::Manual::Tutorial::AdvancedCRUD>
49 L<Appendicies|Catalyst::Manual::Tutorial::Appendicies>
57 This tutorial provides a nine-part introduction to the Catalyst web
58 framework. It seeks to provide a rapid overview of many of its most
59 commonly used features. The focus is on the real-world best practices
60 required in the construction of nearly all Catalyst applications.
62 Although the primary target of the tutorial is users new to the Catalyst
63 framework, experienced users may wish to review specific sections (for
64 example, how to use DBIC for their model classes or how to add
65 authentication and authorization to an existing application).
67 Subjects covered include:
73 A simple application that lists and adds books.
77 The use of C<DBIx::Class> (DBIC) for the model.
81 How to write CRUD (Create, Read, Update and Delete) operations in Catalyst.
85 Authentication ("auth").
89 Role-based authorization ("authz").
93 Attempts to provide an example showing current Catalyst 5.70
94 practices. For example, the use of C<Catalyst::Plugin::DefaultEnd>,
95 DBIC, C<Catalyst::Plugin::ConfigLoader> with myapp.yml, the use of
96 C<lib/MyApp/Controller/Root.pm> vs. C<lib/MyApp.pm>, etc.
100 The use of Template Toolkit (TT) and the C<Catalyst::Helper::View::TTSite> view helper.
104 Useful techniques for troubleshooting and debugging Catalyst applications.
108 The use of SQLite as a database (with code also provided for MySQL and PostgreSQL).
112 How to use HTML::Widget for automated form processing and validation.
116 This tutorial intentionally seeks to make the learning process its main
117 priority. For example, the level of comments in the code found here
118 would like be considered excessive in a "normal project". Because of
119 their contextual value, this tutorial will generally favor inline
120 comments over a separate discussion in the text. It also deliberately
121 tries to demonstrate multiple approaches to various features (in
122 general, you should try to be as consistent as possible with your own
125 Furthermore, this tutorial tries to minimize the number of controllers,
126 models, TT templates, and database tables. Although this does result in
127 things being a bit contrived at times, the concepts should be applicable
128 to more complex environments. More complete and complicated example
129 applications can be found in the C<examples> area of the Catalyst
130 Subversion repository at
131 L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/>.
133 B<Note:> There are a variety of other introductory materials available
134 through the Catalyst web site and at
135 L<http://dev.catalyst.perl.org/wiki/UserIntroductions> and
136 L<http://dev.catalyst.perl.org/>.
140 =head1 VERSIONS AND CONVENTIONS USED IN THIS TUTORIAL
142 This tutorial was built using the following resources. Please note that
143 you will need to make adjustments for different environments and
150 OS = CentOS 4 Linux (RHEL 4)
164 You shouldn't be overly concerned about plugin version numbers, but
165 there could be cases where the tutorial is impacted by what version
166 plugins you use. The plugins used in this tutorial are:
172 Catalyst::Plugin::Authentication -- 0.07
176 Authentication::Credential::Password -- 0.07
180 Catalyst::Plugin::Authentication::Store::DBIC -- 0.06
184 Catalyst::Plugin::Authorization::ACL -- 0.06
188 Catalyst::Plugin::Authorization::Roles -- 0.04
192 Catalyst::Plugin::ConfigLoader -- 0.07
196 Catalyst::Plugin::DefaultEnd -- 0.06
200 Catalyst::Plugin::Dumper -- 0.000002
204 Catalyst::Plugin::HTML::Widget -- 1.1
208 Catalyst::Plugin::Session -- 0.05
212 Catalyst::Plugin::Session::FastMmap -- 0.12
216 Catalyst::Plugin::Session::State::Cookie -- 0.02
220 Catalyst::Plugin::Session::Store::FastMmap -- 0.0
224 Catalyst::Plugin::StackTrace -- 0.0
228 Catalyst::Plugin::Static::Simple -- 0.14
234 Since the web browser is being used on the same box where Perl and the
235 Catalyst development server is running, the URL of
236 C<http://localhost:3000> will be used (the Catalyst development server
237 defaults to port 3000). If you are running Perl on a different box than
238 where your web browser is located (or using a different port number via
239 the C<-p> I<port_number> option to the development server), then you
240 will need to update the URL you use accordingly.
244 Depending on the web browser you are using, you might need to hit
245 C<Shift+Reload> to pull a fresh page when testing your application at
246 various points. Also, the C<-k> keepalive option to the development
247 server can be necessary with some browsers (especially Internet
254 =head1 CATALYST INSTALLATION
256 Unfortunately, one of the most daunting tasks faced by newcomers to
257 Catalyst is getting it installed. Although a compelling strength of
258 Catalyst is that it can easily make full use of CPAN, a vast repository
259 of Perl modules, this can result in initial installations that are both
260 time consuming and frustrating. However, there are a growing number of
261 methods that can dramatically ease this undertaking. Of these, the
262 following are likely to be applicable to the largest number of potential
269 Matt Trout's C<cat-install>
271 Available at L<http://www.shadowcatsystems.co.uk/static/cat-install>,
272 C<cat-install> can be a quick and painless way to get Catalyst up and
273 running. Just download the script from the link above and type C<perl
278 Chris Laco's CatInABox
280 Download the tarball from
281 L<http://handelframework.com/downloads/CatInABox.tar.gz> and unpack it
282 on your machine. Depending on your OS platform, either run C<start.bat>
287 Pre-Built VMWare Images
289 Under the VMWare community program, work is ongoing to develop a number
290 of VMWare images where an entire Catalyst development environment has
291 already been installed, complete with database engines and a full
292 complement of Catalyst plugins.
296 B<IMPORTANT:> For additional information and recommendations on Catalyst
297 installation, please refer to
298 L<Catalyst::Manual::Installation|Catalyst::Manual::Installation>.
300 B<IMPORTANT:> Step-by-step instructions to replicate the environment on
301 which this tutorial was developed can be found at
302 L<Catalyst::Manual::Installation::CentOSTuorial|Catalyst::Manual::Installation::CentOSTuorial>.
304 Using these instructions, you should be able to build a complete CentOS
305 4.X server with Catalyst and all the plugins required to run this
312 This tutorial will primarily focus on SQLite because of its simplicity;
313 however, modifications in the script required to support MySQL and
314 PostgreSQL will be presented in Appendix 2.
316 B<Note:> One of the advantages of the MVC design patterns is that
317 applications become much more database independent. As such, you will
318 notice that only the C<.sql> files used to initialize the database
319 change between database systems... the Catalyst code generally remains
324 =head1 WHERE TO GET WORKING CODE
326 Each part of the tutorial has complete code available in the main
327 Catalyst Subversion repository (see the note at the beginning of each
328 part for the appropriate svn command to use). Additionally, the final
329 code is available as a ready-to-run tarball at
330 TO_BE_ADDED_TO_FINAL_VERSION.
335 Kennedy Clark, C<hkclark@gmail.com>
337 Please report any errors, issues or suggestions to the author.
339 Copyright 2006, Kennedy Clark, under Creative Commons License
340 (L<http://creativecommons.org/licenses/by-nc-sa/2.5/>).