Rework tutorial. Lots of things changed, but key items include: new content in Catal...
[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
3533daff 8This is B<Part 2 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
87operation, but this tutorial has been written using Ubuntu 8.04
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>
133with C<myapp.yml>, the use of C<lib/MyApp/Controller/Root.pm>
134vs. C<lib/MyApp.pm>, etc.
135
136=item *
137
138The use of Template Toolkit (TT) and the
139L<Catalyst::Helper::View::TTSite|Catalyst::Helper::View::TTSite>
140view helper.
141
142=item *
143
144Useful techniques for troubleshooting and debugging Catalyst
145applications.
146
147=item *
148
149The use of SQLite as a database (with code also provided for MySQL and
150PostgreSQL).
151
152=item *
153
1def4a20 154The use of L<HTML::FormFu|HTML::FormFu> for automated form processing
d442cc9f 155and validation.
156
157=back
158
159This tutorial makes the learning process its main priority. For
160example, the level of comments in the code found here would likely be
1def4a20 161considered excessive in a "normal project." Because of their contextual
d442cc9f 162value, this tutorial will generally favor inline comments over a
163separate discussion in the text. It also deliberately tries to
164demonstrate multiple approaches to various features (in general, you
165should try to be as consistent as possible with your own production
166code).
167
168Furthermore, this tutorial tries to minimize the number of controllers,
169models, TT templates, and database tables. Although this does result in
170things being a bit contrived at times, the concepts should be applicable
171to more complex environments. More complete and complicated example
172applications can be found in the C<examples> area of the Catalyst
173Subversion repository at
174L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/>.
175
176B<Note:> There are a variety of other introductory materials available
177through the Catalyst web site and at
178L<http://dev.catalyst.perl.org/wiki/UserIntroductions> and
179L<http://dev.catalyst.perl.org/>.
180
181=head1 VERSIONS AND CONVENTIONS USED IN THIS TUTORIAL
182
183This tutorial was built using the following resources. Please note that
184you may need to make adjustments for different environments and
185versions:
186
187=over 4
188
189=item *
190
1def4a20 191Ubuntu 8.04 Hardy Heron
d442cc9f 192
193=item *
194
1def4a20 195Catalyst v5.7011
dd88c3b6 196
22a67212 197=item *
dd88c3b6 198
1def4a20 199Catalyst::Devel v1.03
d442cc9f 200
201=item *
202
1def4a20 203DBIx::Class v0.08008
d442cc9f 204
205=item *
206
207Catalyst Plugins
208
209The plugins used in this tutorial all have sufficiently stable APIs that
210you shouldn't need to worry about versions. However, there could be
211cases where the tutorial is affected by what version of plugins you
212use. This tutorial has been tested against the following set of plugins:
213
214=over 4
215
216=item *
217
1def4a20 218Catalyst::Plugin::Authentication -- v0.10002
d442cc9f 219
220=item *
221
1def4a20 222Catalyst::Plugin::Authentication::Store::DBIC -- v0.09
d442cc9f 223
224=item *
225
1def4a20 226Catalyst::Plugin::Authorization::ACL -- v0.08
d442cc9f 227
228=item *
229
1def4a20 230Catalyst::Plugin::Authorization::Roles -- v0.05
d442cc9f 231
232=item *
233
1def4a20 234Catalyst::Plugin::ConfigLoader -- v0.17
d442cc9f 235
236=item *
237
1def4a20 238Catalyst::Plugin::Session -- v0.18
d442cc9f 239
240=item *
241
1def4a20 242Catalyst::Plugin::Session::State::Cookie -- v0.08
d442cc9f 243
244=item *
245
1def4a20 246Catalyst::Plugin::Session::Store::FastMmap -- v0.03
d442cc9f 247
248=item *
249
1def4a20 250Catalyst::Plugin::StackTrace -- v0.06
d442cc9f 251
252=item *
253
1def4a20 254Catalyst::Plugin::Static::Simple -- v0.20
d442cc9f 255
256=back
257
258=item *
259
260Since the web browser is being used on the same box where Perl and the
261Catalyst development server is running, the URL of
262C<http://localhost:3000> will be used (the Catalyst development server
263defaults to port 3000). If you are running Perl on a different box than
264where your web browser is located (or using a different port number via
265the C<-p> I<port_number> option to the development server), then you
266will need to update the URL you use accordingly.
267
268=item *
269
270Depending on the web browser you are using, you might need to hit
271C<Shift+Reload> to pull a fresh page when testing your application at
272various points. Also, the C<-k> keepalive option to the development
273server can be necessary with some browsers (especially Internet
274Explorer).
275
276=back
277
278=head1 CATALYST INSTALLATION
279
1def4a20 280If approach in the wrong manner, it can be a daunting tasks to get
3533daff 281Catalyst initially installed. Although a compelling strength of
1def4a20 282Catalyst is that it makes use of many of the modules in the
283vast repository that is CPAN, this can complicate the installation
284process. However, there are a growing number of methods
285that can dramatically ease this undertaking. Of these, the following
286are likely to be applicable to the largest number of potential new
287users:
288
289=over 4
290
291=item *
292
293Ubuntu
294
295Given the popularity of Ubuntu and it's ease of use, Ubuntu can be
296a great way for newcomers to experiment with Catalyst. Because it
297is a "live CD," you can simply boot from the CD, run a few commands,
298and you should have a fully functional environment in which to do
299this tutorial in a matter of minutes.
d442cc9f 300
301=over 4
302
303=item *
304
3533daff 305Download Ubuntu 8.04 (aka, Hardy Heron) Desktop edition and boot from
306the CD and/or image file, select your language, and then "Try Ubuntu
307without any changes to your computer."
1def4a20 308
309=item *
310
3533daff 311Open a terminal session (click "Applications" in the upper-left
312corner, then "Accessories," then "Terminal").
1def4a20 313
314=item *
315
316Add the 'universe' repositories:
317
3533daff 318 sudo gedit /etc/apt/sources.list
1def4a20 319
320And remove the comments from the lines under the comments about the
321'universe' repositories.
322
323=item *
324
325Install Catalyst:
326
327 sudo apt-get update
3533daff 328 sudo apt-get install libdbd-sqlite3-perl libcatalyst-perl libcatalyst-modules-perl
1def4a20 329
330Accept all of the dependencies. Done.
331
3533daff 332NOTE: If you are low on disk space after the above commands (use C<df />
333to tell), you can free up some space with
334C<sudo rm /var/cache/apt/archives/*.deb> (the Live CD uses memory for
335disk space, so having a decent amount of memory will help). And,
336while the instructions above mention the Live CD because that makes it
337easy for people new to Linux, you can obviously also use one of the
338options to install Ubuntu on your drive.
339
1def4a20 340=back
341
342=item *
343
d442cc9f 344Matt Trout's C<cat-install>
345
346Available at L<http://www.shadowcatsystems.co.uk/static/cat-install>,
347C<cat-install> can be a quick and painless way to get Catalyst up and
348running. Just download the script from the link above and type C<perl
349cat-install>.
350
351=item *
352
353Chris Laco's CatInABox
354
355Download the tarball from
356L<http://handelframework.com/downloads/CatInABox.tar.gz> and unpack it
357on your machine. Depending on your OS platform, either run C<start.bat>
358or C<start.sh>.
359
360=item *
361
362Pre-Built VMWare Images
363
364Under the VMWare community program, work is ongoing to develop a number
365of VMWare images where an entire Catalyst development environment has
366already been installed, complete with database engines and a full
367complement of Catalyst plugins.
368
369=back
370
371For additional information and recommendations on Catalyst installation,
372please refer to
373L<Catalyst::Manual::Installation|Catalyst::Manual::Installation>.
374
375B<NOTE:> Step-by-step instructions to replicate the environment on
376which this tutorial was developed can be found at
377L<Catalyst::Manual::Installation::CentOS4|Catalyst::Manual::Installation::CentOS4>.
378Using these instructions, you should be able to build a complete CentOS
3794.X server with Catalyst and all the plugins required to run this
380tutorial.
381
382=head1 DATABASES
383
384This tutorial will primarily focus on SQLite because of its simplicity
385of installation and use; however, modifications in the script required
386to support MySQL and PostgreSQL will be presented in Appendix 2.
387
388B<Note:> One of the advantages of the MVC design patterns is that
389applications become much more database independent. As such, you will
390notice that only the C<.sql> files used to initialize the database
391change between database systems: the Catalyst code generally remains the
392same.
393
394=head1 WHERE TO GET WORKING CODE
395
396Each part of the tutorial has complete code available in the main
397Catalyst Subversion repository (see the note at the beginning of each
398part for the appropriate svn command to use). Additionally, the final
399code is available as a ready-to-run tarball at
400L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/Tutorial/Final_Tarball/MyApp.tgz>.
401
402B<NOTE:> You can run the test cases for the final code with the following
403commands:
404
405 wget http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/Tutorial/Final_Tarball/MyApp.tgz
406 tar zxvf MyApp.tgz
407 cd MyApp
408 CATALYST_DEBUG=0 prove --lib lib t
409
410
411=head1 AUTHOR
412
413Kennedy Clark, C<hkclark@gmail.com>
414
415Please report any errors, issues or suggestions to the author. The
416most recent version of the Catalyst Tutorial can be found at
d712b826 417L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/>.
d442cc9f 418
419Copyright 2006, Kennedy Clark, under Creative Commons License
420(L<http://creativecommons.org/licenses/by-nc-sa/2.5/>).
421
422