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