Update thanks for tutorial (include dhoss)
[catagits/Catalyst-Manual.git] / lib / Catalyst / Manual / Tutorial / Intro.pod
CommitLineData
d442cc9f 1=head1 NAME
2
3Catalyst::Manual::Tutorial::Intro - Catalyst Tutorial - Part 1: Introduction
4
5
6=head1 OVERVIEW
7
2b6c29a2 8This is B<Part 1 of 10> for the Catalyst tutorial.
d442cc9f 9
10L<Tutorial Overview|Catalyst::Manual::Tutorial>
11
12=over 4
13
14=item 1
15
16B<Introduction>
17
18=item 2
19
20L<Catalyst Basics|Catalyst::Manual::Tutorial::CatalystBasics>
21
22=item 3
23
1def4a20 24L<More Catalyst Basics|Catalyst::Manual::Tutorial::MoreCatalystBasics>
d442cc9f 25
26=item 4
27
1def4a20 28L<Basic CRUD|Catalyst::Manual::Tutorial::BasicCRUD>
d442cc9f 29
30=item 5
31
1def4a20 32L<Authentication|Catalyst::Manual::Tutorial::Authentication>
d442cc9f 33
34=item 6
35
1def4a20 36L<Authorization|Catalyst::Manual::Tutorial::Authorization>
d442cc9f 37
38=item 7
39
1def4a20 40L<Debugging|Catalyst::Manual::Tutorial::Debugging>
d442cc9f 41
42=item 8
43
1def4a20 44L<Testing|Catalyst::Manual::Tutorial::Testing>
d442cc9f 45
46=item 9
47
1def4a20 48L<Advanced CRUD|Catalyst::Manual::Tutorial::AdvancedCRUD>
49
50=item 10
51
d442cc9f 52L<Appendices|Catalyst::Manual::Tutorial::Appendices>
53
54=back
55
1def4a20 56
d442cc9f 57=head1 DESCRIPTION
58
ffeb7448 59This tutorial provides a multi-part introduction to the Catalyst web
d442cc9f 60framework. It seeks to provide a rapid overview of many of its most
61commonly used features. The focus is on the real-world best practices
62required in the construction of nearly all Catalyst applications.
63
64Although the primary target of the tutorial is users new to the Catalyst
65framework, experienced users may wish to review specific sections (for
1def4a20 66example, how to use DBIC for their model classes, how to add
67authentication and authorization to an existing application, or form
68management).
d442cc9f 69
70You can obtain the code for all the tutorial examples from the
71catalyst subversion repository by issuing the command:
72
73 svn co http://dev.catalyst.perl.org/repos/Catalyst/tags/examples/Tutorial/MyApp/5.7/ CatalystTutorial
74
75This will download the current code for each tutorial chapter in the
76CatalystTutorial directory. Each example application directory has
77the same name as the tutorial chapter.
78
3d9ae335 79B<These reference implementations are provided so that when you follow
80the tutorial, you can use the code from the subversion repository to
81ensure that your system is set up correctly, and that you have not
82inadvertently made any typographic errors, or accidentally skipped
83part of the tutorial.>
84
ffeb7448 85B<NOTE: You can use any Perl-supported OS and environment to run
3533daff 86Catalyst.> It should make little or no difference to Catalyst's
ffeb7448 87operation, B<but this tutorial has been written using Ubuntu 8.10>
3533daff 88because that represents a quick and easy for most people to try out
ffeb7448 89Catalyst with virtually zero setup time and hassles. Also, the tutorial
90has been tested to work correctly with the versions of Catalyst and all
91the supporting modules in Ubuntu 8.10 (see "VERSIONS AND CONVENTIONS
92USED IN THIS TUTORIAL" below for the specific versions for some of the
93key modules), so B<if you think you might be running into an issue
94related to versions> (for example, a module changed its behavior in a
95newer version or a bug was introduced), B<it might be worth giving
96Ubuntu 8.10 a try>. See the "CATALYST INSTALLATION" section below for
97more information.
3533daff 98
99If you're reading this manual online, you can download the example
100program and all the necessary dependencies to your local machine by
101installing the C<Task::Catalyst::Tutorial> distribution from CPAN:
d442cc9f 102
103 cpan Task::Catalyst::Tutorial
104
105This will also test to make sure the dependencies are working. If you
106have trouble installing these, please ask for help on the #catalyst
107IRC channel, or the Catalyst mailing list.
108
3533daff 109Subjects covered by the tutorial include:
d442cc9f 110
111=over 4
112
113=item *
114
115A simple application that lists and adds books.
116
117=item *
118
119The use of L<DBIx::Class|DBIx::Class> (DBIC) for the model.
120
121=item *
122
123How to write CRUD (Create, Read, Update, and Delete) operations in
124Catalyst.
125
126=item *
127
128Authentication ("auth").
129
130=item *
131
132Role-based authorization ("authz").
133
134=item *
135
136Attempts to provide an example showing current (5.7XXX) Catalyst
137practices. For example, the use of
138L<Catalyst::Action::RenderView|Catalyst::Action::RenderView>,
139DBIC, L<Catalyst::Plugin::ConfigLoader|Catalyst::Plugin::ConfigLoader>
45d511e0 140with C<myapp.conf>, the use of C<lib/MyApp/Controller/Root.pm>
d442cc9f 141vs. C<lib/MyApp.pm>, etc.
142
143=item *
144
1390ef0e 145The use of Template Toolkit (TT).
d442cc9f 146
147=item *
148
149Useful techniques for troubleshooting and debugging Catalyst
150applications.
151
152=item *
153
154The use of SQLite as a database (with code also provided for MySQL and
155PostgreSQL).
156
157=item *
158
1def4a20 159The use of L<HTML::FormFu|HTML::FormFu> for automated form processing
d442cc9f 160and validation.
161
162=back
163
164This tutorial makes the learning process its main priority. For
165example, the level of comments in the code found here would likely be
1def4a20 166considered excessive in a "normal project." Because of their contextual
d442cc9f 167value, this tutorial will generally favor inline comments over a
168separate discussion in the text. It also deliberately tries to
169demonstrate multiple approaches to various features (in general, you
170should try to be as consistent as possible with your own production
171code).
172
173Furthermore, this tutorial tries to minimize the number of controllers,
174models, TT templates, and database tables. Although this does result in
175things being a bit contrived at times, the concepts should be applicable
176to more complex environments. More complete and complicated example
177applications can be found in the C<examples> area of the Catalyst
178Subversion repository at
179L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/>.
180
181B<Note:> There are a variety of other introductory materials available
182through the Catalyst web site and at
183L<http://dev.catalyst.perl.org/wiki/UserIntroductions> and
184L<http://dev.catalyst.perl.org/>.
185
1390ef0e 186
d442cc9f 187=head1 VERSIONS AND CONVENTIONS USED IN THIS TUTORIAL
188
189This tutorial was built using the following resources. Please note that
190you may need to make adjustments for different environments and
191versions:
192
193=over 4
194
195=item *
196
865d3efb 197Ubuntu 8.10 (Intrepid Ibex)
d442cc9f 198
199=item *
200
865d3efb 201Catalyst v5.7014
dd88c3b6 202
22a67212 203=item *
dd88c3b6 204
865d3efb 205Catalyst::Devel v1.07
d442cc9f 206
207=item *
208
865d3efb 209DBIx::Class v0.08010
d442cc9f 210
211=item *
212
213Catalyst Plugins
214
215The plugins used in this tutorial all have sufficiently stable APIs that
216you shouldn't need to worry about versions. However, there could be
217cases where the tutorial is affected by what version of plugins you
218use. This tutorial has been tested against the following set of plugins:
219
220=over 4
221
222=item *
223
865d3efb 224Catalyst::Plugin::Authentication -- v0.10006
d442cc9f 225
226=item *
227
1def4a20 228Catalyst::Plugin::Authorization::ACL -- v0.08
d442cc9f 229
230=item *
231
1def4a20 232Catalyst::Plugin::Authorization::Roles -- v0.05
d442cc9f 233
234=item *
235
865d3efb 236Catalyst::Plugin::ConfigLoader -- v0.20
d442cc9f 237
238=item *
239
865d3efb 240Catalyst::Plugin::Session -- v0.19
d442cc9f 241
242=item *
243
865d3efb 244Catalyst::Plugin::Session::State::Cookie -- v0.09
d442cc9f 245
246=item *
247
865d3efb 248Catalyst::Plugin::Session::Store::FastMmap -- v0.05
d442cc9f 249
250=item *
251
865d3efb 252Catalyst::Plugin::StackTrace -- v0.08
d442cc9f 253
254=item *
255
1def4a20 256Catalyst::Plugin::Static::Simple -- v0.20
d442cc9f 257
258=back
259
260=item *
261
865d3efb 262B<NOTE:> You can check the versions you have installed with the
263following command:
264
265 perl -ME<lt>mod_nameE<gt> -e '"print $E<lt>mod_nameE<gt>::VERSION\n"'
266
267For example:
268 perl -MCatalyst::Plugin::StackTrace -e 'print "$Catalyst::Plugin::StackTrace::VERSION\n"'
269
d442cc9f 270Since the web browser is being used on the same box where Perl and the
271Catalyst development server is running, the URL of
272C<http://localhost:3000> will be used (the Catalyst development server
273defaults to port 3000). If you are running Perl on a different box than
274where your web browser is located (or using a different port number via
275the C<-p> I<port_number> option to the development server), then you
276will need to update the URL you use accordingly.
277
278=item *
279
1390ef0e 280Depending on the web browser you are using, you might need to hit
281C<Shift+Reload> or C<Ctrl+Reload> to pull a fresh page when testing
282your application at various points (see
283L<http://en.wikipedia.org/wiki/Bypass_your_cache> for a comprehensive
284list of options for each browser). Also, the C<-k> keepalive option
285to the development server can be necessary with some browsers
286(especially Internet Explorer).
d442cc9f 287
288=back
289
1390ef0e 290
d442cc9f 291=head1 CATALYST INSTALLATION
292
6c3e46a6 293While the rough edges of Catalyst installation have been a problem in
0c51850e 294the past, this is now mostly solved. Nonetheless, installing Catalyst
295can be a little time consuming. Although a compelling strength of
296Catalyst is that it makes use of many of the modules in the vast
297repository that is CPAN, this can complicate the installation process.
298However, there are a growing number of methods that can dramatically
299ease this undertaking. Of these, the following are likely to be
300applicable to the largest number of potential new users:
1def4a20 301
302=over 4
303
304=item *
305
306Ubuntu
307
ffeb7448 308Given the popularity of Ubuntu and its ease of use, Ubuntu can be a
309great way for newcomers to experiment with Catalyst. Because it is a
310"live CD," you can simply boot from the CD, run a few commands, and you
311should have a fully functional environment in which to do this tutorial
312in a matter of minutes. B<The tutorial was fully tested to work under
313Ubuntu 8.10. Although it SHOULD work under any Catalyst installation
314method you might choose, it can be hard to guarantee this.>
d442cc9f 315
316=over 4
317
318=item *
319
865d3efb 320Download Ubuntu 8.10 (aka, Intrepid Ibex) Desktop edition and boot from
3533daff 321the CD and/or image file, select your language, and then "Try Ubuntu
322without any changes to your computer."
1def4a20 323
324=item *
325
3533daff 326Open a terminal session (click "Applications" in the upper-left
327corner, then "Accessories," then "Terminal").
1def4a20 328
329=item *
330
331Add the 'universe' repositories:
332
3533daff 333 sudo gedit /etc/apt/sources.list
1def4a20 334
335And remove the comments from the lines under the comments about the
336'universe' repositories.
337
338=item *
339
340Install Catalyst:
341
342 sudo apt-get update
15e1d0b2 343 sudo apt-get install libdbd-sqlite3-perl libcatalyst-perl libcatalyst-modules-perl libconfig-general-perl
1def4a20 344
345Accept all of the dependencies. Done.
346
3533daff 347NOTE: If you are low on disk space after the above commands (use C<df />
348to tell), you can free up some space with
349C<sudo rm /var/cache/apt/archives/*.deb> (the Live CD uses memory for
350disk space, so having a decent amount of memory will help). And,
351while the instructions above mention the Live CD because that makes it
352easy for people new to Linux, you can obviously also use one of the
353options to install Ubuntu on your drive.
354
1def4a20 355=back
356
357=item *
358
d442cc9f 359Matt Trout's C<cat-install>
360
ffeb7448 361Available at L<http://www.shadowcatsystems.co.uk/static/cat-install>,
362C<cat-install> can be a fairly painless way to get Catalyst up and
363running. Just download the script from the link above and type C<perl
364cat-install>. Depending on the speed of your Internet connection and
365your computer, it will probably take 30 to 60 minutes to install because
366it downloads, makes, compiles, and tests every module. But this is an
367excellent way to automate the installation of all the latest modules
368used by Catalyst from CPAN.
369
d442cc9f 370
371=item *
372
ffeb7448 373Other Possibilities
374
375=over 4
376
377=item *
378
379OpenBSD Packages
380
381The 2008 Advent Day 4 entry has more information on using OpenBSD
382packages to quickly build a system:
383L<http://www.catalystframework.org/calendar/2008/4>.
384
385=item *
d442cc9f 386
ffeb7448 387NetBSD Package Collection on Solaris
388
389The 2008 Advent Day 15 entry has more information on using C<pkgsrc> and
390NetBSD packages on Solaris:
391L<http://www.catalystframework.org/calendar/2008/15|>.
d442cc9f 392
393=item *
394
ffeb7448 395CatInABox
396
397You can get more information at
398L<http://www.catalystframework.org/calendar/2008/7>
399or L<Perl::Dist::CatInABox|Perl::Dist::CatInABox>.
400
401
402=item *
403
d442cc9f 404Pre-Built VMWare Images
405
406Under the VMWare community program, work is ongoing to develop a number
407of VMWare images where an entire Catalyst development environment has
408already been installed, complete with database engines and a full
409complement of Catalyst plugins.
410
0c51850e 411=item *
412
413Frank Speiser's Amazon EC2 Catalyst SDK
414
415There are currently two flavors of publicly available Amazon Machine
416Images (AMI) that include all the elements you'd need to begin
417developing in a fully functional Catalyst environment within minutes.
418See L<Catalyst::Manual::Installation|Catalyst::Manual::Installation>
419for more details.
420
d442cc9f 421=back
422
ffeb7448 423=back
424
d442cc9f 425For additional information and recommendations on Catalyst installation,
426please refer to
427L<Catalyst::Manual::Installation|Catalyst::Manual::Installation>.
428
429B<NOTE:> Step-by-step instructions to replicate the environment on
430which this tutorial was developed can be found at
431L<Catalyst::Manual::Installation::CentOS4|Catalyst::Manual::Installation::CentOS4>.
432Using these instructions, you should be able to build a complete CentOS
4334.X server with Catalyst and all the plugins required to run this
434tutorial.
435
1390ef0e 436
d442cc9f 437=head1 DATABASES
438
439This tutorial will primarily focus on SQLite because of its simplicity
440of installation and use; however, modifications in the script required
441to support MySQL and PostgreSQL will be presented in Appendix 2.
442
443B<Note:> One of the advantages of the MVC design patterns is that
444applications become much more database independent. As such, you will
445notice that only the C<.sql> files used to initialize the database
446change between database systems: the Catalyst code generally remains the
447same.
448
1390ef0e 449
d442cc9f 450=head1 WHERE TO GET WORKING CODE
451
452Each part of the tutorial has complete code available in the main
453Catalyst Subversion repository (see the note at the beginning of each
454part for the appropriate svn command to use). Additionally, the final
2c128490 455code through Part 8 of the tutorial is available as a ready-to-run
456tarball at
457L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/Tutorial/Final_Tarball/MyApp_Part8.tgz>.
458The final code for other parts of the tutorial are available at:
459L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/Tutorial/Final_Tarballs_Per_Part/>.
460
d442cc9f 461
462B<NOTE:> You can run the test cases for the final code with the following
463commands:
464
2c128490 465 wget http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/Tutorial/Final_Tarball/MyApp_Part8.tgz
d442cc9f 466 tar zxvf MyApp.tgz
467 cd MyApp
468 CATALYST_DEBUG=0 prove --lib lib t
469
470
471=head1 AUTHOR
472
473Kennedy Clark, C<hkclark@gmail.com>
474
475Please report any errors, issues or suggestions to the author. The
476most recent version of the Catalyst Tutorial can be found at
82ab4bbf 477L<http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/>.
d442cc9f 478
45c7830f 479Copyright 2006-2008, Kennedy Clark, under Creative Commons License
865d3efb 480(L<http://creativecommons.org/licenses/by-sa/3.0/us/>).