3 Catalyst::Manual::Tutorial::Intro - Catalyst Tutorial - Part 1: Introduction
8 This is B<Part 1 of 10> for the Catalyst tutorial.
10 L<Tutorial Overview|Catalyst::Manual::Tutorial>
20 L<Catalyst Basics|Catalyst::Manual::Tutorial::CatalystBasics>
24 L<More Catalyst Basics|Catalyst::Manual::Tutorial::MoreCatalystBasics>
28 L<Basic CRUD|Catalyst::Manual::Tutorial::BasicCRUD>
32 L<Authentication|Catalyst::Manual::Tutorial::Authentication>
36 L<Authorization|Catalyst::Manual::Tutorial::Authorization>
40 L<Debugging|Catalyst::Manual::Tutorial::Debugging>
44 L<Testing|Catalyst::Manual::Tutorial::Testing>
48 L<Advanced CRUD|Catalyst::Manual::Tutorial::AdvancedCRUD>
52 L<Appendices|Catalyst::Manual::Tutorial::Appendices>
59 This tutorial provides a multipart introduction to the Catalyst web
60 framework. It seeks to provide a rapid overview of many of its most
61 commonly used features. The focus is on the real-world best practices
62 required in the construction of nearly all Catalyst applications.
64 Although the primary target of the tutorial is users new to the Catalyst
65 framework, experienced users may wish to review specific sections (for
66 example, how to use DBIC for their model classes, how to add
67 authentication and authorization to an existing application, or form
70 You can obtain the code for all the tutorial examples from the
71 catalyst subversion repository by issuing the command:
73 svn co http://dev.catalyst.perl.org/repos/Catalyst/tags/examples/Tutorial/MyApp/5.7/ CatalystTutorial
75 This will download the current code for each tutorial chapter in the
76 CatalystTutorial directory. Each example application directory has
77 the same name as the tutorial chapter.
79 B<These reference implementations are provided so that when you follow
80 the tutorial, you can use the code from the subversion repository to
81 ensure that your system is set up correctly, and that you have not
82 inadvertently made any typographic errors, or accidentally skipped
83 part of the tutorial.>
85 B<NOTE: You can use any perl-supported OS and environment to run
86 Catalyst.> It should make little or no difference to Catalyst's
87 operation, but this tutorial has been written using Ubuntu 8.10
88 because that represents a quick and easy for most people to try out
89 Catalyst with virtually zero setup time and hassles. See the Catalyst
90 installation section below for more information.
92 If you're reading this manual online, you can download the example
93 program and all the necessary dependencies to your local machine by
94 installing the C<Task::Catalyst::Tutorial> distribution from CPAN:
96 cpan Task::Catalyst::Tutorial
98 This will also test to make sure the dependencies are working. If you
99 have trouble installing these, please ask for help on the #catalyst
100 IRC channel, or the Catalyst mailing list.
102 Subjects covered by the tutorial include:
108 A simple application that lists and adds books.
112 The use of L<DBIx::Class|DBIx::Class> (DBIC) for the model.
116 How to write CRUD (Create, Read, Update, and Delete) operations in
121 Authentication ("auth").
125 Role-based authorization ("authz").
129 Attempts to provide an example showing current (5.7XXX) Catalyst
130 practices. For example, the use of
131 L<Catalyst::Action::RenderView|Catalyst::Action::RenderView>,
132 DBIC, L<Catalyst::Plugin::ConfigLoader|Catalyst::Plugin::ConfigLoader>
133 with C<myapp.conf>, the use of C<lib/MyApp/Controller/Root.pm>
134 vs. C<lib/MyApp.pm>, etc.
138 The use of Template Toolkit (TT) and the
139 L<Catalyst::Helper::View::TTSite|Catalyst::Helper::View::TTSite>
144 Useful techniques for troubleshooting and debugging Catalyst
149 The use of SQLite as a database (with code also provided for MySQL and
154 The use of L<HTML::FormFu|HTML::FormFu> for automated form processing
159 This tutorial makes the learning process its main priority. For
160 example, the level of comments in the code found here would likely be
161 considered excessive in a "normal project." Because of their contextual
162 value, this tutorial will generally favor inline comments over a
163 separate discussion in the text. It also deliberately tries to
164 demonstrate multiple approaches to various features (in general, you
165 should try to be as consistent as possible with your own production
168 Furthermore, this tutorial tries to minimize the number of controllers,
169 models, TT templates, and database tables. Although this does result in
170 things being a bit contrived at times, the concepts should be applicable
171 to more complex environments. More complete and complicated example
172 applications can be found in the C<examples> area of the Catalyst
173 Subversion repository at
174 L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/>.
176 B<Note:> There are a variety of other introductory materials available
177 through the Catalyst web site and at
178 L<http://dev.catalyst.perl.org/wiki/UserIntroductions> and
179 L<http://dev.catalyst.perl.org/>.
181 =head1 VERSIONS AND CONVENTIONS USED IN THIS TUTORIAL
183 This tutorial was built using the following resources. Please note that
184 you may need to make adjustments for different environments and
191 Ubuntu 8.10 (Intrepid Ibex)
199 Catalyst::Devel v1.07
209 The plugins used in this tutorial all have sufficiently stable APIs that
210 you shouldn't need to worry about versions. However, there could be
211 cases where the tutorial is affected by what version of plugins you
212 use. This tutorial has been tested against the following set of plugins:
218 Catalyst::Plugin::Authentication -- v0.10006
222 Catalyst::Plugin::Authorization::ACL -- v0.08
226 Catalyst::Plugin::Authorization::Roles -- v0.05
230 Catalyst::Plugin::ConfigLoader -- v0.20
234 Catalyst::Plugin::Session -- v0.19
238 Catalyst::Plugin::Session::State::Cookie -- v0.09
242 Catalyst::Plugin::Session::Store::FastMmap -- v0.05
246 Catalyst::Plugin::StackTrace -- v0.08
250 Catalyst::Plugin::Static::Simple -- v0.20
256 B<NOTE:> You can check the versions you have installed with the
259 perl -ME<lt>mod_nameE<gt> -e '"print $E<lt>mod_nameE<gt>::VERSION\n"'
262 perl -MCatalyst::Plugin::StackTrace -e 'print "$Catalyst::Plugin::StackTrace::VERSION\n"'
264 Since the web browser is being used on the same box where Perl and the
265 Catalyst development server is running, the URL of
266 C<http://localhost:3000> will be used (the Catalyst development server
267 defaults to port 3000). If you are running Perl on a different box than
268 where your web browser is located (or using a different port number via
269 the C<-p> I<port_number> option to the development server), then you
270 will need to update the URL you use accordingly.
274 Depending on the web browser you are using, you might need to hit
275 C<Shift+Reload> to pull a fresh page when testing your application at
276 various points. Also, the C<-k> keepalive option to the development
277 server can be necessary with some browsers (especially Internet
282 =head1 CATALYST INSTALLATION
284 While the rough edges of Catalyst installation have been a problem in
285 the past, this is now mostly solved. Nonetheless, installing Catalyst
286 can be a little time consuming. Although a compelling strength of
287 Catalyst is that it makes use of many of the modules in the vast
288 repository that is CPAN, this can complicate the installation process.
289 However, there are a growing number of methods that can dramatically
290 ease this undertaking. Of these, the following are likely to be
291 applicable to the largest number of potential new users:
299 Given the popularity of Ubuntu and its ease of use, Ubuntu can be
300 a great way for newcomers to experiment with Catalyst. Because it
301 is a "live CD," you can simply boot from the CD, run a few commands,
302 and you should have a fully functional environment in which to do
303 this tutorial in a matter of minutes.
309 Download Ubuntu 8.10 (aka, Intrepid Ibex) Desktop edition and boot from
310 the CD and/or image file, select your language, and then "Try Ubuntu
311 without any changes to your computer."
315 Open a terminal session (click "Applications" in the upper-left
316 corner, then "Accessories," then "Terminal").
320 Add the 'universe' repositories:
322 sudo gedit /etc/apt/sources.list
324 And remove the comments from the lines under the comments about the
325 'universe' repositories.
332 sudo apt-get install libdbd-sqlite3-perl libcatalyst-perl libcatalyst-modules-perl libconfig-general-perl
334 Accept all of the dependencies. Done.
336 NOTE: If you are low on disk space after the above commands (use C<df />
337 to tell), you can free up some space with
338 C<sudo rm /var/cache/apt/archives/*.deb> (the Live CD uses memory for
339 disk space, so having a decent amount of memory will help). And,
340 while the instructions above mention the Live CD because that makes it
341 easy for people new to Linux, you can obviously also use one of the
342 options to install Ubuntu on your drive.
348 Matt Trout's C<cat-install>
350 Available at L<http://www.shadowcatsystems.co.uk/static/cat-install>,
351 C<cat-install> can be a quick and painless way to get Catalyst up and
352 running. Just download the script from the link above and type C<perl
357 Chris Laco's CatInABox
359 Download the tarball from
360 L<http://handelframework.com/downloads/CatInABox.tar.gz> and unpack it
361 on your machine. Depending on your OS platform, either run C<start.bat>
366 Pre-Built VMWare Images
368 Under the VMWare community program, work is ongoing to develop a number
369 of VMWare images where an entire Catalyst development environment has
370 already been installed, complete with database engines and a full
371 complement of Catalyst plugins.
375 Frank Speiser's Amazon EC2 Catalyst SDK
377 There are currently two flavors of publicly available Amazon Machine
378 Images (AMI) that include all the elements you'd need to begin
379 developing in a fully functional Catalyst environment within minutes.
380 See L<Catalyst::Manual::Installation|Catalyst::Manual::Installation>
385 For additional information and recommendations on Catalyst installation,
387 L<Catalyst::Manual::Installation|Catalyst::Manual::Installation>.
389 B<NOTE:> Step-by-step instructions to replicate the environment on
390 which this tutorial was developed can be found at
391 L<Catalyst::Manual::Installation::CentOS4|Catalyst::Manual::Installation::CentOS4>.
392 Using these instructions, you should be able to build a complete CentOS
393 4.X server with Catalyst and all the plugins required to run this
398 This tutorial will primarily focus on SQLite because of its simplicity
399 of installation and use; however, modifications in the script required
400 to support MySQL and PostgreSQL will be presented in Appendix 2.
402 B<Note:> One of the advantages of the MVC design patterns is that
403 applications become much more database independent. As such, you will
404 notice that only the C<.sql> files used to initialize the database
405 change between database systems: the Catalyst code generally remains the
408 =head1 WHERE TO GET WORKING CODE
410 Each part of the tutorial has complete code available in the main
411 Catalyst Subversion repository (see the note at the beginning of each
412 part for the appropriate svn command to use). Additionally, the final
413 code is available as a ready-to-run tarball at
414 L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/Tutorial/Final_Tarball/MyApp.tgz>.
416 B<NOTE:> You can run the test cases for the final code with the following
419 wget http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/Tutorial/Final_Tarball/MyApp.tgz
422 CATALYST_DEBUG=0 prove --lib lib t
427 Kennedy Clark, C<hkclark@gmail.com>
429 Please report any errors, issues or suggestions to the author. The
430 most recent version of the Catalyst Tutorial can be found at
431 L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/>.
433 Copyright 2006-2008, Kennedy Clark, under Creative Commons License
434 (L<http://creativecommons.org/licenses/by-sa/3.0/us/>).