X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FManual%2FIntro.pod;h=9f39c49baa5decfd4ff6c915472a64e3526df450;hb=75c0ec035b7fdca765a41974a7970bf170b273d0;hp=5410cd1eea208c7e8758556946a199d6f90e2c49;hpb=d4ef4999c556cf3b3a6317eb51d6c9b435d39a0a;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Manual/Intro.pod b/lib/Catalyst/Manual/Intro.pod index 5410cd1..9f39c49 100644 --- a/lib/Catalyst/Manual/Intro.pod +++ b/lib/Catalyst/Manual/Intro.pod @@ -8,12 +8,22 @@ This is a brief introduction to Catalyst. It explains the most important features of how Catalyst works and shows how to get a simple application up and running quickly. For an introduction (without code) to Catalyst itself, and why you should be using it, see L. +For a systematic step-by-step introduction to writing an application +with Catalyst, see L. =head2 What is Catalyst? Catalyst is an elegant web application framework, extremely flexible yet extremely simple. It's similar to Ruby on Rails, Spring (Java), and -L, upon which it was originally based. +L, upon which it was originally based. Its most important +design philosphy is to provide easy access to all the tools you need to +develop web applications, with few restrictions on how you need to use +these tools. Under Catalyst, it is always possible to do things in a +different way. However, this does mean that it is always possible to do +things in a different way. Other web frameworks are simpler to use and +easy to get up and running, but achieve this by locking the programmer +into a single set of tools. Catalyst's emphasis on flexibility means +that you have to think more to use it. We view this as a feature. =head3 MVC @@ -24,15 +34,15 @@ modify code that handles one concern without affecting code that handles the others. Catalyst promotes the re-use of existing Perl modules that already handle common web application concerns well. -Here's how the M, V, and C map to those concerns, with examples of -well-known Perl modules you may want to use for each. +Here's how the Model, View, and Controller map to those concerns, with +examples of well-known Perl modules you may want to use for each. =over 4 =item * B Access and modify content (data). L, L, -L, L... +L, L... =item * B @@ -54,9 +64,8 @@ is becoming a popular design method for web applications. =head3 Flexibility -Catalyst is much more flexible than many other frameworks. We'll talk -more about this later, but rest assured you can use your favorite Perl -modules with Catalyst. +Catalyst is much more flexible than many other frameworks. Rest assured +you can use your favorite Perl modules with Catalyst. =over 4 @@ -94,9 +103,10 @@ example: Now http://localhost:3000/hello prints "Hello World!". -=item * B +=item * B -Use L or L. +Use L or L. Other +engines are also available. =back @@ -134,7 +144,8 @@ framework, making it easy to test applications from the command line. =item * B Catalyst provides helper scripts to quickly generate running starter -code for components and unit tests. See L. +code for components and unit tests. Install L and see +L. =back @@ -145,7 +156,14 @@ running, using the helper scripts described above. =head3 Install - $ perl -MCPAN -e 'install Task::Catalyst' +Installation of Catalyst can be a time-consuming and frustrating +effort, due to its large number of dependencies. The easiest way +to get up and running is to use Matt Trout's C +script, from L, +and then install L. + + # perl cat-install + # perl -MCPAN -e 'install Catalyst::Devel' =head3 Setup @@ -173,13 +191,349 @@ Both of these URLs should take you to the welcome page.) =back -Easy! - =head2 How It Works Let's see how Catalyst works, by taking a closer look at the components and other parts of a Catalyst application. +=head3 Components + +Catalyst has an uncommonly flexible component system. You can define as +many L, L, and L as you like. As discussed +previously, the general idea is that the View is responsible for the +output of data to the user (typically via a web browser, but a View can +also generate PDFs or e-mails, for example); the Model is responsible +for providing data (typically from a relational database); and the +Controller is responsible for interacting with the user and deciding +how user input determines what actions the application takes. + +In the world of MVC, there are frequent discussions and disagreements +about the nature of each element - whether certain types of logic +belong in the Model or the Controller, etc. Catalyst's flexibility +means that this decision is entirely up to you, the programmer; +Catalyst doesn't enforce anything. See L for +a general discussion of these concerns. + +All components must inherit from L, which provides a +simple class structure and some common class methods like C and +C (constructor). + + package MyApp::Controller::Catalog; + + use strict; + use base 'Catalyst::Base'; + + __PACKAGE__->config( foo => 'bar' ); + + 1; + +You don't have to C or otherwise register Models, Views, and +Controllers. Catalyst automatically discovers and instantiates them +when you call C in the main application. All you need to do is +put them in directories named for each Component type. You can use a +short alias for each one. + +=over 4 + +=item * B + +=item * B + +=item * B + +=item * B + +=item * B + +=item * B + +=back + +In older versions of Catalyst, the recommended practice (and the one +automatically created by helper scripts) was to name the directories +C, C, and C. Though these still work, we now recommend +the use of the full names. + +=head4 Views + +To show how to define views, we'll use an already-existing base class for the +L