3 Catalyst::Manual::Tutorial::Intro - Catalyst Tutorial - Part 1: Introduction
8 This is B<Part 1 of 9> of the Catalyst Tutorial.
10 L<Tutorial Overview|Catalyst::Manual::Tutorial>
20 L<Catalyst Basics|Catalyst::Manual::Tutorial::CatalystBasics>
24 L<Basic CRUD|Catalyst::Manual::Tutorial::BasicCRUD>
28 L<Authentication|Catalyst::Manual::Tutorial::Authentication>
32 L<Authorization|Catalyst::Manual::Tutorial::Authorization>
36 L<Debugging|Catalyst::Manual::Tutorial::Debugging>
40 L<Testing|Catalyst::Manual::Tutorial::Testing>
44 L<Advanced CRUD|Catalyst::Manual::Tutorial::AdvancedCRUD>
48 L<Appendices|Catalyst::Manual::Tutorial::Appendices>
54 This tutorial provides a multipart introduction to the Catalyst web
55 framework. It seeks to provide a rapid overview of many of its most
56 commonly used features. The focus is on the real-world best practices
57 required in the construction of nearly all Catalyst applications.
59 Although the primary target of the tutorial is users new to the Catalyst
60 framework, experienced users may wish to review specific sections (for
61 example, how to use DBIC for their model classes or how to add
62 authentication and authorization to an existing application).
64 You can obtain the code for all the tutorial examples from the
65 catalyst subversion repository by issuing the command:
67 svn co http://dev.catalyst.perl.org/repos/Catalyst/tags/examples/Tutorial/MyApp/5.7/ CatalystTutorial
69 This will download the current code for each tutorial chapter in the
70 CatalystTutorial directory. Each example application directory has
71 the same name as the tutorial chapter.
73 Additionally, if you're reading this manual online, you can download
74 the example program and all the necessary dependencies to
75 your local machine by installing the C<Task::Catalyst::Tutorial>
76 distribution from CPAN:
78 cpan Task::Catalyst::Tutorial
80 This will also test to make sure the dependencies are working. If you
81 have trouble installing these, please ask for help on the #catalyst
82 IRC channel, or the Catalyst mailing list.
84 Subjects covered include:
90 A simple application that lists and adds books.
94 The use of L<DBIx::Class|DBIx::Class> (DBIC) for the model.
98 How to write CRUD (Create, Read, Update, and Delete) operations in
103 Authentication ("auth").
107 Role-based authorization ("authz").
111 Attempts to provide an example showing current (5.7XXX) Catalyst
112 practices. For example, the use of
113 L<Catalyst::Action::RenderView|Catalyst::Action::RenderView>,
114 DBIC, L<Catalyst::Plugin::ConfigLoader|Catalyst::Plugin::ConfigLoader>
115 with C<myapp.yml>, the use of C<lib/MyApp/Controller/Root.pm>
116 vs. C<lib/MyApp.pm>, etc.
120 The use of Template Toolkit (TT) and the
121 L<Catalyst::Helper::View::TTSite|Catalyst::Helper::View::TTSite>
126 Useful techniques for troubleshooting and debugging Catalyst
131 The use of SQLite as a database (with code also provided for MySQL and
136 The use of L<HTML::Widget|HTML::Widget> for automated form processing
141 This tutorial makes the learning process its main priority. For
142 example, the level of comments in the code found here would likely be
143 considered excessive in a "normal project". Because of their contextual
144 value, this tutorial will generally favor inline comments over a
145 separate discussion in the text. It also deliberately tries to
146 demonstrate multiple approaches to various features (in general, you
147 should try to be as consistent as possible with your own production
150 Furthermore, this tutorial tries to minimize the number of controllers,
151 models, TT templates, and database tables. Although this does result in
152 things being a bit contrived at times, the concepts should be applicable
153 to more complex environments. More complete and complicated example
154 applications can be found in the C<examples> area of the Catalyst
155 Subversion repository at
156 L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/>.
158 B<Note:> There are a variety of other introductory materials available
159 through the Catalyst web site and at
160 L<http://dev.catalyst.perl.org/wiki/UserIntroductions> and
161 L<http://dev.catalyst.perl.org/>.
163 =head1 VERSIONS AND CONVENTIONS USED IN THIS TUTORIAL
165 This tutorial was built using the following resources. Please note that
166 you may need to make adjustments for different environments and
173 OS = CentOS 4 Linux (RHEL 4)
187 The plugins used in this tutorial all have sufficiently stable APIs that
188 you shouldn't need to worry about versions. However, there could be
189 cases where the tutorial is affected by what version of plugins you
190 use. This tutorial has been tested against the following set of plugins:
196 Catalyst::Plugin::Authentication -- 0.09
200 Catalyst::Plugin::Authentication::Store::DBIC -- 0.07
204 Catalyst::Plugin::Authorization::ACL -- 0.08
208 Catalyst::Plugin::Authorization::Roles -- 0.04
212 Catalyst::Plugin::ConfigLoader -- 0.13
216 Catalyst::Plugin::HTML::Widget -- 1.1
220 Catalyst::Plugin::Session -- 0.12
224 Catalyst::Plugin::Session::State::Cookie -- 0.05
228 Catalyst::Plugin::Session::Store::FastMmap -- 0.02
232 Catalyst::Plugin::StackTrace -- 0.06
236 Catalyst::Plugin::Static::Simple -- 0.14
242 Since the web browser is being used on the same box where Perl and the
243 Catalyst development server is running, the URL of
244 C<http://localhost:3000> will be used (the Catalyst development server
245 defaults to port 3000). If you are running Perl on a different box than
246 where your web browser is located (or using a different port number via
247 the C<-p> I<port_number> option to the development server), then you
248 will need to update the URL you use accordingly.
252 Depending on the web browser you are using, you might need to hit
253 C<Shift+Reload> to pull a fresh page when testing your application at
254 various points. Also, the C<-k> keepalive option to the development
255 server can be necessary with some browsers (especially Internet
260 =head1 CATALYST INSTALLATION
262 Unfortunately, one of the most daunting tasks faced by newcomers to
263 Catalyst is getting it installed. Although a compelling strength of
264 Catalyst is that it can easily make use of many of the modules in the
265 vast repository that is CPAN, this can result in initial installations
266 that are both time consuming and frustrating. However, there are a
267 growing number of methods that can dramatically ease this undertaking.
268 Of these, the following are likely to be applicable to the largest
269 number of potential new users:
275 Matt Trout's C<cat-install>
277 Available at L<http://www.shadowcatsystems.co.uk/static/cat-install>,
278 C<cat-install> can be a quick and painless way to get Catalyst up and
279 running. Just download the script from the link above and type C<perl
284 Chris Laco's CatInABox
286 Download the tarball from
287 L<http://handelframework.com/downloads/CatInABox.tar.gz> and unpack it
288 on your machine. Depending on your OS platform, either run C<start.bat>
293 Pre-Built VMWare Images
295 Under the VMWare community program, work is ongoing to develop a number
296 of VMWare images where an entire Catalyst development environment has
297 already been installed, complete with database engines and a full
298 complement of Catalyst plugins.
302 For additional information and recommendations on Catalyst installation,
304 L<Catalyst::Manual::Installation|Catalyst::Manual::Installation>.
306 B<NOTE:> Step-by-step instructions to replicate the environment on
307 which this tutorial was developed can be found at
308 L<Catalyst::Manual::Installation::CentOS4|Catalyst::Manual::Installation::CentOS4>.
309 Using these instructions, you should be able to build a complete CentOS
310 4.X server with Catalyst and all the plugins required to run this
315 This tutorial will primarily focus on SQLite because of its simplicity
316 of installation and use; however, modifications in the script required
317 to support MySQL and PostgreSQL will be presented in Appendix 2.
319 B<Note:> One of the advantages of the MVC design patterns is that
320 applications become much more database independent. As such, you will
321 notice that only the C<.sql> files used to initialize the database
322 change between database systems: the Catalyst code generally remains the
325 =head1 WHERE TO GET WORKING CODE
327 Each part of the tutorial has complete code available in the main
328 Catalyst Subversion repository (see the note at the beginning of each
329 part for the appropriate svn command to use). Additionally, the final
330 code is available as a ready-to-run tarball at
331 L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/Tutorial/Final_Tarball/MyApp.tgz>.
333 B<NOTE:> You can run the test cases for the final code with the following
336 wget http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/Tutorial/Final_Tarball/MyApp.tgz
339 CATALYST_DEBUG=0 prove --lib lib t
344 Kennedy Clark, C<hkclark@gmail.com>
346 Please report any errors, issues or suggestions to the author. The
347 most recent version of the Catalyst Tutorial can be found at
348 L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/Catalyst-Runtime/lib/Catalyst/Manual/Tutorial/>.
350 Copyright 2006, Kennedy Clark, under Creative Commons License
351 (L<http://creativecommons.org/licenses/by-nc-sa/2.5/>).