Update method used to free up disk space for live CD
[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
2b75577c 345Accept all of the dependencies. Done.
346
347If you are running from the Live CD, you probably also want to free up
348some disk space with the following:
349
350 sudo apt-get clean
351
352NOTE: While the instructions above mention the Live CD because that
353makes it easy for people new to Linux, you can obviously also use one
354of the options to install Ubuntu on your drive.
3533daff 355
1def4a20 356=back
357
358=item *
359
d442cc9f 360Matt Trout's C<cat-install>
361
ffeb7448 362Available at L<http://www.shadowcatsystems.co.uk/static/cat-install>,
363C<cat-install> can be a fairly painless way to get Catalyst up and
364running. Just download the script from the link above and type C<perl
365cat-install>. Depending on the speed of your Internet connection and
366your computer, it will probably take 30 to 60 minutes to install because
367it downloads, makes, compiles, and tests every module. But this is an
368excellent way to automate the installation of all the latest modules
369used by Catalyst from CPAN.
370
d442cc9f 371
372=item *
373
ffeb7448 374Other Possibilities
375
376=over 4
377
378=item *
379
380OpenBSD Packages
381
382The 2008 Advent Day 4 entry has more information on using OpenBSD
383packages to quickly build a system:
384L<http://www.catalystframework.org/calendar/2008/4>.
385
386=item *
d442cc9f 387
ffeb7448 388NetBSD Package Collection on Solaris
389
390The 2008 Advent Day 15 entry has more information on using C<pkgsrc> and
391NetBSD packages on Solaris:
392L<http://www.catalystframework.org/calendar/2008/15|>.
d442cc9f 393
394=item *
395
ffeb7448 396CatInABox
397
398You can get more information at
399L<http://www.catalystframework.org/calendar/2008/7>
400or L<Perl::Dist::CatInABox|Perl::Dist::CatInABox>.
401
402
403=item *
404
d442cc9f 405Pre-Built VMWare Images
406
407Under the VMWare community program, work is ongoing to develop a number
408of VMWare images where an entire Catalyst development environment has
409already been installed, complete with database engines and a full
410complement of Catalyst plugins.
411
0c51850e 412=item *
413
414Frank Speiser's Amazon EC2 Catalyst SDK
415
416There are currently two flavors of publicly available Amazon Machine
417Images (AMI) that include all the elements you'd need to begin
418developing in a fully functional Catalyst environment within minutes.
419See L<Catalyst::Manual::Installation|Catalyst::Manual::Installation>
420for more details.
421
d442cc9f 422=back
423
ffeb7448 424=back
425
d442cc9f 426For additional information and recommendations on Catalyst installation,
427please refer to
428L<Catalyst::Manual::Installation|Catalyst::Manual::Installation>.
429
430B<NOTE:> Step-by-step instructions to replicate the environment on
431which this tutorial was developed can be found at
432L<Catalyst::Manual::Installation::CentOS4|Catalyst::Manual::Installation::CentOS4>.
433Using these instructions, you should be able to build a complete CentOS
4344.X server with Catalyst and all the plugins required to run this
435tutorial.
436
1390ef0e 437
d442cc9f 438=head1 DATABASES
439
440This tutorial will primarily focus on SQLite because of its simplicity
441of installation and use; however, modifications in the script required
442to support MySQL and PostgreSQL will be presented in Appendix 2.
443
444B<Note:> One of the advantages of the MVC design patterns is that
445applications become much more database independent. As such, you will
446notice that only the C<.sql> files used to initialize the database
447change between database systems: the Catalyst code generally remains the
448same.
449
1390ef0e 450
d442cc9f 451=head1 WHERE TO GET WORKING CODE
452
453Each part of the tutorial has complete code available in the main
454Catalyst Subversion repository (see the note at the beginning of each
455part for the appropriate svn command to use). Additionally, the final
2c128490 456code through Part 8 of the tutorial is available as a ready-to-run
457tarball at
458L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/Tutorial/Final_Tarball/MyApp_Part8.tgz>.
459The final code for other parts of the tutorial are available at:
460L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/Tutorial/Final_Tarballs_Per_Part/>.
461
d442cc9f 462
463B<NOTE:> You can run the test cases for the final code with the following
464commands:
465
2c128490 466 wget http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/Tutorial/Final_Tarball/MyApp_Part8.tgz
d442cc9f 467 tar zxvf MyApp.tgz
468 cd MyApp
469 CATALYST_DEBUG=0 prove --lib lib t
470
471
472=head1 AUTHOR
473
474Kennedy Clark, C<hkclark@gmail.com>
475
476Please report any errors, issues or suggestions to the author. The
477most recent version of the Catalyst Tutorial can be found at
82ab4bbf 478L<http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/>.
d442cc9f 479
45c7830f 480Copyright 2006-2008, Kennedy Clark, under Creative Commons License
865d3efb 481(L<http://creativecommons.org/licenses/by-sa/3.0/us/>).