Commit | Line | Data |
d442cc9f |
1 | =head1 NAME |
2 | |
3 | Catalyst::Manual::Tutorial::Intro - Catalyst Tutorial - Part 1: Introduction |
4 | |
5 | |
6 | =head1 OVERVIEW |
7 | |
8 | This is B<Part 1 of 9> of the Catalyst Tutorial. |
9 | |
10 | L<Tutorial Overview|Catalyst::Manual::Tutorial> |
11 | |
12 | =over 4 |
13 | |
14 | =item 1 |
15 | |
16 | B<Introduction> |
17 | |
18 | =item 2 |
19 | |
20 | L<Catalyst Basics|Catalyst::Manual::Tutorial::CatalystBasics> |
21 | |
22 | =item 3 |
23 | |
24 | L<Basic CRUD|Catalyst::Manual::Tutorial::BasicCRUD> |
25 | |
26 | =item 4 |
27 | |
28 | L<Authentication|Catalyst::Manual::Tutorial::Authentication> |
29 | |
30 | =item 5 |
31 | |
32 | L<Authorization|Catalyst::Manual::Tutorial::Authorization> |
33 | |
34 | =item 6 |
35 | |
36 | L<Debugging|Catalyst::Manual::Tutorial::Debugging> |
37 | |
38 | =item 7 |
39 | |
40 | L<Testing|Catalyst::Manual::Tutorial::Testing> |
41 | |
42 | =item 8 |
43 | |
44 | L<Advanced CRUD|Catalyst::Manual::Tutorial::AdvancedCRUD> |
45 | |
46 | =item 9 |
47 | |
48 | L<Appendices|Catalyst::Manual::Tutorial::Appendices> |
49 | |
50 | =back |
51 | |
52 | =head1 DESCRIPTION |
53 | |
54 | This tutorial provides a multipart introduction to the Catalyst web |
55 | framework. It seeks to provide a rapid overview of many of its most |
56 | commonly used features. The focus is on the real-world best practices |
57 | required in the construction of nearly all Catalyst applications. |
58 | |
59 | Although the primary target of the tutorial is users new to the Catalyst |
60 | framework, experienced users may wish to review specific sections (for |
61 | example, how to use DBIC for their model classes or how to add |
62 | authentication and authorization to an existing application). |
63 | |
64 | You can obtain the code for all the tutorial examples from the |
65 | catalyst subversion repository by issuing the command: |
66 | |
67 | svn co http://dev.catalyst.perl.org/repos/Catalyst/tags/examples/Tutorial/MyApp/5.7/ CatalystTutorial |
68 | |
69 | This will download the current code for each tutorial chapter in the |
70 | CatalystTutorial directory. Each example application directory has |
71 | the same name as the tutorial chapter. |
72 | |
3d9ae335 |
73 | B<These reference implementations are provided so that when you follow |
74 | the tutorial, you can use the code from the subversion repository to |
75 | ensure that your system is set up correctly, and that you have not |
76 | inadvertently made any typographic errors, or accidentally skipped |
77 | part of the tutorial.> |
78 | |
d442cc9f |
79 | Additionally, if you're reading this manual online, you can download |
3dcf2e2c |
80 | the example program and all the necessary dependencies to |
d442cc9f |
81 | your local machine by installing the C<Task::Catalyst::Tutorial> |
82 | distribution from CPAN: |
83 | |
84 | cpan Task::Catalyst::Tutorial |
85 | |
86 | This will also test to make sure the dependencies are working. If you |
87 | have trouble installing these, please ask for help on the #catalyst |
88 | IRC channel, or the Catalyst mailing list. |
89 | |
90 | Subjects covered include: |
91 | |
92 | =over 4 |
93 | |
94 | =item * |
95 | |
96 | A simple application that lists and adds books. |
97 | |
98 | =item * |
99 | |
100 | The use of L<DBIx::Class|DBIx::Class> (DBIC) for the model. |
101 | |
102 | =item * |
103 | |
104 | How to write CRUD (Create, Read, Update, and Delete) operations in |
105 | Catalyst. |
106 | |
107 | =item * |
108 | |
109 | Authentication ("auth"). |
110 | |
111 | =item * |
112 | |
113 | Role-based authorization ("authz"). |
114 | |
115 | =item * |
116 | |
117 | Attempts to provide an example showing current (5.7XXX) Catalyst |
118 | practices. For example, the use of |
119 | L<Catalyst::Action::RenderView|Catalyst::Action::RenderView>, |
120 | DBIC, L<Catalyst::Plugin::ConfigLoader|Catalyst::Plugin::ConfigLoader> |
121 | with C<myapp.yml>, the use of C<lib/MyApp/Controller/Root.pm> |
122 | vs. C<lib/MyApp.pm>, etc. |
123 | |
124 | =item * |
125 | |
126 | The use of Template Toolkit (TT) and the |
127 | L<Catalyst::Helper::View::TTSite|Catalyst::Helper::View::TTSite> |
128 | view helper. |
129 | |
130 | =item * |
131 | |
132 | Useful techniques for troubleshooting and debugging Catalyst |
133 | applications. |
134 | |
135 | =item * |
136 | |
137 | The use of SQLite as a database (with code also provided for MySQL and |
138 | PostgreSQL). |
139 | |
140 | =item * |
141 | |
142 | The use of L<HTML::Widget|HTML::Widget> for automated form processing |
143 | and validation. |
144 | |
145 | =back |
146 | |
147 | This tutorial makes the learning process its main priority. For |
148 | example, the level of comments in the code found here would likely be |
149 | considered excessive in a "normal project". Because of their contextual |
150 | value, this tutorial will generally favor inline comments over a |
151 | separate discussion in the text. It also deliberately tries to |
152 | demonstrate multiple approaches to various features (in general, you |
153 | should try to be as consistent as possible with your own production |
154 | code). |
155 | |
156 | Furthermore, this tutorial tries to minimize the number of controllers, |
157 | models, TT templates, and database tables. Although this does result in |
158 | things being a bit contrived at times, the concepts should be applicable |
159 | to more complex environments. More complete and complicated example |
160 | applications can be found in the C<examples> area of the Catalyst |
161 | Subversion repository at |
162 | L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/>. |
163 | |
164 | B<Note:> There are a variety of other introductory materials available |
165 | through the Catalyst web site and at |
166 | L<http://dev.catalyst.perl.org/wiki/UserIntroductions> and |
167 | L<http://dev.catalyst.perl.org/>. |
168 | |
169 | =head1 VERSIONS AND CONVENTIONS USED IN THIS TUTORIAL |
170 | |
171 | This tutorial was built using the following resources. Please note that |
172 | you may need to make adjustments for different environments and |
173 | versions: |
174 | |
175 | =over 4 |
176 | |
177 | =item * |
178 | |
179 | OS = CentOS 4 Linux (RHEL 4) |
180 | |
181 | =item * |
182 | |
dd88c3b6 |
183 | Catalyst v5.7 |
184 | |
185 | = item * |
186 | |
187 | Catalyst::Devel v1.02 |
d442cc9f |
188 | |
189 | =item * |
190 | |
191 | DBIx::Class v0.06003 |
192 | |
193 | =item * |
194 | |
195 | Catalyst Plugins |
196 | |
197 | The plugins used in this tutorial all have sufficiently stable APIs that |
198 | you shouldn't need to worry about versions. However, there could be |
199 | cases where the tutorial is affected by what version of plugins you |
200 | use. This tutorial has been tested against the following set of plugins: |
201 | |
202 | =over 4 |
203 | |
204 | =item * |
205 | |
206 | Catalyst::Plugin::Authentication -- 0.09 |
207 | |
208 | =item * |
209 | |
210 | Catalyst::Plugin::Authentication::Store::DBIC -- 0.07 |
211 | |
212 | =item * |
213 | |
214 | Catalyst::Plugin::Authorization::ACL -- 0.08 |
215 | |
216 | =item * |
217 | |
218 | Catalyst::Plugin::Authorization::Roles -- 0.04 |
219 | |
220 | =item * |
221 | |
222 | Catalyst::Plugin::ConfigLoader -- 0.13 |
223 | |
224 | =item * |
225 | |
226 | Catalyst::Plugin::HTML::Widget -- 1.1 |
227 | |
228 | =item * |
229 | |
230 | Catalyst::Plugin::Session -- 0.12 |
231 | |
232 | =item * |
233 | |
234 | Catalyst::Plugin::Session::State::Cookie -- 0.05 |
235 | |
236 | =item * |
237 | |
238 | Catalyst::Plugin::Session::Store::FastMmap -- 0.02 |
239 | |
240 | =item * |
241 | |
242 | Catalyst::Plugin::StackTrace -- 0.06 |
243 | |
244 | =item * |
245 | |
246 | Catalyst::Plugin::Static::Simple -- 0.14 |
247 | |
248 | =back |
249 | |
250 | =item * |
251 | |
252 | Since the web browser is being used on the same box where Perl and the |
253 | Catalyst development server is running, the URL of |
254 | C<http://localhost:3000> will be used (the Catalyst development server |
255 | defaults to port 3000). If you are running Perl on a different box than |
256 | where your web browser is located (or using a different port number via |
257 | the C<-p> I<port_number> option to the development server), then you |
258 | will need to update the URL you use accordingly. |
259 | |
260 | =item * |
261 | |
262 | Depending on the web browser you are using, you might need to hit |
263 | C<Shift+Reload> to pull a fresh page when testing your application at |
264 | various points. Also, the C<-k> keepalive option to the development |
265 | server can be necessary with some browsers (especially Internet |
266 | Explorer). |
267 | |
268 | =back |
269 | |
270 | =head1 CATALYST INSTALLATION |
271 | |
272 | Unfortunately, one of the most daunting tasks faced by newcomers to |
273 | Catalyst is getting it installed. Although a compelling strength of |
274 | Catalyst is that it can easily make use of many of the modules in the |
275 | vast repository that is CPAN, this can result in initial installations |
276 | that are both time consuming and frustrating. However, there are a |
277 | growing number of methods that can dramatically ease this undertaking. |
278 | Of these, the following are likely to be applicable to the largest |
279 | number of potential new users: |
280 | |
281 | =over 4 |
282 | |
283 | =item * |
284 | |
285 | Matt Trout's C<cat-install> |
286 | |
287 | Available at L<http://www.shadowcatsystems.co.uk/static/cat-install>, |
288 | C<cat-install> can be a quick and painless way to get Catalyst up and |
289 | running. Just download the script from the link above and type C<perl |
290 | cat-install>. |
291 | |
292 | =item * |
293 | |
294 | Chris Laco's CatInABox |
295 | |
296 | Download the tarball from |
297 | L<http://handelframework.com/downloads/CatInABox.tar.gz> and unpack it |
298 | on your machine. Depending on your OS platform, either run C<start.bat> |
299 | or C<start.sh>. |
300 | |
301 | =item * |
302 | |
303 | Pre-Built VMWare Images |
304 | |
305 | Under the VMWare community program, work is ongoing to develop a number |
306 | of VMWare images where an entire Catalyst development environment has |
307 | already been installed, complete with database engines and a full |
308 | complement of Catalyst plugins. |
309 | |
310 | =back |
311 | |
312 | For additional information and recommendations on Catalyst installation, |
313 | please refer to |
314 | L<Catalyst::Manual::Installation|Catalyst::Manual::Installation>. |
315 | |
316 | B<NOTE:> Step-by-step instructions to replicate the environment on |
317 | which this tutorial was developed can be found at |
318 | L<Catalyst::Manual::Installation::CentOS4|Catalyst::Manual::Installation::CentOS4>. |
319 | Using these instructions, you should be able to build a complete CentOS |
320 | 4.X server with Catalyst and all the plugins required to run this |
321 | tutorial. |
322 | |
323 | =head1 DATABASES |
324 | |
325 | This tutorial will primarily focus on SQLite because of its simplicity |
326 | of installation and use; however, modifications in the script required |
327 | to support MySQL and PostgreSQL will be presented in Appendix 2. |
328 | |
329 | B<Note:> One of the advantages of the MVC design patterns is that |
330 | applications become much more database independent. As such, you will |
331 | notice that only the C<.sql> files used to initialize the database |
332 | change between database systems: the Catalyst code generally remains the |
333 | same. |
334 | |
335 | =head1 WHERE TO GET WORKING CODE |
336 | |
337 | Each part of the tutorial has complete code available in the main |
338 | Catalyst Subversion repository (see the note at the beginning of each |
339 | part for the appropriate svn command to use). Additionally, the final |
340 | code is available as a ready-to-run tarball at |
341 | L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/Tutorial/Final_Tarball/MyApp.tgz>. |
342 | |
343 | B<NOTE:> You can run the test cases for the final code with the following |
344 | commands: |
345 | |
346 | wget http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/Tutorial/Final_Tarball/MyApp.tgz |
347 | tar zxvf MyApp.tgz |
348 | cd MyApp |
349 | CATALYST_DEBUG=0 prove --lib lib t |
350 | |
351 | |
352 | =head1 AUTHOR |
353 | |
354 | Kennedy Clark, C<hkclark@gmail.com> |
355 | |
356 | Please report any errors, issues or suggestions to the author. The |
357 | most recent version of the Catalyst Tutorial can be found at |
d712b826 |
358 | L<http://dev.catalyst.perl.org/repos/Catalyst/trunk/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/>. |
d442cc9f |
359 | |
360 | Copyright 2006, Kennedy Clark, under Creative Commons License |
361 | (L<http://creativecommons.org/licenses/by-nc-sa/2.5/>). |
362 | |
363 | |