fix pod link (RT#80361)
[catagits/Catalyst-Manual.git] / lib / Catalyst / Manual / Intro.pod
CommitLineData
11876a3b 1=head1 NAME
cb93c9d7 2
3Catalyst::Manual::Intro - Introduction to Catalyst
4
5=head1 DESCRIPTION
6
7This is a brief introduction to Catalyst. It explains the most important
8features of how Catalyst works and shows how to get a simple application
9up and running quickly. For an introduction (without code) to Catalyst
10itself, and why you should be using it, see L<Catalyst::Manual::About>.
11For a systematic step-by-step introduction to writing an application
12with Catalyst, see L<Catalyst::Manual::Tutorial>.
13
14=head2 What is Catalyst?
15
16Catalyst is an elegant web application framework, extremely flexible
792ad331 17yet extremely simple. It's similar to Ruby on Rails, Spring (Java), and
18L<Maypole|Maypole>, upon which it was originally based. Its most
5336f546 19important design philosophy is to provide easy access to all the tools
792ad331 20you need to develop web applications, with few restrictions on how you
21need to use these tools. However, this does mean that it is always
22possible to do things in a different way. Other web frameworks are
23I<initially> simpler to use, but achieve this by locking the programmer
24into a single set of tools. Catalyst's emphasis on flexibility means
25that you have to think more to use it. We view this as a feature. For
f577e42d 26example, this leads to Catalyst being better suited to system integration
792ad331 27tasks than other web frameworks.
cb93c9d7 28
29=head3 MVC
30
31Catalyst follows the Model-View-Controller (MVC) design pattern,
32allowing you to easily separate concerns, like content, presentation,
33and flow control, into separate modules. This separation allows you to
34modify code that handles one concern without affecting code that handles
35the others. Catalyst promotes the re-use of existing Perl modules that
36already handle common web application concerns well.
37
38Here's how the Model, View, and Controller map to those concerns, with
39examples of well-known Perl modules you may want to use for each.
40
41=over 4
42
43=item * B<Model>
44
45Access and modify content (data). L<DBIx::Class>, L<Class::DBI>,
46L<Xapian>, L<Net::LDAP>...
47
48=item * B<View>
49
50Present content to the user. L<Template Toolkit|Template>,
51L<Mason|HTML::Mason>, L<HTML::Template>...
52
53=item * B<Controller>
54
55Control the whole request phase, check parameters, dispatch actions, flow
f577e42d 56control. This is the meat of where Catalyst works.
cb93c9d7 57
58=back
59
60If you're unfamiliar with MVC and design patterns, you may want to
61check out the original book on the subject, I<Design Patterns>, by
62Gamma, Helm, Johnson, and Vlissides, also known as the Gang of Four
63(GoF). Many, many web application frameworks are based on MVC, which
64is becoming a popular design paradigm for the world wide web.
65
66=head3 Flexibility
67
68Catalyst is much more flexible than many other frameworks. Rest assured
69you can use your favorite Perl modules with Catalyst.
70
71=over 4
72
73=item * B<Multiple Models, Views, and Controllers>
74
75To build a Catalyst application, you handle each type of concern inside
76special modules called L</Components>. Often this code will be very
77simple, just calling out to Perl modules like those listed above under
78L</MVC>. Catalyst handles these components in a very flexible way. Use
79as many Models, Views, and Controllers as you like, using as many
80different Perl modules as you like, all in the same application. Want to
81manipulate multiple databases, and retrieve some data via LDAP? No
82problem. Want to present data from the same Model using L<Template
83Toolkit|Template> and L<PDF::Template>? Easy.
84
85=item * B<Reuseable Components>
86
87Not only does Catalyst promote the re-use of already existing Perl
88modules, it also allows you to re-use your Catalyst components in
89multiple Catalyst applications.
90
91=item * B<Unrestrained URL-to-Action Dispatching>
92
93Catalyst allows you to dispatch any URLs to any application L</Actions>,
94even through regular expressions! Unlike most other frameworks, it
95doesn't require mod_rewrite or class and method names in URLs.
96
97With Catalyst you register your actions and address them directly. For
98example:
99
a8df13c3 100 sub hello : Local {
cb93c9d7 101 my ( $self, $context ) = @_;
102 $context->response->body('Hello World!');
103 }
104
105Now http://localhost:3000/hello prints "Hello World!".
106
1b2f9849 107Note that actions with the C< :Local > attribute are equivalent to
a8df13c3 108using a C<:Path('action_name') > attribute, so our action could be
109equivalently:
4299d9f5 110
a8df13c3 111 sub hi : Path('hello') {
4299d9f5 112 my ( $self, $context ) = @_;
113 $context->response->body('Hello World!');
114 }
115
116
cb93c9d7 117=item * B<Support for CGI, mod_perl, Apache::Request, FastCGI>
118
492f2dd5 119Use L<Catalyst::Engine::Apache> or L<Catalyst::Engine::CGI>. Another
120interesting engine is L<Catalyst::Engine::HTTP::Prefork> - available from CPAN
121separately - which will turn the built server into a fully fledged production
122ready server (although you'll probably want to run it behind a front end proxy
123if you end up using it).
cb93c9d7 124
eb09ba22 125=item * PSGI Support
126
127Starting with Catalyst version 5.9 Catalyst ships with L<PSGI> integration
128for even more powerful and flexible testing and deployment options. See
129L<Catalyst::PSGI> for details.
130
8e728a18 131=back
132
cb93c9d7 133=head3 Simplicity
134
135The best part is that Catalyst implements all this flexibility in a very
136simple way.
137
138=over 4
139
140=item * B<Building Block Interface>
141
142Components interoperate very smoothly. For example, Catalyst
143automatically makes a L</Context> object available to every
144component. Via the context, you can access the request object, share
145data between components, and control the flow of your
146application. Building a Catalyst application feels a lot like snapping
147together toy building blocks, and everything just works.
148
149=item * B<Component Auto-Discovery>
150
151No need to C<use> all of your components. Catalyst automatically finds
152and loads them.
153
154=item * B<Pre-Built Components for Popular Modules>
155
156See L<Catalyst::Model::DBIC::Schema> for L<DBIx::Class>, or
157L<Catalyst::View::TT> for L<Template Toolkit|Template>.
158
159=item * B<Built-in Test Framework>
160
161Catalyst comes with a built-in, lightweight http server and test
162framework, making it easy to test applications from the web browser,
163and the command line.
164
165=item * B<Helper Scripts>
166
167Catalyst provides helper scripts to quickly generate running starter
168code for components and unit tests. Install L<Catalyst::Devel> and see
169L<Catalyst::Helper>.
170
171=back
172
173=head2 Quickstart
174
175Here's how to install Catalyst and get a simple application up and
176running, using the helper scripts described above.
177
178=head3 Install
179
b1a08fe1 180Installation of Catalyst should be straightforward:
181
182 # perl -MCPAN -e 'install Catalyst::Runtime'
cb93c9d7 183 # perl -MCPAN -e 'install Catalyst::Devel'
184
185=head3 Setup
186
187 $ catalyst.pl MyApp
188 # output omitted
189 $ cd MyApp
190 $ script/myapp_create.pl controller Library::Login
191
0c51850e 192=head4 Frank Speiser's Amazon EC2 Catalyst SDK
193
194There are currently two flavors of publicly available Amazon Machine
195Images (AMI) that include all the elements you'd need to begin
196developing in a fully functional Catalyst environment within
197minutes. See
198L<Catalyst::Manual::Installation|Catalyst::Manual::Installation> for
199more details.
200
201
cb93c9d7 202=head3 Run
203
204 $ script/myapp_server.pl
205
206Now visit these locations with your favorite browser or user agent to see
207Catalyst in action:
208
209(NOTE: Although we create a controller here, we don't actually use it.
210Both of these URLs should take you to the welcome page.)
211
212
213=over 4
214
215=item http://localhost:3000/
216
217=item http://localhost:3000/library/login/
218
219=back
220
221=head2 How It Works
222
223Let's see how Catalyst works, by taking a closer look at the components
224and other parts of a Catalyst application.
225
226=head3 Components
227
228Catalyst has an uncommonly flexible component system. You can define as
229many L</Models>, L</Views>, and L</Controllers> as you like. As discussed
230previously, the general idea is that the View is responsible for the
231output of data to the user (typically via a web browser, but a View can
b1a08fe1 232also generate PDFs or e-mails, for example); the Model is responsible
cb93c9d7 233for providing data (typically from a relational database); and the
234Controller is responsible for interacting with the user and deciding
235how user input determines what actions the application takes.
236
237In the world of MVC, there are frequent discussions and disagreements
238about the nature of each element - whether certain types of logic
239belong in the Model or the Controller, etc. Catalyst's flexibility
b1a08fe1 240means that this decision is entirely up to you, the programmer;
cb93c9d7 241Catalyst doesn't enforce anything. See L<Catalyst::Manual::About> for
242a general discussion of these issues.
243
b2aea8fe 244Model, View and Controller components must inherit from L<Catalyst::Model>,
47a79274 245L<Catalyst::View> and L<Catalyst::Controller>, respectively. These, in turn, inherit
b2aea8fe 246from L<Catalyst::Component> which provides a simple class structure and some
247common class methods like C<config> and C<new> (constructor).
cb93c9d7 248
249 package MyApp::Controller::Catalog;
b1a08fe1 250 use Moose;
251 use namespace::autoclean;
cb93c9d7 252
b1a08fe1 253 BEGIN { extends 'Catalyst::Controller' }
cb93c9d7 254
255 __PACKAGE__->config( foo => 'bar' );
256
257 1;
258
259You don't have to C<use> or otherwise register Models, Views, and
260Controllers. Catalyst automatically discovers and instantiates them
261when you call C<setup> in the main application. All you need to do is
262put them in directories named for each Component type. You can use a
263short alias for each one.
264
265=over 4
266
b1a08fe1 267=item * B<MyApp/Model/>
cb93c9d7 268
cb93c9d7 269=item * B<MyApp/View/>
270
cb93c9d7 271=item * B<MyApp/Controller/>
272
cb93c9d7 273=back
274
cb93c9d7 275=head4 Views
276
277To show how to define views, we'll use an already-existing base class for the
278L<Template Toolkit|Template>, L<Catalyst::View::TT>. All we need to do is
279inherit from this class:
280
281 package MyApp::View::TT;
282
283 use strict;
284 use base 'Catalyst::View::TT';
285
286 1;
287
288(You can also generate this automatically by using the helper script:
289
290 script/myapp_create.pl view TT TT
291
292where the first C<TT> tells the script that the name of the view should
293be C<TT>, and the second that it should be a Template Toolkit view.)
294
295This gives us a process() method and we can now just do
296$c->forward('MyApp::View::TT') to render our templates. The base class
297makes process() implicit, so we don't have to say
298C<$c-E<gt>forward(qw/MyApp::View::TT process/)>.
299
300 sub hello : Global {
301 my ( $self, $c ) = @_;
302 $c->stash->{template} = 'hello.tt';
303 }
304
305 sub end : Private {
306 my ( $self, $c ) = @_;
307 $c->forward( $c->view('TT') );
308 }
309
310You normally render templates at the end of a request, so it's a perfect
311use for the global C<end> action.
312
313In practice, however, you would use a default C<end> action as supplied
314by L<Catalyst::Action::RenderView>.
315
316Also, be sure to put the template under the directory specified in
317C<$c-E<gt>config-E<gt>{root}>, or you'll end up looking at the debug
318screen.
319
320=head4 Models
321
322Models are providers of data. This data could come from anywhere - a
323search engine index, a spreadsheet, the file system - but typically a
324Model represents a database table. The data source does not
325intrinsically have much to do with web applications or Catalyst - it
326could just as easily be used to write an offline report generator or a
327command-line tool.
328
329To show how to define models, again we'll use an already-existing base
330class, this time for L<DBIx::Class>: L<Catalyst::Model::DBIC::Schema>.
331We'll also need L<DBIx::Class::Schema::Loader>.
332
333But first, we need a database.
334
335 -- myapp.sql
336 CREATE TABLE foo (
337 id INTEGER PRIMARY KEY,
338 data TEXT
339 );
340
341 CREATE TABLE bar (
342 id INTEGER PRIMARY KEY,
343 foo INTEGER REFERENCES foo,
344 data TEXT
345 );
346
347 INSERT INTO foo (data) VALUES ('TEST!');
348
9d49ae04 349 % sqlite3 /tmp/myapp.db < myapp.sql
cb93c9d7 350
351Now we can create a DBIC::Schema model for this database.
352
353 script/myapp_create.pl model MyModel DBIC::Schema MySchema create=static 'dbi:SQLite:/tmp/myapp.db'
354
54550e13 355L<DBIx::Class::Schema::Loader> can automatically load table layouts and
4299d9f5 356relationships, and convert them into a static schema definition
357C<MySchema>, which you can edit later.
cb93c9d7 358
359Use the stash to pass data to your templates.
360
361We add the following to MyApp/Controller/Root.pm
362
363 sub view : Global {
364 my ( $self, $c, $id ) = @_;
b1a08fe1 365
cb93c9d7 366 $c->stash->{item} = $c->model('MyModel::Foo')->find($id);
367 }
368
369 1;
b1a08fe1 370
cb93c9d7 371 sub end : Private {
372 my ( $self, $c ) = @_;
b1a08fe1 373
cb93c9d7 374 $c->stash->{template} ||= 'index.tt';
375 $c->forward( $c->view('TT') );
376 }
377
378We then create a new template file "root/index.tt" containing:
379
380 The Id's data is [% item.data %]
381
382Models do not have to be part of your Catalyst application; you
383can always call an outside module that serves as your Model:
384
385 # in a Controller
386 sub list : Local {
387 my ( $self, $c ) = @_;
b1a08fe1 388
cb93c9d7 389 $c->stash->{template} = 'list.tt';
b1a08fe1 390
cb93c9d7 391 use Some::Outside::Database::Module;
392 my @records = Some::Outside::Database::Module->search({
393 artist => 'Led Zeppelin',
394 });
b1a08fe1 395
cb93c9d7 396 $c->stash->{records} = \@records;
397 }
398
399But by using a Model that is part of your Catalyst application, you
400gain several things: you don't have to C<use> each component, Catalyst
401will find and load it automatically at compile-time; you can
402C<forward> to the module, which can only be done to Catalyst
403components. Only Catalyst components can be fetched with
404C<$c-E<gt>model('SomeModel')>.
405
406Happily, since many people have existing Model classes that they
407would like to use with Catalyst (or, conversely, they want to
408write Catalyst models that can be used outside of Catalyst, e.g.
409in a cron job), it's trivial to write a simple component in
410Catalyst that slurps in an outside Model:
411
412 package MyApp::Model::DB;
413 use base qw/Catalyst::Model::DBIC::Schema/;
414 __PACKAGE__->config(
415 schema_class => 'Some::DBIC::Schema',
416 connect_info => ['dbi:SQLite:foo.db', '', '', {AutoCommit=>1}]
417 );
418 1;
419
420and that's it! Now C<Some::DBIC::Schema> is part of your
421Cat app as C<MyApp::Model::DB>.
422
423Within Catalyst, the common approach to writing a model for your
424application is wrapping a generic model (e.g. L<DBIx::Class::Schema>, a
425bunch of XMLs, or anything really) with an object that contains
426configuration data, convenience methods, and so forth. Thus you
427will in effect have two models - a wrapper model that knows something
428about Catalyst and your web application, and a generic model that is
429totally independent of these needs.
430
431Technically, within Catalyst a model is a B<component> - an instance of
432the model's class belonging to the application. It is important to
433stress that the lifetime of these objects is per application, not per
434request.
435
436While the model base class (L<Catalyst::Model>) provides things like
437C<config> to better integrate the model into the application, sometimes
438this is not enough, and the model requires access to C<$c> itself.
439
440Situations where this need might arise include:
441
442=over 4
443
444=item *
445
446Interacting with another model
447
448=item *
449
450Using per-request data to control behavior
451
452=item *
453
454Using plugins from a Model (for example L<Catalyst::Plugin::Cache>).
455
456=back
457
458From a style perspective it's usually considered bad form to make your
459model "too smart" about things - it should worry about business logic
460and leave the integration details to the controllers. If, however, you
5336f546 461find that it does not make sense at all to use an auxiliary controller
cb93c9d7 462around the model, and the model's need to access C<$c> cannot be
463sidestepped, there exists a power tool called L</ACCEPT_CONTEXT>.
464
465=head4 Controllers
466
467Multiple controllers are a good way to separate logical domains of your
468application.
469
470 package MyApp::Controller::Login;
471
472 use base qw/Catalyst::Controller/;
473
be3349e1 474 sub sign_in : Path("sign-in") { }
cb93c9d7 475 sub new_password : Path("new-password") { }
be3349e1 476 sub sign_out : Path("sign-out") { }
cb93c9d7 477
478 package MyApp::Controller::Catalog;
479
480 use base qw/Catalyst::Controller/;
481
482 sub view : Local { }
483 sub list : Local { }
484
485 package MyApp::Controller::Cart;
486
487 use base qw/Catalyst::Controller/;
488
489 sub add : Local { }
490 sub update : Local { }
491 sub order : Local { }
492
493Note that you can also supply attributes via the Controller's config so
494long as you have at least one attribute on a subref to be exported
495(:Action is commonly used for this) - for example the following is
496equivalent to the same controller above:
497
498 package MyApp::Controller::Login;
499
500 use base qw/Catalyst::Controller/;
501
502 __PACKAGE__->config(
503 actions => {
504 'sign_in' => { Path => 'sign-in' },
505 'new_password' => { Path => 'new-password' },
506 'sign_out' => { Path => 'sign-out' },
507 },
508 );
509
510 sub sign_in : Action { }
511 sub new_password : Action { }
512 sub sign_out : Action { }
513
514=head3 ACCEPT_CONTEXT
515
516Whenever you call $c->component("Foo") you get back an object - the
517instance of the model. If the component supports the C<ACCEPT_CONTEXT>
518method instead of returning the model itself, the return value of C<<
519$model->ACCEPT_CONTEXT( $c ) >> will be used.
520
0cc6ab50 521This means that whenever your model/view/controller needs to talk to
522C<$c> it gets a chance to do this when it's needed.
cb93c9d7 523
524A typical C<ACCEPT_CONTEXT> method will either clone the model and return one
525with the context object set, or it will return a thin wrapper that contains
526C<$c> and delegates to the per-application model object.
527
0cc6ab50 528Generally it's a bad idea to expose the context object (C<$c>) in your
529model or view code. Instead you use the C<ACCEPT_CONTEXT> subroutine
530to grab the bits of the context object that you need, and provide
531accessors to them in the model. This ensures that C<$c> is only in
7fcc54f3 532scope where it is needed which reduces maintenance and debugging
0cc6ab50 533headaches. So, if for example you needed two
534L<Catalyst::Model::DBIC::Schema> models in the same Catalyst model
535code, you might do something like this:
536
537 __PACKAGE__->mk_accessors(qw(model1_schema model2_schema));
538 sub ACCEPT_CONTEXT {
539 my ( $self, $c, @extra_arguments ) = @_;
540 $self = bless({ %$self,
541 model1_schema => $c->model('Model1')->schema,
542 model2_schema => $c->model('Model2')->schema
543 }, ref($self));
544 return $self;
545 }
546
547This effectively treats $self as a B<prototype object> that gets a new
548parameter. C<@extra_arguments> comes from any trailing arguments to
549C<< $c->component( $bah, @extra_arguments ) >> (or C<< $c->model(...)
550>>, C<< $c->view(...) >> etc).
551
552In a subroutine in the model code, we can then do this:
553
554 sub whatever {
555 my ($self) = @_;
556 my $schema1 = $self->model1_schema;
557 my $schema2 = $self->model2_schema;
558 ...
559 }
560
561Note that we still want the Catalyst models to be a thin wrapper
562around classes that will work independently of the Catalyst
563application to promote reusability of code. Here we might just want
564to grab the $c->model('DB')->schema so as to get the connection
565information from the Catalyst application's configuration for example.
566
567The life time of this value is B<per usage>, and not per request. To
568make this per request you can use the following technique:
cb93c9d7 569
570Add a field to C<$c>, like C<my_model_instance>. Then write your
571C<ACCEPT_CONTEXT> method to look like this:
572
573 sub ACCEPT_CONTEXT {
574 my ( $self, $c ) = @_;
575
576 if ( my $per_request = $c->my_model_instance ) {
577 return $per_request;
578 } else {
579 my $new_instance = bless { %$self, c => $c }, ref($self);
580 Scalar::Util::weaken($new_instance->{c}); # or we have a circular reference
581 $c->my_model_instance( $new_instance );
582 return $new_instance;
583 }
584 }
585
0cc6ab50 586For a similar technique to grab a new component instance on each
587request, see L<Catalyst::Component::InstancePerContext>.
588
cb93c9d7 589=head3 Application Class
590
591In addition to the Model, View, and Controller components, there's a
592single class that represents your application itself. This is where you
593configure your application, load plugins, and extend Catalyst.
594
595 package MyApp;
596
597 use strict;
ca7528df 598 use parent qw/Catalyst/;
b411df01 599 use Catalyst qw/-Debug ConfigLoader Static::Simple/;
cb93c9d7 600 MyApp->config(
601 name => 'My Application',
602
603 # You can put anything else you want in here:
604 my_configuration_variable => 'something',
605 );
606 1;
607
608In older versions of Catalyst, the application class was where you put
609global actions. However, as of version 5.66, the recommended practice is
610to place such actions in a special Root controller (see L</Actions>,
611below), to avoid namespace collisions.
612
613=over 4
614
615=item * B<name>
616
617The name of your application.
618
619=back
620
621Optionally, you can specify a B<root> parameter for templates and static
622data. If omitted, Catalyst will try to auto-detect the directory's
623location. You can define as many parameters as you want for plugins or
624whatever you need. You can access them anywhere in your application via
625C<$context-E<gt>config-E<gt>{$param_name}>.
626
627=head3 Context
628
629Catalyst automatically blesses a Context object into your application
630class and makes it available everywhere in your application. Use the
631Context to directly interact with Catalyst and glue your L</Components>
632together. For example, if you need to use the Context from within a
633Template Toolkit template, it's already there:
634
635 <h1>Welcome to [% c.config.name %]!</h1>
636
637As illustrated in our URL-to-Action dispatching example, the Context is
638always the second method parameter, behind the Component object
639reference or class name itself. Previously we called it C<$context> for
640clarity, but most Catalyst developers just call it C<$c>:
641
642 sub hello : Global {
643 my ( $self, $c ) = @_;
644 $c->res->body('Hello World!');
645 }
646
647The Context contains several important objects:
648
649=over 4
650
651=item * L<Catalyst::Request>
652
653 $c->request
654 $c->req # alias
655
656The request object contains all kinds of request-specific information, like
657query parameters, cookies, uploads, headers, and more.
658
659 $c->req->params->{foo};
660 $c->req->cookies->{sessionid};
661 $c->req->headers->content_type;
662 $c->req->base;
663 $c->req->uri_with( { page = $pager->next_page } );
664
665=item * L<Catalyst::Response>
666
667 $c->response
668 $c->res # alias
669
670The response is like the request, but contains just response-specific
671information.
672
673 $c->res->body('Hello World');
674 $c->res->status(404);
675 $c->res->redirect('http://oook.de');
676
709ea2fc 677=item * config
cb93c9d7 678
679 $c->config
680 $c->config->{root};
681 $c->config->{name};
682
683=item * L<Catalyst::Log>
684
685 $c->log
686 $c->log->debug('Something happened');
687 $c->log->info('Something you should know');
688
689=item * B<Stash>
690
691 $c->stash
692 $c->stash->{foo} = 'bar';
693 $c->stash->{baz} = {baz => 'qox'};
694 $c->stash->{fred} = [qw/wilma pebbles/];
695
696and so on.
697
698=back
699
700The last of these, the stash, is a universal hash for sharing data among
701application components. For an example, we return to our 'hello' action:
702
703 sub hello : Global {
704 my ( $self, $c ) = @_;
705 $c->stash->{message} = 'Hello World!';
706 $c->forward('show_message');
707 }
708
709 sub show_message : Private {
710 my ( $self, $c ) = @_;
711 $c->res->body( $c->stash->{message} );
712 }
713
714Note that the stash should be used only for passing data in an
715individual request cycle; it gets cleared at a new request. If you need
716to maintain persistent data, use a session. See
717L<Catalyst::Plugin::Session> for a comprehensive set of
718Catalyst-friendly session-handling tools.
719
720=head3 Actions
721
d6ea2bcb 722You've already seen some examples of actions in this document:
723subroutines with C<:Path> and C<:Local> attributes attached.
724Here, we explain what actions are and how these attributes affect
725what's happening.
726
727When Catalyst processes a webpage request, it looks for actions to
728take that will deal with the incoming request and produce a response
729such as a webpage. You create these actions for your application by
730writing subroutines within your controller and marking them with
731special attributes. The attributes, the namespace, and the function
732name determine when Catalyst will call the subroutine.
733
734These action subroutines call certain functions to say what response
735the webserver will give to the web request. They can also tell
736Catalyst to run other actions on the request (one example of this is
737called forwarding the request; this is discussed later).
738
739Action subroutines must have a special attribute on to show that they
740are actions - as well as marking when to call them, this shows that
741they take a specific set of arguments and behave in a specific way.
742At startup, Catalyst looks for all the actions in controllers,
743registers them and creates L<Catalyst::Action> objects describing
744them. When requests come in, Catalyst chooses which actions should be
745called to handle the request.
746
747(Occasionally, you might use the action objects directly, but in
748general, when we talk about actions, we're talking about the
749subroutines in your application that do things to process a request.)
750
751You can choose one of several attributes for action subroutines; these
752specify which requests are processed by that subroutine. Catalyst
753will look at the URL it is processing, and the actions that it has
754found, and automatically call the actions it finds that match the
755circumstances of the request.
756
caf6e9ce 757The URL (for example http://localhost:3000/foo/bar) consists of two
d6ea2bcb 758parts, the base, describing how to connect to the server
759(http://localhost:3000/ in this example) and the path, which the
760server uses to decide what to return (foo/bar). Please note that the
761trailing slash after the hostname[:port] always belongs to base and
762not to the path. Catalyst uses only the path part when trying to find
763actions to process.
764
765Depending on the type of action used, the URLs may match a combination
766of the controller namespace, the arguments passed to the action
767attribute, and the name of the subroutine.
cb93c9d7 768
769=over 4
770
d6ea2bcb 771=item * B<Controller namespaces>
772
773The namespace is a modified form of the component's class (package)
774name. This modified class name excludes the parts that have a
775pre-defined meaning in Catalyst ("MyApp::Controller" in the above
776example), replaces "::" with "/", and converts the name to lower case.
777See L</Components> for a full explanation of the pre-defined meaning
778of Catalyst component class names.
779
780=item * B<Overriding the namespace>
781
030e99c1 782Note that C<< __PACKAGE__->config->(namespace => ... ) >> can be used to override the
d6ea2bcb 783current namespace when matching. So:
784
785 package MyApp::Controller::Example;
786
787would normally use 'example' as its namespace for matching, but if
788this is specially overridden with
789
19a5b486 790 __PACKAGE__->config( namespace => 'thing' );
d6ea2bcb 791
792it matches using the namespace 'thing' instead.
793
cb93c9d7 794=item * B<Application Wide Actions>
795
d6ea2bcb 796MyApp::Controller::Root, as created by the catalyst.pl script, will
797typically contain actions which are called for the top level of the
798application (e.g. http://localhost:3000/ ):
cb93c9d7 799
800 package MyApp::Controller::Root;
801 use base 'Catalyst::Controller';
f577e42d 802
cb93c9d7 803 # Sets the actions in this controller to be registered with no prefix
804 # so they function identically to actions created in MyApp.pm
f577e42d 805
19a5b486 806 __PACKAGE__->config( namespace => '');
f577e42d 807
4299d9f5 808 sub default : Path {
cb93c9d7 809 my ( $self, $context ) = @_;
4299d9f5 810 $context->response->status(404);
811 $context->response->body('404 not found');
cb93c9d7 812 }
f577e42d 813
cb93c9d7 814 1;
815
d6ea2bcb 816
817The code
818
19a5b486 819 __PACKAGE__->config( namespace => '' );
d6ea2bcb 820
821makes the controller act as if its namespace is empty. As you'll see
f577e42d 822below, an empty namespace makes many of the URL-matching attributes, such
823as :Path and :Local match at the start of the URL path (i.e. the
824application root).
d6ea2bcb 825
cb93c9d7 826=back
827
828=head4 Action types
829
d6ea2bcb 830Catalyst supports several types of actions. These mainly correspond
831to ways of matching a URL to an action subroutine. Internally, these
832matching types are implemented by L<Catalyst::DispatchType>-derived
833classes; the documentation there can be helpful in seeing how they
834work.
835
836They will all attempt to match the start of the path. The remainder
837of the path is passed as arguments.
cb93c9d7 838
839=over 4
840
d6ea2bcb 841=item * Namespace-prefixed (C<:Local>)
842
b1a08fe1 843 package MyApp::Controller::My::Controller;
d6ea2bcb 844 sub foo : Local { }
845
846Matches any URL beginning with> http://localhost:3000/my/controller/foo. The namespace and
847subroutine name together determine the path.
848
0a52c718 849=item * Root-level (C<:Global>)
d6ea2bcb 850
851 package MyApp::Controller::Foo;
d6ea2bcb 852
f577e42d 853 sub bar : Global {
854 my ($self, $c) = @_;
855 $c->res->body(
856 $c->res->body('sub bar in Controller::Foo triggered on a request for '
857 . $c->req->uri));
858 }
d6ea2bcb 859
f577e42d 8601;
d6ea2bcb 861
498f110b 862Matches http://localhost:3000/bar - that is, the action is mapped
70101578 863directly to the method name, ignoring the controller namespace.
d6ea2bcb 864
f577e42d 865C<:Global> always matches from the application root: it is simply
5336f546 866shorthand for C<:Path('/methodname')>. C<:Local> is shorthand for
f577e42d 867C<:Path('methodname')>, which takes the controller namespace as described
868above.
869
870Usage of the C<Global> handler is rare in all but very old Catalyst
871applications (e.g. before Catalyst 5.7). The use cases where C<Global>
872used to make sense are now largely replaced by the C<Chained> dispatch
873type, or by empty C<Path> declarations on an controller action. C<Global>
874is still included in Catalyst for backwards compatibility, although
7c8f8c03 875legitimate use-cases for it may still exist.
d6ea2bcb 876
845ef405 877=item * Changing handler behaviour: eating arguments (C<:Args>)
d6ea2bcb 878
879Args is not an action type per se, but an action modifier - it adds a
880match restriction to any action it's provided to, additionally
881requiring as many path parts as are specified for the action to be
882matched. For example, in MyApp::Controller::Foo,
883
884 sub bar :Local
885
886would match any URL starting /foo/bar. To restrict this you can do
887
888 sub bar :Local :Args(1)
889
890to only match URLs starting /foo/bar/* - with one additional path
891element required after 'bar'.
892
b1a08fe1 893NOTE that adding C<:Args(0)> and missing out :Args completely are B<not>
845ef405 894the same thing.
895
b1a08fe1 896C<:Args(0)> means that no arguments are taken. Thus, the URL and path must
845ef405 897match precisely.
898
b1a08fe1 899No :Args at all means that B<any number> of arguments are taken. Thus, any
0a52c718 900URL that B<starts with> the controller's path will match. Obviously, this means
901you cannot chain from an action that does not specify args, as the next action
902in the chain will be swallowed as an arg to the first!
845ef405 903
904
d6ea2bcb 905=item * Literal match (C<:Path>)
906
907C<Path> actions match things starting with a precise specified path,
908and nothing else.
909
910C<Path> actions without a leading forward slash match a specified path
911relative to their current namespace. This example matches URLs
912starting http://localhost:3000/my/controller/foo/bar :
cb93c9d7 913
914 package MyApp::Controller::My::Controller;
915 sub bar : Path('foo/bar') { }
916
d6ea2bcb 917C<Path> actions B<with> a leading slash ignore their namespace, and
918match from the start of the URL path. Example:
cb93c9d7 919
920 package MyApp::Controller::My::Controller;
921 sub bar : Path('/foo/bar') { }
922
d6ea2bcb 923This matches URLs beginning http://localhost:3000/foo/bar.
924
925Empty C<Path> definitions match on the namespace only, exactly like
926C<:Global>.
cb93c9d7 927
928 package MyApp::Controller::My::Controller;
929 sub bar : Path { }
930
d6ea2bcb 931The above code matches http://localhost:3000/my/controller.
932
933Actions with the C<:Local> attribute are similarly equivalent to
934C<:Path('action_name')>:
cb93c9d7 935
b1a08fe1 936 sub foo : Local { }
cb93c9d7 937
b1a08fe1 938is equivalent to
d6ea2bcb 939
940 sub foo : Path('foo') { }
941
942=item * Pattern-match (C<:Regex> and C<:LocalRegex>)
b1a08fe1 943
d6ea2bcb 944 package MyApp::Controller::My::Controller;
cb93c9d7 945 sub bar : Regex('^item(\d+)/order(\d+)$') { }
946
d6ea2bcb 947This matches any URL that matches the pattern in the action key, e.g.
cb93c9d7 948http://localhost:3000/item23/order42. The '' around the regexp is
949optional, but perltidy likes it. :)
950
d6ea2bcb 951C<:Regex> matches act globally, i.e. without reference to the namespace
952from which they are called. So the above will B<not> match
953http://localhost:3000/my/controller/item23/order42 - use a
954C<:LocalRegex> action instead.
cb93c9d7 955
d6ea2bcb 956 package MyApp::Controller::My::Controller;
cb93c9d7 957 sub bar : LocalRegex('^widget(\d+)$') { }
958
d6ea2bcb 959C<:LocalRegex> actions act locally, i.e. the namespace is matched
960first. The above example would match urls like
961http://localhost:3000/my/controller/widget23.
cb93c9d7 962
d6ea2bcb 963If you omit the "C<^>" from either sort of regex, then it will match any depth
964from the base path:
cb93c9d7 965
966 package MyApp::Controller::Catalog;
967 sub bar : LocalRegex('widget(\d+)$') { }
968
d6ea2bcb 969This differs from the previous example in that it will match
970http://localhost:3000/my/controller/foo/widget23 - and a number of
971other paths.
cb93c9d7 972
d6ea2bcb 973For both C<:LocalRegex> and C<:Regex> actions, if you use capturing
974parentheses to extract values within the matching URL, those values
975are available in the C<$c-E<gt>req-E<gt>captures> array. In the above
976example, "widget23" would capture "23" in the above example, and
977C<$c-E<gt>req-E<gt>captures-E<gt>[0]> would be "23". If you want to
978pass arguments at the end of your URL, you must use regex action
979keys. See L</URL Path Handling> below.
cb93c9d7 980
d6ea2bcb 981=item * Chained handlers (C<:Chained>)
cb93c9d7 982
983Catalyst also provides a method to build and dispatch chains of actions,
984like
985
986 sub catalog : Chained : CaptureArgs(1) {
987 my ( $self, $c, $arg ) = @_;
988 ...
989 }
990
991 sub item : Chained('catalog') : Args(1) {
992 my ( $self, $c, $arg ) = @_;
993 ...
994 }
995
d6ea2bcb 996to handle a C</catalog/*/item/*> path. Matching actions are called
997one after another - C<catalog()> gets called and handed one path
998element, then C<item()> gets called with another one. For further
999information about this dispatch type, please see
1000L<Catalyst::DispatchType::Chained>.
cb93c9d7 1001
1002=item * B<Private>
1003
1004 sub foo : Private { }
1005
d6ea2bcb 1006This will never match a URL - it provides a private action which can
1007be called programmatically from within Catalyst, but is never called
1008automatically due to the URL being requested.
1009
1010Catalyst's C<:Private> attribute is exclusive and doesn't work with other
1011attributes (so will not work combined with C<:Path> or C<:Chained>
1012attributes, for instance).
1013
1014Private actions can only be executed explicitly from inside a Catalyst
1015application. You might do this in your controllers by calling
1016catalyst methods such as C<forward> or C<detach> to fire them:
cb93c9d7 1017
1018 $c->forward('foo');
09f13e1d 1019 # or
1020 $c->detach('foo');
cb93c9d7 1021
d6ea2bcb 1022See L</Flow Control> for a full explanation of how you can pass
1023requests on to other actions. Note that, as discussed there, when
1024forwarding from another component, you must use the absolute path to
1025the method, so that a private C<bar> method in your
1026C<MyApp::Controller::Catalog::Order::Process> controller must, if
1027called from elsewhere, be reached with
cb93c9d7 1028C<$c-E<gt>forward('/catalog/order/process/bar')>.
1029
cb93c9d7 1030=back
1031
d6ea2bcb 1032B<Note:> After seeing these examples, you probably wonder what the
1033point is of defining subroutine names for regex and path
1034actions. However, every public action is also a private one with a
1035path corresponding to its namespace and subroutine name, so you have
1036one unified way of addressing components in your C<forward>s.
1037
1038=head4 Built-in special actions
cb93c9d7 1039
d6ea2bcb 1040If present, the special actions C< index >, C< auto >, C<begin>,
1041C<end> and C< default > are called at certain points in the request
1042cycle.
cb93c9d7 1043
1044In response to specific application states, Catalyst will automatically
d6ea2bcb 1045call these built-in actions in your application class:
cb93c9d7 1046
1047=over 4
1048
4299d9f5 1049=item * B<default : Path>
cb93c9d7 1050
d6ea2bcb 1051This is called when no other action matches. It could be used, for
1052example, for displaying a generic frontpage for the main app, or an
1053error page for individual controllers. B<Note>: in older Catalyst
1054applications you will see C<default : Private> which is roughly
1055speaking equivalent.
cb93c9d7 1056
cb93c9d7 1057
4299d9f5 1058=item * B<index : Path : Args (0) >
cb93c9d7 1059
4299d9f5 1060C<index> is much like C<default> except that it takes no arguments and
1061it is weighted slightly higher in the matching process. It is useful
1062as a static entry point to a controller, e.g. to have a static welcome
1063page. Note that it's also weighted higher than Path. Actually the sub
1064name C<index> can be called anything you want. The sub attributes are
955bdf3d 1065what determines the behaviour of the action. B<Note>: in older
1066Catalyst applications, you will see C<index : Private> used, which is
1067roughly speaking equivalent.
cb93c9d7 1068
1069=item * B<begin : Private>
1070
d6ea2bcb 1071Called at the beginning of a request, once the controller that will
1072run has been identified, but before any URL-matching actions are
1073called. Catalyst will call the C<begin> function in the controller
1074which contains the action matching the URL.
cb93c9d7 1075
1076=item * B<end : Private>
1077
d6ea2bcb 1078Called at the end of a request, after all URL-matching actions are called.
1079Catalyst will call the C<end> function in the controller
1080which contains the action matching the URL.
1081
1082=item * B<auto : Private>
1083
1084In addition to the normal built-in actions, you have a special action
1085for making chains, C<auto>. C<auto> actions will be run after any
1086C<begin>, but before your URL-matching action is processed. Unlike the other
1087built-ins, multiple C<auto> actions can be called; they will be
1088called in turn, starting with the application class and going through
1089to the most specific class.
cb93c9d7 1090
1091=back
1092
1093=head4 Built-in actions in controllers/autochaining
1094
f76813a2 1095 package MyApp::Controller::Foo;
cb93c9d7 1096 sub begin : Private { }
4299d9f5 1097 sub default : Path { }
d6ea2bcb 1098 sub end : Path { }
1099
1100You can define built-in actions within your controllers as well as on
1101your application class. In other words, for each of the three built-in
1102actions above, only one will be run in any request cycle. Thus, if
1103C<MyApp::Controller::Catalog::begin> exists, it will be run in place
1104of C<MyApp::begin> if you're in the C<catalog> namespace, and
1105C<MyApp::Controller::Catalog::Order::begin> would override this in
cb93c9d7 1106turn.
1107
d6ea2bcb 1108 sub auto : Private { }
cb93c9d7 1109
d6ea2bcb 1110C<auto>, however, doesn't override like this: providing they exist,
a696baf6 1111C<MyApp::Controller::Root::auto>, C<MyApp::Controller::Catalog::auto> and
d6ea2bcb 1112C<MyApp::Catalog::Order::auto> would be called in turn.
cb93c9d7 1113
1114Here are some examples of the order in which the various built-ins
1115would be called:
1116
1117=over 4
1118
1119=item for a request for C</foo/foo>
1120
f76813a2 1121 MyApp::Controller::Foo::auto
cb93c9d7 1122 MyApp::Controller::Foo::default # in the absence of MyApp::Controller::Foo::Foo
f76813a2 1123 MyApp::Controller::Foo::end
cb93c9d7 1124
1125=item for a request for C</foo/bar/foo>
1126
1127 MyApp::Controller::Foo::Bar::begin
cb93c9d7 1128 MyApp::Controller::Foo::auto
1129 MyApp::Controller::Foo::Bar::auto
1130 MyApp::Controller::Foo::Bar::default # for MyApp::Controller::Foo::Bar::foo
1131 MyApp::Controller::Foo::Bar::end
1132
1133=back
1134
1135The C<auto> action is also distinguished by the fact that you can break
1136out of the processing chain by returning 0. If an C<auto> action returns
11370, any remaining actions will be skipped, except for C<end>. So, for the
1138request above, if the first auto returns false, the chain would look
1139like this:
1140
1141=over 4
1142
1143=item for a request for C</foo/bar/foo> where first C<auto> returns
1144false
1145
1146 MyApp::Controller::Foo::Bar::begin
d6ea2bcb 1147 MyApp::Controller::Foo::auto # returns false, skips some calls:
1148 # MyApp::Controller::Foo::Bar::auto - never called
1149 # MyApp::Controller::Foo::Bar::foo - never called
cb93c9d7 1150 MyApp::Controller::Foo::Bar::end
1151
d6ea2bcb 1152You can also C<die> in the auto action; in that case, the request will
1153go straight to the finalize stage, without processing further
1154actions. So in the above example, C<MyApp::Controller::Foo::Bar::end>
1155is skipped as well.
1156
cb93c9d7 1157=back
1158
d6ea2bcb 1159An example of why one might use C<auto> is an authentication action:
1160you could set up a C<auto> action to handle authentication in your
cb93c9d7 1161application class (which will always be called first), and if
d6ea2bcb 1162authentication fails, returning 0 would skip any remaining methods for
1163that URL.
cb93c9d7 1164
1165B<Note:> Looking at it another way, C<auto> actions have to return a
b1a08fe1 1166true value to continue processing!
cb93c9d7 1167
1168=head4 URL Path Handling
1169
d6ea2bcb 1170You can pass arguments as part of the URL path, separated with forward
1171slashes (/). If the action is a Regex or LocalRegex, the '$' anchor
1172must be used. For example, suppose you want to handle
1173C</foo/$bar/$baz>, where C<$bar> and C<$baz> may vary:
cb93c9d7 1174
1175 sub foo : Regex('^foo$') { my ($self, $context, $bar, $baz) = @_; }
1176
1177But what if you also defined actions for C</foo/boo> and C</foo/boo/hoo>?
1178
1179 sub boo : Path('foo/boo') { .. }
1180 sub hoo : Path('foo/boo/hoo') { .. }
1181
d6ea2bcb 1182Catalyst matches actions in most specific to least specific order - that is, whatever matches the most pieces of the path wins:
cb93c9d7 1183
1184 /foo/boo/hoo
1185 /foo/boo
1186 /foo # might be /foo/bar/baz but won't be /foo/boo/hoo
1187
1188So Catalyst would never mistakenly dispatch the first two URLs to the
1189'^foo$' action.
1190
b1a08fe1 1191If a Regex or LocalRegex action doesn't use the '$' anchor, the action will
1192still match a URL containing arguments; however the arguments won't be
d6ea2bcb 1193available via C<@_>, because the Regex will 'eat' them.
1194
1195Beware! If you write two matchers, that match the same path, with the
1196same specificity (that is, they match the same quantity of the path),
1197there's no guarantee which will actually get called. Non-regex
1198matchers get tried first, followed by regex ones, but if you have, for
1199instance:
1200
1201 package MyApp::Controller::Root;
1202
1203 sub match1 :Path('/a/b') { }
1204
1205 package MyApp::Controller::A;
1206
1207 sub b :Local { } # Matches /a/b
1208
1209then Catalyst will call the one it finds first. In summary, Don't Do
1210This.
cb93c9d7 1211
d6ea2bcb 1212=head4 Query Parameter Processing
cb93c9d7 1213
1214Parameters passed in the URL query string are handled with methods in
1215the L<Catalyst::Request> class. The C<param> method is functionally
1216equivalent to the C<param> method of C<CGI.pm> and can be used in
1217modules that require this.
1218
1219 # http://localhost:3000/catalog/view/?category=hardware&page=3
1220 my $category = $c->req->param('category');
1221 my $current_page = $c->req->param('page') || 1;
1222
1223 # multiple values for single parameter name
b1a08fe1 1224 my @values = $c->req->param('scrolling_list');
cb93c9d7 1225
1226 # DFV requires a CGI.pm-like input hash
1227 my $results = Data::FormValidator->check($c->req->params, \%dfv_profile);
1228
1229=head3 Flow Control
1230
1231You control the application flow with the C<forward> method, which
1232accepts the key of an action to execute. This can be an action in the
1233same or another Catalyst controller, or a Class name, optionally
1234followed by a method name. After a C<forward>, the control flow will
1235return to the method from which the C<forward> was issued.
1236
1237A C<forward> is similar to a method call. The main differences are that
1238it wraps the call in an C<eval> to allow exception handling; it
1239automatically passes along the context object (C<$c> or C<$context>);
1240and it allows profiling of each call (displayed in the log with
1241debugging enabled).
1242
1243 sub hello : Global {
1244 my ( $self, $c ) = @_;
1245 $c->stash->{message} = 'Hello World!';
1246 $c->forward('check_message'); # $c is automatically included
1247 }
1248
1249 sub check_message : Private {
1250 my ( $self, $c ) = @_;
1251 return unless $c->stash->{message};
1252 $c->forward('show_message');
1253 }
1254
1255 sub show_message : Private {
1256 my ( $self, $c ) = @_;
1257 $c->res->body( $c->stash->{message} );
1258 }
1259
1260A C<forward> does not create a new request, so your request object
1261(C<$c-E<gt>req>) will remain unchanged. This is a key difference between
1262using C<forward> and issuing a redirect.
1263
1264You can pass new arguments to a C<forward> by adding them
1265in an anonymous array. In this case C<$c-E<gt>req-E<gt>args>
1266will be changed for the duration of the C<forward> only; upon
1267return, the original value of C<$c-E<gt>req-E<gt>args> will
1268be reset.
1269
1270 sub hello : Global {
1271 my ( $self, $c ) = @_;
1272 $c->stash->{message} = 'Hello World!';
1273 $c->forward('check_message',[qw/test1/]);
1274 # now $c->req->args is back to what it was before
1275 }
1276
eecdf6ee 1277 sub check_message : Action {
1278 my ( $self, $c, $first_argument ) = @_;
1279 my $also_first_argument = $c->req->args->[0]; # now = 'test1'
cb93c9d7 1280 # do something...
1281 }
1282
1283As you can see from these examples, you can just use the method name as
1284long as you are referring to methods in the same controller. If you want
1285to forward to a method in another controller, or the main application,
1286you will have to refer to the method by absolute path.
1287
1288 $c->forward('/my/controller/action');
1289 $c->forward('/default'); # calls default in main application
1290
eecdf6ee 1291You can also forward to classes and methods.
08cb655f 1292
cb93c9d7 1293 sub hello : Global {
1294 my ( $self, $c ) = @_;
eecdf6ee 1295 $c->forward(qw/MyApp::View:Hello say_hello/);
cb93c9d7 1296 }
1297
1298 sub bye : Global {
1299 my ( $self, $c ) = @_;
1300 $c->forward('MyApp::Model::Hello'); # no method: will try 'process'
1301 }
1302
eecdf6ee 1303 package MyApp::View::Hello;
cb93c9d7 1304
1305 sub say_hello {
1306 my ( $self, $c ) = @_;
1307 $c->res->body('Hello World!');
1308 }
1309
1310 sub process {
1311 my ( $self, $c ) = @_;
1312 $c->res->body('Goodbye World!');
1313 }
1314
eecdf6ee 1315This mechanism is used by L<Catalyst::Action::RenderView> to forward
1316to the C<process> method in a view class.
1317
1318It should be noted that whilst forward is useful, it is not the only way
1319of calling other code in Catalyst. Forward just gives you stats in the debug
1320screen, wraps the code you're calling in an exception handler and localises
1321C<< $c->request->args >>.
1322
1323If you don't want or need these features then it's perfectly acceptable
1324(and faster) to do something like this:
1325
e8556dab 1326 sub hello : Global {
1327 my ( $self, $c ) = @_;
1328 $c->stash->{message} = 'Hello World!';
1329 $self->check_message( $c, 'test1' );
1330 }
1331
1332 sub check_message {
1333 my ( $self, $c, $first_argument ) = @_;
1334 # do something...
1335 }
eecdf6ee 1336
cb93c9d7 1337Note that C<forward> returns to the calling action and continues
1338processing after the action finishes. If you want all further processing
1339in the calling action to stop, use C<detach> instead, which will execute
1340the C<detach>ed action and not return to the calling sub. In both cases,
1341Catalyst will automatically try to call process() if you omit the
1342method.
1343
cb93c9d7 1344=head3 Testing
1345
1346Catalyst has a built-in http server for testing or local
1347deployment. (Later, you can easily use a more powerful server, for
1348example Apache/mod_perl or FastCGI, in a production environment.)
1349
1350Start your application on the command line...
1351
1352 script/myapp_server.pl
1353
1354...then visit http://localhost:3000/ in a browser to view the output.
1355
1356You can also do it all from the command line:
1357
1358 script/myapp_test.pl http://localhost/
1359
1360Catalyst has a number of tools for actual regression testing of
1361applications. The helper scripts will automatically generate basic tests
1362that can be extended as you develop your project. To write your own
1363comprehensive test scripts, L<Test::WWW::Mechanize::Catalyst> is an
1364invaluable tool.
1365
b86fa467 1366For more testing ideas, see L<Catalyst::Manual::Tutorial::08_Testing>.
cb93c9d7 1367
1368Have fun!
1369
1370=head1 SEE ALSO
1371
1372=over 4
1373
1374=item * L<Catalyst::Manual::About>
1375
1376=item * L<Catalyst::Manual::Tutorial>
1377
1378=item * L<Catalyst>
1379
1380=back
1381
1382=head1 SUPPORT
1383
1384IRC:
1385
1386 Join #catalyst on irc.perl.org.
1387 Join #catalyst-dev on irc.perl.org to help with development.
1388
1389Mailing lists:
1390
392906f2 1391 http://lists.scsys.co.uk/mailman/listinfo/catalyst
1392 http://lists.scsys.co.uk/mailman/listinfo/catalyst-dev
cb93c9d7 1393
fed95b6c 1394Wiki:
1395
1396 http://dev.catalystframework.org/wiki
1397
1398FAQ:
1399
1400 http://dev.catalystframework.org/wiki/faq
1401
bbddff00 1402=head1 AUTHORS
cb93c9d7 1403
bbddff00 1404Catalyst Contributors, see Catalyst.pm
cb93c9d7 1405
1406=head1 COPYRIGHT
1407
bbddff00 1408This library is free software. You can redistribute it and/or modify it under
1409the same terms as Perl itself.
b1a08fe1 1410
1411=cut