Update dev server info in the Cookbook, took out warnings about IE and added more...
[catagits/Catalyst-Manual.git] / lib / Catalyst / Manual / Cookbook.pod
CommitLineData
cb93c9d7 1=head1 NAME
2
3Catalyst::Manual::Cookbook - Cooking with Catalyst
4
5=head1 DESCRIPTION
6
7Yummy code like your mum used to bake!
8
9=head1 RECIPES
10
11=head1 Basics
12
13These recipes cover some basic stuff that is worth knowing for catalyst developers.
14
15=head2 Delivering a Custom Error Page
16
17By default, Catalyst will display its own error page whenever it
18encounters an error in your application. When running under C<-Debug>
19mode, the error page is a useful screen including the error message and
20L<Data::Dump> output of the relevant parts of the C<$c> context object.
21When not in C<-Debug>, users see a simple "Please come back later" screen.
22
23To use a custom error page, use a special C<end> method to short-circuit
24the error processing. The following is an example; you might want to
25adjust it further depending on the needs of your application (for
26example, any calls to C<fillform> will probably need to go into this
27C<end> method; see L<Catalyst::Plugin::FillInForm>).
28
29 sub end : Private {
30 my ( $self, $c ) = @_;
31
32 if ( scalar @{ $c->error } ) {
33 $c->stash->{errors} = $c->error;
34 $c->stash->{template} = 'errors.tt';
35 $c->forward('MyApp::View::TT');
36 $c->error(0);
37 }
38
39 return 1 if $c->response->status =~ /^3\d\d$/;
40 return 1 if $c->response->body;
41
42 unless ( $c->response->content_type ) {
43 $c->response->content_type('text/html; charset=utf-8');
44 }
45
46 $c->forward('MyApp::View::TT');
47 }
48
49You can manually set errors in your code to trigger this page by calling
50
51 $c->error( 'You broke me!' );
52
53=head2 Disable statistics
54
55Just add this line to your application class if you don't want those nifty
56statistics in your debug messages.
57
58 sub Catalyst::Log::info { }
59
60=head2 Enable debug status in the environment
61
62Normally you enable the debugging info by adding the C<-Debug> flag to
63your C<use Catalyst> statement. However, you can also enable it using
64environment variable, so you can (for example) get debug info without
65modifying your application scripts. Just set C<CATALYST_DEBUG> or
66C<E<lt>MYAPPE<gt>_DEBUG> to a true value.
67
68=head2 Sessions
69
70When you have your users identified, you will want to somehow remember that
71fact, to save them from having to identify themselves for every single
72page. One way to do this is to send the username and password parameters in
73every single page, but that's ugly, and won't work for static pages.
74
75Sessions are a method of saving data related to some transaction, and giving
76the whole collection a single ID. This ID is then given to the user to return
77to us on every page they visit while logged in. The usual way to do this is
78using a browser cookie.
79
80Catalyst uses two types of plugins to represent sessions:
81
82=head3 State
83
84A State module is used to keep track of the state of the session between the
85users browser, and your application.
86
87A common example is the Cookie state module, which sends the browser a cookie
88containing the session ID. It will use default value for the cookie name and
89domain, so will "just work" when used.
90
91=head3 Store
92
93A Store module is used to hold all the data relating to your session, for
94example the users ID, or the items for their shopping cart. You can store data
95in memory (FastMmap), in a file (File) or in a database (DBI).
96
97=head3 Authentication magic
98
99If you have included the session modules in your application, the
100Authentication modules will automagically use your session to save and
101retrieve the user data for you.
102
103=head3 Using a session
104
105Once the session modules are loaded, the session is available as C<<
106$c->session >>, and can be writen to and read from as a simple hash reference.
107
108=head3 EXAMPLE
109
110 use Catalyst qw/
111 Session
112 Session::Store::FastMmap
113 Session::State::Cookie
114 /;
115
116
117 ## Write data into the session
118
119 sub add_item : Local {
120 my ( $self, $c ) = @_;
121
122 my $item_id = $c->req->param("item");
123
124 push @{ $c->session->{items} }, $item_id;
125
126 }
127
128 ## A page later we retrieve the data from the session:
129
130 sub get_items : Local {
131 my ( $self, $c ) = @_;
132
133 $c->stash->{items_to_display} = $c->session->{items};
134
135 }
136
137
138=head3 More information
139
140L<http://search.cpan.org/dist/Catalyst-Plugin-Session>
141
142L<http://search.cpan.org/dist/Catalyst-Plugin-Session-State-Cookie>
143
144L<http://search.cpan.org/dist/Catalyst-Plugin-Session-State-URI>
145
146L<http://search.cpan.org/dist/Catalyst-Plugin-Session-Store-FastMmap>
147
148L<http://search.cpan.org/dist/Catalyst-Plugin-Session-Store-File>
149
150L<http://search.cpan.org/dist/Catalyst-Plugin-Session-Store-DBI>
151
152=head2 Configure your application
153
154You configure your application with the C<config> method in your
155application class. This can be hard-coded, or brought in from a
156separate configuration file.
157
158=head3 Using YAML
159
160YAML is a method for creating flexible and readable configuration
161files. It's a great way to keep your Catalyst application configuration
162in one easy-to-understand location.
163
164In your application class (e.g. C<lib/MyApp.pm>):
165
166 use YAML;
167 # application setup
168 __PACKAGE__->config( YAML::LoadFile(__PACKAGE__->config->{'home'} . '/myapp.yml') );
169 __PACKAGE__->setup;
170
171Now create C<myapp.yml> in your application home:
172
173 --- #YAML:1.0
174 # DO NOT USE TABS FOR INDENTATION OR label/value SEPARATION!!!
175 name: MyApp
176
177 # session; perldoc Catalyst::Plugin::Session::FastMmap
178 session:
179 expires: '3600'
180 rewrite: '0'
181 storage: '/tmp/myapp.session'
182
183 # emails; perldoc Catalyst::Plugin::Email
184 # this passes options as an array :(
185 email:
186 - SMTP
187 - localhost
188
189This is equivalent to:
190
191 # configure base package
192 __PACKAGE__->config( name => MyApp );
193 # configure authentication
194 __PACKAGE__->config->{authentication} = {
195 user_class => 'MyApp::Model::MyDB::Customer',
196 ...
197 };
198 # configure sessions
199 __PACKAGE__->config->{session} = {
200 expires => 3600,
201 ...
202 };
203 # configure email sending
204 __PACKAGE__->config->{email} = [qw/SMTP localhost/];
205
206See also L<YAML>.
207
208=head1 Skipping your VCS's directories
209
210Catalyst uses Module::Pluggable to load Models, Views and Controllers.
211Module::Pluggable will scan through all directories and load modules
212it finds. Sometimes you might want to skip some of these directories,
213for example when your version control system makes a subdirectory with
214meta-information in every version-controlled directory. While
215Catalyst skips subversion and CVS directories already, there are other
216source control systems. Here is the configuration you need to add
217their directories to the list to skip.
218
219You can make catalyst skip these directories using the Catalyst config:
220
221 # Configure the application
222 __PACKAGE__->config(
223 name => 'MyApp',
224 setup_components => { except => qr/SCCS/ },
225 );
226
227See the Module::Pluggable manual page for more information on B<except>
228and other options.
229
230=head1 Users and Access Control
231
232Most multiuser, and some single user web applications require that
233users identify themselves, and the application is often required to
234define those roles. The recipes below describe some ways of doing
235this.
236
237=head2 Authentication (logging in)
238
239This is extensively covered in other documentation; see in particular
240L<Catalyst::Plugin::Authentication> and the Authentication chapter
241of the Tutorial at L<Catalyst::Manual::Tutorial::Authorization>.
242
243=head2 Pass-through login (and other actions)
244
245An easy way of having assorted actions that occur during the processing
246of a request that are orthogonal to its actual purpose - logins, silent
247commands etc. Provide actions for these, but when they're required for
248something else fill e.g. a form variable __login and have a sub begin
249like so:
250
251 sub begin : Private {
252 my ($self, $c) = @_;
253 foreach my $action (qw/login docommand foo bar whatever/) {
254 if ($c->req->params->{"__${action}"}) {
255 $c->forward($action);
256 }
257 }
258 }
259
260
261=head2 Role-based Authorization
262
263For more advanced access control, you may want to consider using role-based
264authorization. This means you can assign different roles to each user, e.g.
265"user", "admin", etc.
266
267The C<login> and C<logout> methods and view template are exactly the same as
268in the previous example.
269
270The L<Catalyst::Plugin::Authorization::Roles> plugin is required when
271implementing roles:
272
273 use Catalyst qw/
274 Authentication
275 Authentication::Credential::Password
276 Authentication::Store::Htpasswd
277 Authorization::Roles
278 /;
279
280Roles are implemented automatically when using
281L<Catalyst::Authentication::Store::Htpasswd>:
282
283 # no additional role configuration required
284 __PACKAGE__->config->{authentication}{htpasswd} = "passwdfile";
285
286Or can be set up manually when using L<Catalyst::Authentication::Store::DBIC>:
287
288 # Authorization using a many-to-many role relationship
289 __PACKAGE__->config->{authorization}{dbic} = {
290 'role_class' => 'My::Model::DBIC::Role',
291 'role_field' => 'name',
292 'user_role_user_field' => 'user',
293
294 # DBIx::Class only (omit if using Class::DBI)
295 'role_rel' => 'user_role',
296
297 # Class::DBI only, (omit if using DBIx::Class)
298 'user_role_class' => 'My::Model::CDBI::UserRole'
299 'user_role_role_field' => 'role',
300 };
301
302To restrict access to any action, you can use the C<check_user_roles> method:
303
304 sub restricted : Local {
305 my ( $self, $c ) = @_;
306
307 $c->detach("unauthorized")
308 unless $c->check_user_roles( "admin" );
309
310 # do something restricted here
311 }
312
313You can also use the C<assert_user_roles> method. This just gives an error if
314the current user does not have one of the required roles:
315
316 sub also_restricted : Global {
317 my ( $self, $c ) = @_;
318 $c->assert_user_roles( qw/ user admin / );
319 }
320
321=head2 Authentication/Authorization
322
323This is done in several steps:
324
325=over 4
326
327=item Verification
328
329Getting the user to identify themselves, by giving you some piece of
330information known only to you and the user. Then you can assume that the user
331is who they say they are. This is called B<credential verification>.
332
333=item Authorization
334
335Making sure the user only accesses functions you want them to access. This is
336done by checking the verified users data against your internal list of groups,
337or allowed persons for the current page.
338
339=back
340
341=head3 Modules
342
343The Catalyst Authentication system is made up of many interacting modules, to
344give you the most flexibility possible.
345
346=head4 Credential verifiers
347
348A Credential module tables the user input, and passes it to a Store, or some
349other system, for verification. Typically, a user object is created by either
350this module or the Store and made accessible by a C<< $c->user >> call.
351
352Examples:
353
354 Password - Simple username/password checking.
355 HTTPD - Checks using basic HTTP auth.
356 TypeKey - Check using the typekey system.
357
358=head3 Storage backends
359
360A Storage backend contains the actual data representing the users. It is
361queried by the credential verifiers. Updating the store is not done within
362this system, you will need to do it yourself.
363
364Examples:
365
366 DBIC - Storage using a database.
367 Minimal - Storage using a simple hash (for testing).
368
369=head3 User objects
370
371A User object is created by either the storage backend or the credential
372verifier, and filled with the retrieved user information.
373
374Examples:
375
376 Hash - A simple hash of keys and values.
377
378=head3 ACL authorization
379
380ACL stands for Access Control List. The ACL plugin allows you to regulate
381access on a path by path basis, by listing which users, or roles, have access
382to which paths.
383
384=head3 Roles authorization
385
386Authorization by roles is for assigning users to groups, which can then be
387assigned to ACLs, or just checked when needed.
388
389=head3 Logging in
390
391When you have chosen your modules, all you need to do is call the C<<
392$c->login >> method. If called with no parameters, it will try to find
393suitable parameters, such as B<username> and B<password>, or you can pass it
394these values.
395
396=head3 Checking roles
397
398Role checking is done by using the C<< $c->check_user_roles >> method, this will
399check using the currently logged in user (via C<< $c->user >>). You pass it
400the name of a role to check, and it returns true if the user is a member.
401
402=head3 EXAMPLE
403
404 use Catalyst qw/Authentication
405 Authentication::Credential::Password
406 Authentication::Store::Htpasswd
407 Authorization::Roles/;
408
409 __PACKAGE__->config->{authentication}{htpasswd} = "passwdfile";
410
411 sub login : Local {
412 my ($self, $c) = @_;
413
414 if ( my $user = $c->req->param("user")
415 and my $password = $c->req->param("password") )
416 {
417 if ( $c->login( $user, $password ) ) {
418 $c->res->body( "hello " . $c->user->name );
419 } else {
420 # login incorrect
421 }
422 }
423 else {
424 # invalid form input
425 }
426 }
427
428 sub restricted : Local {
429 my ( $self, $c ) = @_;
430
431 $c->detach("unauthorized")
432 unless $c->check_user_roles( "admin" );
433
434 # do something restricted here
435 }
436
437=head3 Using authentication in a testing environment
438
439Ideally, to write tests for authentication/authorization code one would first
440set up a test database with known data, then use
441L<Test::WWW::Mechanize::Catalyst> to simulate a user logging in. Unfortunately
442the former can be rather awkward, which is why it's a good thing that the
443authentication framework is so flexible.
444
445Instead of using a test database, one can simply change the authentication
446store to something a bit easier to deal with in a testing
447environment. Additionally, this has the advantage of not modifying one's
448database, which can be problematic if one forgets to use the testing instead of
449production database.
450
451e.g.,
452
453 use Catalyst::Plugin::Authentication::Store::Minimal::Backend;
454
455 # Sets up the user `test_user' with password `test_pass'
456 MyApp->default_auth_store(
457 Catalyst::Plugin::Authentication::Store::Minimal::Backend->new({
458 test_user => { password => 'test_pass' },
459 })
460 );
461
462Now, your test code can call C<$c->login('test_user', 'test_pass')> and
463successfully login, without messing with the database at all.
464
465=head3 More information
466
467L<http://search.cpan.org/perldoc?Catalyst::Plugin::Authentication> has a longer explanation.
468
469=head2 Authorization
470
471=head3 Introduction
472
473Authorization is the step that comes after authentication. Authentication
474establishes that the user agent is really representing the user we think it's
475representing, and then authorization determines what this user is allowed to
476do.
477
478=head3 Role Based Access Control
479
480Under role based access control each user is allowed to perform any number of
481roles. For example, at a zoo no one but specially trained personnel can enter
482the moose cage (Mynd you, møøse bites kan be pretty nasti!). For example:
483
484 package Zoo::Controller::MooseCage;
485
486 sub feed_moose : Local {
487 my ( $self, $c ) = @_;
488
489 $c->model( "Moose" )->eat( $c->req->param("food") );
490 }
491
492With this action, anyone can just come into the moose cage and feed the moose,
493which is a very dangerous thing. We need to restrict this action, so that only
494a qualified moose feeder can perform that action.
495
496The Authorization::Roles plugin let's us perform role based access control
497checks. Let's load it:
498
499 use Catalyst qw/
500 Authentication # yadda yadda
501 Authorization::Roles
502 /;
503
504And now our action should look like this:
505
506 sub feed_moose : Local {
507 my ( $self, $c ) = @_;
508
509 if ( $c->check_roles( "moose_feeder" ) ) {
510 $c->model( "Moose" )->eat( $c->req->param("food") );
511 } else {
512 $c->stash->{error} = "unauthorized";
513 }
514 }
515
516This checks C<< $c->user >>, and only if the user has B<all> the roles in the
517list, a true value is returned.
518
519C<check_roles> has a sister method, C<assert_roles>, which throws an exception
520if any roles are missing.
521
522Some roles that might actually make sense in, say, a forum application:
523
524=over 4
525
526=item *
527
528administrator
529
530=item *
531
532moderator
533
534=back
535
536each with a distinct task (system administration versus content administration).
537
538=head3 Access Control Lists
539
540Checking for roles all the time can be tedious and error prone.
541
542The Authorization::ACL plugin let's us declare where we'd like checks to be
543done automatically for us.
544
545For example, we may want to completely block out anyone who isn't a
546C<moose_feeder> from the entire C<MooseCage> controller:
547
548 Zoo->deny_access_unless( "/moose_cage", [qw/moose_feeder/] );
549
550The role list behaves in the same way as C<check_roles>. However, the ACL
551plugin isn't limited to just interacting with the Roles plugin. We can use a
552code reference instead. For example, to allow either moose trainers or moose
553feeders into the moose cage, we can create a more complex check:
554
555 Zoo->deny_access_unless( "/moose_cage", sub {
556 my $c = shift;
557 $c->check_roles( "moose_trainer" ) || $c->check_roles( "moose_feeder" );
558 });
559
560The more specific a role, the earlier it will be checked. Let's say moose
561feeders are now restricted to only the C<feed_moose> action, while moose
562trainers get access everywhere:
563
564 Zoo->deny_access_unless( "/moose_cage", [qw/moose_trainer/] );
565 Zoo->allow_access_if( "/moose_cage/feed_moose", [qw/moose_feeder/]);
566
567When the C<feed_moose> action is accessed the second check will be made. If the
568user is a C<moose_feeder>, then access will be immediately granted. Otherwise,
569the next rule in line will be tested - the one checking for a C<moose_trainer>.
570If this rule is not satisfied, access will be immediately denied.
571
572Rules applied to the same path will be checked in the order they were added.
573
574Lastly, handling access denial events is done by creating an C<access_denied>
575private action:
576
577 sub access_denied : Private {
578 my ( $self, $c, $action ) = @_;
579
580
581 }
582
583This action works much like auto, in that it is inherited across namespaces
584(not like object oriented code). This means that the C<access_denied> action
585which is B<nearest> to the action which was blocked will be triggered.
586
587If this action does not exist, an error will be thrown, which you can clean up
588in your C<end> private action instead.
589
590Also, it's important to note that if you restrict access to "/" then C<end>,
591C<default>, etc will also be restricted.
592
593 MyApp->acl_allow_root_internals;
594
595will create rules that permit access to C<end>, C<begin>, and C<auto> in the
596root of your app (but not in any other controller).
597
598=head1 Models
599
600Models are where application data belongs. Catalyst is exteremely
601flexible with the kind of models that it can use. The recipes here
602are just the start.
603
604=head2 Using existing DBIC (etc.) classes with Catalyst
605
606Many people have existing Model classes that they would like to use with
607Catalyst (or, conversely, they want to write Catalyst models that can be
608used outside of Catalyst, e.g. in a cron job). It's trivial to write a
609simple component in Catalyst that slurps in an outside Model:
610
611 package MyApp::Model::DB;
612 use base qw/Catalyst::Model::DBIC::Schema/;
613 __PACKAGE__->config(
614 schema_class => 'Some::DBIC::Schema',
615 connect_info => ['dbi:SQLite:foo.db', '', '', {AutoCommit=>1}];
616 );
617 1;
618
619and that's it! Now C<Some::DBIC::Schema> is part of your
620Cat app as C<MyApp::Model::DB>.
621
622=head2 DBIx::Class as a Catalyst Model
623
624See L<Catalyst::Model::DBIC::Schema>.
625
626=head2 XMLRPC
627
628Unlike SOAP, XMLRPC is a very simple (and imo elegant) web-services
629protocol, exchanging small XML messages like these:
630
631Request:
632
633 POST /api HTTP/1.1
634 TE: deflate,gzip;q=0.3
635 Connection: TE, close
636 Accept: text/xml
637 Accept: multipart/*
638 Host: 127.0.0.1:3000
639 User-Agent: SOAP::Lite/Perl/0.60
640 Content-Length: 192
641 Content-Type: text/xml
642
643 <?xml version="1.0" encoding="UTF-8"?>
644 <methodCall>
645 <methodName>add</methodName>
646 <params>
647 <param><value><int>1</int></value></param>
648 <param><value><int>2</int></value></param>
649 </params>
650 </methodCall>
651
652Response:
653
654 Connection: close
655 Date: Tue, 20 Dec 2005 07:45:55 GMT
656 Content-Length: 133
657 Content-Type: text/xml
658 Status: 200
659 X-Catalyst: 5.70
660
661 <?xml version="1.0" encoding="us-ascii"?>
662 <methodResponse>
663 <params>
664 <param><value><int>3</int></value></param>
665 </params>
666 </methodResponse>
667
668Now follow these few steps to implement the application:
669
6701. Install Catalyst (5.61 or later), Catalyst::Plugin::XMLRPC (0.06 or
671later) and SOAP::Lite (for XMLRPCsh.pl).
672
6732. Create an application framework:
674
675 % catalyst.pl MyApp
676 ...
677 % cd MyApp
678
6793. Add the XMLRPC plugin to MyApp.pm
680
681 use Catalyst qw/-Debug Static::Simple XMLRPC/;
682
6834. Add an API controller
684
685 % ./script/myapp_create.pl controller API
686
6875. Add a XMLRPC redispatch method and an add method with Remote
688attribute to lib/MyApp/Controller/API.pm
689
690 sub default : Private {
691 my ( $self, $c ) = @_;
692 $c->xmlrpc;
693 }
694
695 sub add : Remote {
696 my ( $self, $c, $a, $b ) = @_;
697 return $a + $b;
698 }
699
700The default action is the entry point for each XMLRPC request. It will
701redispatch every request to methods with Remote attribute in the same
702class.
703
704The C<add> method is not a traditional action; it has no private or
705public path. Only the XMLRPC dispatcher knows it exists.
706
7076. That's it! You have built your first web service. Let's test it with
708XMLRPCsh.pl (part of SOAP::Lite):
709
710 % ./script/myapp_server.pl
711 ...
712 % XMLRPCsh.pl http://127.0.0.1:3000/api
713 Usage: method[(parameters)]
714 > add( 1, 2 )
715 --- XMLRPC RESULT ---
716 '3'
717
718=head3 Tip
719
720Your return data type is usually auto-detected, but you can easily
721enforce a specific one.
722
723 sub add : Remote {
724 my ( $self, $c, $a, $b ) = @_;
725 return RPC::XML::int->new( $a + $b );
726 }
727
728
729
730=head1 Views
731
732Views pertain to the display of your application. As with models,
733catalyst is uncommonly flexible. The recipes below are just a start.
734
735=head2 Catalyst::View::TT
736
737One of the first things you probably want to do when starting a new
738Catalyst application is set up your View. Catalyst doesn't care how you
739display your data; you can choose to generate HTML, PDF files, or plain
740text if you wanted.
741
742Most Catalyst applications use a template system to generate their HTML,
743and though there are several template systems available, Template
744Toolkit is probably the most popular.
745
746Once again, the Catalyst developers have done all the hard work, and
747made things easy for the rest of us. Catalyst::View::TT provides the
748interface to Template Toolkit, and provides Helpers which let us set it
749up that much more easily.
750
751=head3 Creating your View
752
753Catalyst::View::TT provides two different helpers for us to use: TT and
754TTSite.
755
756=head4 TT
757
758Create a basic Template Toolkit View using the provided helper script:
759
760 script/myapp_create.pl view TT TT
761
762This will create lib/MyApp/View/MyView.pm, which is going to be pretty
763empty to start. However, it sets everything up that you need to get
764started. You can now define which template you want and forward to your
765view. For instance:
766
767 sub hello : Local {
768 my ( $self, $c ) = @_;
769
770 $c->stash->{template} = 'hello.tt';
771
772 $c->forward( $c->view('TT') );
773 }
774
775In practice you wouldn't do the forwarding manually, but would
776use L<Catalyst::Action::RenderView>.
777
778=head4 TTSite
779
780Although the TT helper does create a functional, working view, you may
781find yourself having to create the same template files and changing the
782same options every time you create a new application. The TTSite helper
783saves us even more time by creating the basic templates and setting some
784common options for us.
785
786Once again, you can use the helper script:
787
788 script/myapp_create.pl view TT TTSite
789
790This time, the helper sets several options for us in the generated View.
791
792 __PACKAGE__->config({
793 CATALYST_VAR => 'Catalyst',
794 INCLUDE_PATH => [
795 MyApp->path_to( 'root', 'src' ),
796 MyApp->path_to( 'root', 'lib' )
797 ],
798 PRE_PROCESS => 'config/main',
799 WRAPPER => 'site/wrapper',
800 ERROR => 'error.tt2',
801 TIMER => 0
802 });
803
804=over
805
806=item
807
808INCLUDE_PATH defines the directories that Template Toolkit should search
809for the template files.
810
811=item
812
813PRE_PROCESS is used to process configuration options which are common to
814every template file.
815
816=item
817
818WRAPPER is a file which is processed with each template, usually used to
819easily provide a common header and footer for every page.
820
821=back
822
823In addition to setting these options, the TTSite helper also created the
824template and config files for us! In the 'root' directory, you'll notice
825two new directories: src and lib.
826
827Several configuration files in root/lib/config are called by PRE_PROCESS.
828
829The files in root/lib/site are the site-wide templates, called by
830WRAPPER, and display the html framework, control the layout, and provide
831the templates for the header and footer of your page. Using the template
832organization provided makes it much easier to standardize pages and make
833changes when they are (inevitably) needed.
834
835The template files that you will create for your application will go
836into root/src, and you don't need to worry about putting the the <html>
837or <head> sections; just put in the content. The WRAPPER will the rest
838of the page around your template for you.
839
840
841=head3 $c->stash
842
843Of course, having the template system include the header and footer for
844you isn't all that we want our templates to do. We need to be able to
845put data into our templates, and have it appear where and how we want
846it, right? That's where the stash comes in.
847
848In our controllers, we can add data to the stash, and then access it
849from the template. For instance:
850
851 sub hello : Local {
852 my ( $self, $c ) = @_;
853
854 $c->stash->{name} = 'Adam';
855
856 $c->stash->{template} = 'hello.tt';
857
858 $c->forward( $c->view('TT') );
859 }
860
861Then, in hello.tt:
862
863 <strong>Hello, [% name %]!</strong>
864
865When you view this page, it will display "Hello, Adam!"
866
867All of the information in your stash is available, by its name/key, in
868your templates. And your data don't have to be plain, old, boring
869scalars. You can pass array references and hash references, too.
870
871In your controller:
872
873 sub hello : Local {
874 my ( $self, $c ) = @_;
875
876 $c->stash->{names} = [ 'Adam', 'Dave', 'John' ];
877
878 $c->stash->{template} = 'hello.tt';
879
880 $c->forward( $c->view('TT') );
881 }
882
883In hello.tt:
884
885 [% FOREACH name IN names %]
886 <strong>Hello, [% name %]!</strong><br />
887 [% END %]
888
889This allowed us to loop through each item in the arrayref, and display a
890line for each name that we have.
891
892This is the most basic usage, but Template Toolkit is quite powerful,
893and allows you to truly keep your presentation logic separate from the
894rest of your application.
895
896=head3 $c->uri_for()
897
898One of my favorite things about Catalyst is the ability to move an
899application around without having to worry that everything is going to
900break. One of the areas that used to be a problem was with the http
901links in your template files. For example, suppose you have an
902application installed at http://www.domain.com/Calendar. The links point
903to "/Calendar", "/Calendar/2005", "/Calendar/2005/10", etc. If you move
904the application to be at http://www.mydomain.com/Tools/Calendar, then
905all of those links will suddenly break.
906
907That's where $c->uri_for() comes in. This function will merge its
908parameters with either the base location for the app, or its current
909namespace. Let's take a look at a couple of examples.
910
911In your template, you can use the following:
912
913 <a href="[% c.uri_for('/login') %]">Login Here</a>
914
915Although the parameter starts with a forward slash, this is relative to the application root, not the webserver root. This is important to remember. So, if your application is installed at http://www.domain.com/Calendar, then the link would be http://www.mydomain.com/Calendar/Login. If you move your application to a different domain or path, then that link will still be correct.
916
917Likewise,
918
919 <a href="[% c.uri_for('2005','10', '24') %]">October, 24 2005</a>
920
921The first parameter does NOT have a forward slash, and so it will be relative to the current namespace. If the application is installed at http://www.domain.com/Calendar. and if the template is called from MyApp::Controller::Display, then the link would become http://www.domain.com/Calendar/Display/2005/10/24.
922
923Once again, this allows you to move your application around without having to worry about broken links. But there's something else, as well. Since the links are generated by uri_for, you can use the same template file by several different controllers, and each controller will get the links that its supposed to. Since we believe in Don't Repeat Yourself, this is particularly helpful if you have common elements in your site that you want to keep in one file.
924
925Further Reading:
926
927L<http://search.cpan.org/perldoc?Catalyst>
928
929L<http://search.cpan.org/perldoc?Catalyst%3A%3AView%3A%3ATT>
930
931L<http://search.cpan.org/perldoc?Template>
932
933=head2 Adding RSS feeds
934
935Adding RSS feeds to your Catalyst applications is simple. We'll see two
936different aproaches here, but the basic premise is that you forward to
937the normal view action first to get the objects, then handle the output
938differently.
939
940=head3 Using TT templates
941
942This is the aproach used in Agave (L<http://dev.rawmode.org/>).
943
944 sub rss : Local {
945 my ($self,$c) = @_;
946 $c->forward('view');
947 $c->stash->{template}='rss.tt';
948 }
949
950Then you need a template. Here's the one from Agave:
951
952 <?xml version="1.0" encoding="UTF-8"?>
953 <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
954 <channel>
955 <title>[ [% blog.name || c.config.name || "Agave" %] ] RSS Feed</title>
956 <link>[% base %]</link>
957 <description>Recent posts</description>
958 <language>en-us</language>
959 <ttl>40</ttl>
960 [% WHILE (post = posts.next) %]
961 <item>
962 <title>[% post.title %]</title>
963 <description>[% post.formatted_teaser|html%]</description>
964 <pubDate>[% post.pub_date %]</pubDate>
965 <guid>[% post.full_uri %]</guid>
966 <link>[% post.full_uri %]</link>
967 <dc:creator>[% post.author.screenname %]</dc:creator>
968 </item>
969 [% END %]
970 </channel>
971 </rss>
972
973=head3 Using XML::Feed
974
975A more robust solution is to use XML::Feed, as was done in the Catalyst
976Advent Calendar. Assuming we have a C<view> action that populates
977'entries' with some DBIx::Class iterator, the code would look something
978like this:
979
980 sub rss : Local {
981 my ($self,$c) = @_;
982 $c->forward('view'); # get the entries
983
984 my $feed = XML::Feed->new('RSS');
985 $feed->title( $c->config->{name} . ' RSS Feed' );
986 $feed->link( $c->req->base ); # link to the site.
987 $feed->description('Catalyst advent calendar'); Some description
988
989 # Process the entries
990 while( my $entry = $c->stash->{entries}->next ) {
991 my $feed_entry = XML::Feed::Entry->new('RSS');
992 $feed_entry->title($entry->title);
993 $feed_entry->link( $c->uri_for($entry->link) );
994 $feed_entry->issued( DateTime->from_epoch(epoch => $entry->created) );
995 $feed->add_entry($feed_entry);
996 }
997 $c->res->body( $feed->as_xml );
998 }
999
1000A little more code in the controller, but with this approach you're
1001pretty sure to get something that validates.
1002
1003Note that for both of the above aproaches, you'll need to set the
1004content type like this:
1005
1006 $c->res->content_type('application/rss+xml');
1007
1008=head3 Final words
1009
1010You could generalize the second variant easily by replacing 'RSS' with a
1011variable, so you can generate Atom feeds with the same code.
1012
1013Now, go ahead and make RSS feeds for all your stuff. The world *needs*
1014updates on your goldfish!
1015
1016=head2 Forcing the browser to download content
1017
1018Sometimes you need your application to send content for download. For
1019example, you can generate a comma-separated values (CSV) file for your
1020users to download and import into their spreadsheet program.
1021
1022Let's say you have an C<Orders> controller which generates a CSV file
1023in the C<export> action (i.e., C<http://localhost:3000/orders/export>):
1024
1025 sub export : Local Args(0) {
1026 my ( $self, $c ) = @_;
1027
1028 # In a real application, you'd generate this from the database
1029 my $csv = "1,5.99\n2,29.99\n3,3.99\n";
1030
1031 $c->res->content_type('text/comma-separated-values');
1032 $c->res->body($csv);
1033 }
1034
1035Normally the browser uses the last part of the URI to generate a
1036filename for data it cannot display. In this case your browser would
1037likely ask you to save a file named C<export>.
1038
1039Luckily you can have the browser download the content with a specific
1040filename by setting the C<Content-Disposition> header:
1041
1042 my $filename = 'Important Orders.csv';
1043 $c->res->header('Content-Disposition', qq[attachment; filename="$filename"]);
1044
1045Note the use of quotes around the filename; this ensures that any
1046spaces in the filename are handled by the browser.
1047
1048Put this right before calling C<< $c->res->body >> and your browser
1049will download a file named C<Important Orders.csv> instead of
1050C<export>.
1051
1052You can also use this to have the browser download content which it
1053normally displays, such as JPEG images or even HTML. Just be sure to
1054set the appropriate content type and disposition.
1055
1056
1057=head1 Controllers
1058
1059Controllers are the main point of communication between the web server
1060and your application. Here we explore some aspects of how they work.
1061
1062=head2 Extending RenderView (formerly DefaultEnd)
1063
1064The recommended approach for an C<end> action is to use
1065L<Catalyst::Action::RenderView> (taking the place of
1066L<Catalyst::Plugin::DefaultEnd>), which does what you usually need.
1067However there are times when you need to add a bit to it, but don't want
1068to write your own C<end> action.
1069
1070You can extend it like this:
1071
1072To add something to an C<end> action that is called before rendering
1073(this is likely to be what you want), simply place it in the C<end>
1074method:
1075
1076 sub end : ActionClass('RenderView') {
1077 my ( $self, $c ) = @_;
1078 # do stuff here; the RenderView action is called afterwards
1079 }
1080
1081To add things to an C<end> action that are called I<after> rendering,
1082you can set it up like this:
1083
1084 sub render : ActionClass('RenderView') { }
1085
1086 sub end : Private {
1087 my ( $self, $c ) = @_;
1088 $c->forward('render');
1089 # do stuff here
1090 }
1091
1092=head2 Action Types
1093
1094=head3 Introduction
1095
1096A Catalyst application is driven by one or more Controller modules. There are
1097a number of ways that Catalyst can decide which of the methods in your
1098controller modules it should call. Controller methods are also called actions,
1099because they determine how your catalyst application should (re-)act to any
1100given URL. When the application is started up, catalyst looks at all your
1101actions, and decides which URLs they map to.
1102
1103=head3 Type attributes
1104
1105Each action is a normal method in your controller, except that it has an
1106L<attribute|http://search.cpan.org/~nwclark/perl-5.8.7/lib/attributes.pm>
1107attached. These can be one of several types.
1108
1109Assume our Controller module starts with the following package declaration:
1110
1111 package MyApp::Controller::Buckets;
1112
1113and we are running our application on localhost, port 3000 (the test
1114server default).
1115
1116=over 4
1117
1118=item Path
1119
1120A Path attribute also takes an argument, this can be either a relative
1121or an absolute path. A relative path will be relative to the controller
1122namespace, an absolute path will represent an exact matching URL.
1123
1124 sub my_handles : Path('handles') { .. }
1125
1126becomes
1127
1128 http://localhost:3000/buckets/handles
1129
1130and
1131
1132 sub my_handles : Path('/handles') { .. }
1133
1134becomes
1135
1136 http://localhost:3000/handles
1137
1138=item Local
1139
1140When using a Local attribute, no parameters are needed, instead, the name of
1141the action is matched in the URL. The namespaces created by the name of the
1142controller package is always part of the URL.
1143
1144 sub my_handles : Local { .. }
1145
1146becomes
1147
1148 http://localhost:3000/buckets/my_handles
1149
1150=item Global
1151
1152A Global attribute is similar to a Local attribute, except that the namespace
1153of the controller is ignored, and matching starts at root.
1154
1155 sub my_handles : Global { .. }
1156
1157becomes
1158
1159 http://localhost:3000/my_handles
1160
1161=item Regex
1162
1163By now you should have figured that a Regex attribute is just what it sounds
1164like. This one takes a regular expression, and matches starting from
1165root. These differ from the rest as they can match multiple URLs.
1166
1167 sub my_handles : Regex('^handles') { .. }
1168
1169matches
1170
1171 http://localhost:3000/handles
1172
1173and
1174
1175 http://localhost:3000/handles_and_other_parts
1176
1177etc.
1178
1179=item LocalRegex
1180
1181A LocalRegex is similar to a Regex, except it only matches below the current
1182controller namespace.
1183
1184 sub my_handles : LocalRegex(^handles') { .. }
1185
1186matches
1187
1188 http://localhost:3000/buckets/handles
1189
1190and
1191
1192 http://localhost:3000/buckets/handles_and_other_parts
1193
1194etc.
1195
1196=item Private
1197
1198Last but not least, there is the Private attribute, which allows you to create
1199your own internal actions, which can be forwarded to, but won't be matched as
1200URLs.
1201
1202 sub my_handles : Private { .. }
1203
1204becomes nothing at all..
1205
1206Catalyst also predefines some special Private actions, which you can override,
1207these are:
1208
1209=over 4
1210
1211=item default
1212
1213The default action will be called, if no other matching action is found. If
1214you don't have one of these in your namespace, or any sub part of your
1215namespace, you'll get an error page instead. If you want to find out where it
1216was the user was trying to go, you can look in the request object using
1217C<< $c->req->path >>.
1218
1219 sub default : Private { .. }
1220
1221works for all unknown URLs, in this controller namespace, or every one if put
1222directly into MyApp.pm.
1223
1224=item index
1225
1226The index action is called when someone tries to visit the exact namespace of
1227your controller. If index, default and matching Path actions are defined, then
1228index will be used instead of default and Path.
1229
1230 sub index : Private { .. }
1231
1232becomes
1233
1234 http://localhost:3000/buckets
1235
1236=item begin
1237
1238The begin action is called at the beginning of every request involving this
1239namespace directly, before other matching actions are called. It can be used
1240to set up variables/data for this particular part of your app. A single begin
1241action is called, its always the one most relevant to the current namespace.
1242
1243 sub begin : Private { .. }
1244
1245is called once when
1246
1247 http://localhost:3000/bucket/(anything)?
1248
1249is visited.
1250
1251=item end
1252
1253Like begin, this action is always called for the namespace it is in, after
1254every other action has finished. It is commonly used to forward processing to
1255the View component. A single end action is called, its always the one most
1256relevant to the current namespace.
1257
1258
1259 sub end : Private { .. }
1260
1261is called once after any actions when
1262
1263 http://localhost:3000/bucket/(anything)?
1264
1265is visited.
1266
1267=item auto
1268
1269Lastly, the auto action is magic in that B<every> auto action in
1270the chain of paths up to and including the ending namespace, will be
1271called. (In contrast, only one of the begin/end/default actions will be
1272called, the relevant one).
1273
1274 package MyApp.pm;
1275 sub auto : Private { .. }
1276
1277and
1278
1279 sub auto : Private { .. }
1280
1281will both be called when visiting
1282
1283 http://localhost:3000/bucket/(anything)?
1284
1285=back
1286
1287=back
1288
1289=head3 A word of warning
1290
1291Due to possible namespace conflicts with Plugins, it is advised to only put the
1292pre-defined Private actions in your main MyApp.pm file, all others should go
1293in a Controller module.
1294
1295=head3 More Information
1296
1297L<http://search.cpan.org/author/SRI/Catalyst-5.61/lib/Catalyst/Manual/Intro.pod>
1298
1299L<http://dev.catalyst.perl.org/wiki/FlowChart>
1300
1301=head2 Component-based Subrequests
1302
1303See L<Catalyst::Plugin::SubRequest>.
1304
1305=head2 File uploads
1306
1307=head3 Single file upload with Catalyst
1308
1309To implement uploads in Catalyst, you need to have a HTML form similar to
1310this:
1311
1312 <form action="/upload" method="post" enctype="multipart/form-data">
1313 <input type="hidden" name="form_submit" value="yes">
1314 <input type="file" name="my_file">
1315 <input type="submit" value="Send">
1316 </form>
1317
1318It's very important not to forget C<enctype="multipart/form-data"> in
1319the form.
1320
1321Catalyst Controller module 'upload' action:
1322
1323 sub upload : Global {
1324 my ($self, $c) = @_;
1325
1326 if ( $c->request->parameters->{form_submit} eq 'yes' ) {
1327
1328 if ( my $upload = $c->request->upload('my_file') ) {
1329
1330 my $filename = $upload->filename;
1331 my $target = "/tmp/upload/$filename";
1332
1333 unless ( $upload->link_to($target) || $upload->copy_to($target) ) {
1334 die( "Failed to copy '$filename' to '$target': $!" );
1335 }
1336 }
1337 }
1338
1339 $c->stash->{template} = 'file_upload.html';
1340 }
1341
1342=head3 Multiple file upload with Catalyst
1343
1344Code for uploading multiple files from one form needs a few changes:
1345
1346The form should have this basic structure:
1347
1348 <form action="/upload" method="post" enctype="multipart/form-data">
1349 <input type="hidden" name="form_submit" value="yes">
1350 <input type="file" name="file1" size="50"><br>
1351 <input type="file" name="file2" size="50"><br>
1352 <input type="file" name="file3" size="50"><br>
1353 <input type="submit" value="Send">
1354 </form>
1355
1356And in the controller:
1357
1358 sub upload : Local {
1359 my ($self, $c) = @_;
1360
1361 if ( $c->request->parameters->{form_submit} eq 'yes' ) {
1362
1363 for my $field ( $c->req->upload ) {
1364
1365 my $upload = $c->req->upload($field);
1366 my $filename = $upload->filename;
1367 my $target = "/tmp/upload/$filename";
1368
1369 unless ( $upload->link_to($target) || $upload->copy_to($target) ) {
1370 die( "Failed to copy '$filename' to '$target': $!" );
1371 }
1372 }
1373 }
1374
1375 $c->stash->{template} = 'file_upload.html';
1376 }
1377
1378C<for my $field ($c-E<gt>req->upload)> loops automatically over all file
1379input fields and gets input names. After that is basic file saving code,
1380just like in single file upload.
1381
1382Notice: C<die>ing might not be what you want to do, when an error
1383occurs, but it works as an example. A better idea would be to store
1384error C<$!> in $c->stash->{error} and show a custom error template
1385displaying this message.
1386
1387For more information about uploads and usable methods look at
1388L<Catalyst::Request::Upload> and L<Catalyst::Request>.
1389
1390=head2 Forwarding with arguments
1391
1392Sometimes you want to pass along arguments when forwarding to another
1393action. As of version 5.30, arguments can be passed in the call to
1394C<forward>; in earlier versions, you can manually set the arguments in
1395the Catalyst Request object:
1396
1397 # version 5.30 and later:
1398 $c->forward('/wherever', [qw/arg1 arg2 arg3/]);
1399
1400 # pre-5.30
1401 $c->req->args([qw/arg1 arg2 arg3/]);
1402 $c->forward('/wherever');
1403
1404(See the L<Catalyst::Manual::Intro> Flow_Control section for more
1405information on passing arguments via C<forward>.)
1406
1407
1408=head1 Deployment
1409
1410The recipes below describe aspects of the deployment process,
1411including web server engines and tips to improve application efficiency.
1412
1413=head2 mod_perl Deployment
1414
1415mod_perl is the best solution for many applications, but we'll list some pros
1416and cons so you can decide for yourself. The other production deployment
1417option is FastCGI, for which see below.
1418
1419=head3 Pros
1420
1421=head4 Speed
1422
1423mod_perl is very fast and your app will benefit from being loaded in memory
1424within each Apache process.
1425
1426=head4 Shared memory for multiple apps
1427
1428If you need to run several Catalyst apps on the same server, mod_perl will
1429share the memory for common modules.
1430
1431=head3 Cons
1432
1433=head4 Memory usage
1434
1435Since your application is fully loaded in memory, every Apache process will
1436be rather large. This means a large Apache process will be tied up while
1437serving static files, large files, or dealing with slow clients. For this
1438reason, it is best to run a two-tiered web architecture with a lightweight
1439frontend server passing dynamic requests to a large backend mod_perl
1440server.
1441
1442=head4 Reloading
1443
1444Any changes made to the core code of your app require a full Apache restart.
1445Catalyst does not support Apache::Reload or StatINC. This is another good
1446reason to run a frontend web server where you can set up an
1447C<ErrorDocument 502> page to report that your app is down for maintenance.
1448
1449=head4 Cannot run multiple versions of the same app
1450
1451It is not possible to run two different versions of the same application in
1452the same Apache instance because the namespaces will collide.
1453
1454=head4 Setup
1455
1456Now that we have that out of the way, let's talk about setting up mod_perl
1457to run a Catalyst app.
1458
1459=head4 1. Install Catalyst::Engine::Apache
1460
1461You should install the latest versions of both Catalyst and
1462Catalyst::Engine::Apache. The Apache engines were separated from the
1463Catalyst core in version 5.50 to allow for updates to the engine without
1464requiring a new Catalyst release.
1465
1466=head4 2. Install Apache with mod_perl
1467
1468Both Apache 1.3 and Apache 2 are supported, although Apache 2 is highly
1469recommended. With Apache 2, make sure you are using the prefork MPM and not
1470the worker MPM. The reason for this is that many Perl modules are not
1471thread-safe and may have problems running within the threaded worker
1472environment. Catalyst is thread-safe however, so if you know what you're
1473doing, you may be able to run using worker.
1474
1475In Debian, the following commands should get you going.
1476
1477 apt-get install apache2-mpm-prefork
1478 apt-get install libapache2-mod-perl2
1479
1480=head4 3. Configure your application
1481
1482Every Catalyst application will automagically become a mod_perl handler
1483when run within mod_perl. This makes the configuration extremely easy.
1484Here is a basic Apache 2 configuration.
1485
1486 PerlSwitches -I/var/www/MyApp/lib
1487 PerlModule MyApp
1488
1489 <Location />
1490 SetHandler modperl
1491 PerlResponseHandler MyApp
1492 </Location>
1493
1494The most important line here is C<PerlModule MyApp>. This causes mod_perl
1495to preload your entire application into shared memory, including all of your
1496controller, model, and view classes and configuration. If you have -Debug
1497mode enabled, you will see the startup output scroll by when you first
1498start Apache.
1499
1500For an example Apache 1.3 configuration, please see the documentation for
1501L<Catalyst::Engine::Apache::MP13>.
1502
1503=head3 Test It
1504
1505That's it, your app is now a full-fledged mod_perl application! Try it out
1506by going to http://your.server.com/.
1507
1508=head3 Other Options
1509
1510=head4 Non-root location
1511
1512You may not always want to run your app at the root of your server or virtual
1513host. In this case, it's a simple change to run at any non-root location
1514of your choice.
1515
1516 <Location /myapp>
1517 SetHandler modperl
1518 PerlResponseHandler MyApp
1519 </Location>
1520
1521When running this way, it is best to make use of the C<uri_for> method in
1522Catalyst for constructing correct links.
1523
1524=head4 Static file handling
1525
1526Static files can be served directly by Apache for a performance boost.
1527
1528 DocumentRoot /var/www/MyApp/root
1529 <Location /static>
1530 SetHandler default-handler
1531 </Location>
1532
1533This will let all files within root/static be handled directly by Apache. In
1534a two-tiered setup, the frontend server should handle static files.
1535The configuration to do this on the frontend will vary.
1536
3cca8359 1537The same is accomplished in lighttpd with the following snippet:
1538
1539 $HTTP["url"] !~ "^/(?:img/|static/|css/|favicon.ico$)" {
1540 fastcgi.server = (
1541 "" => (
1542 "MyApp" => (
1543 "socket" => "/tmp/myapp.socket",
1544 "check-local" => "disable",
1545 )
1546 )
1547 )
1548 }
1549
1550Which serves everything in the img, static, css directories
1551statically, as well as the favicon file.
1552
c1c35b01 1553Note the path of the application needs to be stated explicitly in the
1554web server configuration for both these recipes.
3cca8359 1555
cb93c9d7 1556=head2 Catalyst on shared hosting
1557
1558So, you want to put your Catalyst app out there for the whole world to
1559see, but you don't want to break the bank. There is an answer - if you
1560can get shared hosting with FastCGI and a shell, you can install your
1561Catalyst app in a local directory on your shared host. First, run
1562
1563 perl -MCPAN -e shell
1564
1565and go through the standard CPAN configuration process. Then exit out
1566without installing anything. Next, open your .bashrc and add
1567
1568 export PATH=$HOME/local/bin:$HOME/local/script:$PATH
1569 perlversion=`perl -v | grep 'built for' | awk '{print $4}' | sed -e 's/v//;'`
1570 export PERL5LIB=$HOME/local/share/perl/$perlversion:$HOME/local/lib/perl/$perlversion:$HOME/local/lib:$PERL5LIB
1571
1572and log out, then back in again (or run C<". .bashrc"> if you
1573prefer). Finally, edit C<.cpan/CPAN/MyConfig.pm> and add
1574
1575 'make_install_arg' => qq[SITEPREFIX=$ENV{HOME}/local],
1576 'makepl_arg' => qq[INSTALLDIRS=site install_base=$ENV{HOME}/local],
1577
1578Now you can install the modules you need using CPAN as normal; they
1579will be installed into your local directory, and perl will pick them
1580up. Finally, change directory into the root of your virtual host and
1581symlink your application's script directory in:
1582
1583 cd path/to/mydomain.com
1584 ln -s ~/lib/MyApp/script script
1585
1586And add the following lines to your .htaccess file (assuming the server
1587is setup to handle .pl as fcgi - you may need to rename the script to
1588myapp_fastcgi.fcgi and/or use a SetHandler directive):
1589
1590 RewriteEngine On
1591 RewriteCond %{REQUEST_URI} !^/?script/myapp_fastcgi.pl
1592 RewriteRule ^(.*)$ script/myapp_fastcgi.pl/$1 [PT,L]
1593
1594Now C<http://mydomain.com/> should now Just Work. Congratulations, now
1595you can tell your friends about your new website (or in our case, tell
1596the client it's time to pay the invoice :) )
1597
1598=head2 FastCGI Deployment
1599
1600FastCGI is a high-performance extension to CGI. It is suitable
1601for production environments.
1602
1603=head3 Pros
1604
1605=head4 Speed
1606
1607FastCGI performs equally as well as mod_perl. Don't let the 'CGI' fool you;
1608your app runs as multiple persistent processes ready to receive connections
1609from the web server.
1610
1611=head4 App Server
1612
1613When using external FastCGI servers, your application runs as a standalone
1614application server. It may be restarted independently from the web server.
1615This allows for a more robust environment and faster reload times when
1616pushing new app changes. The frontend server can even be configured to
1617display a friendly "down for maintenance" page while the application is
1618restarting.
1619
1620=head4 Load-balancing
1621
1622You can launch your application on multiple backend servers and allow the
1623frontend web server to load-balance between all of them. And of course, if
1624one goes down, your app continues to run fine.
1625
1626=head4 Multiple versions of the same app
1627
1628Each FastCGI application is a separate process, so you can run different
1629versions of the same app on a single server.
1630
1631=head4 Can run with threaded Apache
1632
1633Since your app is not running inside of Apache, the faster mpm_worker module
1634can be used without worrying about the thread safety of your application.
1635
1636=head3 Cons
1637
1638=head4 More complex environment
1639
1640With FastCGI, there are more things to monitor and more processes running
1641than when using mod_perl.
1642
1643=head3 Setup
1644
1645=head4 1. Install Apache with mod_fastcgi
1646
1647mod_fastcgi for Apache is a third party module, and can be found at
1648L<http://www.fastcgi.com/>. It is also packaged in many distributions,
1649for example, libapache2-mod-fastcgi in Debian.
1650
1651=head4 2. Configure your application
1652
1653 # Serve static content directly
1654 DocumentRoot /var/www/MyApp/root
1655 Alias /static /var/www/MyApp/root/static
1656
1657 FastCgiServer /var/www/MyApp/script/myapp_fastcgi.pl -processes 3
1658 Alias /myapp/ /var/www/MyApp/script/myapp_fastcgi.pl/
1659
1660 # Or, run at the root
1661 Alias / /var/www/MyApp/script/myapp_fastcgi.pl/
1662
1663The above commands will launch 3 app processes and make the app available at
1664/myapp/
1665
1666=head3 Standalone server mode
1667
1668While not as easy as the previous method, running your app as an external
1669server gives you much more flexibility.
1670
1671First, launch your app as a standalone server listening on a socket.
1672
1673 script/myapp_fastcgi.pl -l /tmp/myapp.socket -n 5 -p /tmp/myapp.pid -d
1674
1675You can also listen on a TCP port if your web server is not on the same
1676machine.
1677
1678 script/myapp_fastcgi.pl -l :8080 -n 5 -p /tmp/myapp.pid -d
1679
1680You will probably want to write an init script to handle starting/stopping
1681of the app using the pid file.
1682
1683Now, we simply configure Apache to connect to the running server.
1684
1685 # 502 is a Bad Gateway error, and will occur if the backend server is down
1686 # This allows us to display a friendly static page that says "down for
1687 # maintenance"
1688 Alias /_errors /var/www/MyApp/root/error-pages
1689 ErrorDocument 502 /_errors/502.html
1690
31bdf270 1691 FastCgiExternalServer /tmp/myapp.fcgi -socket /tmp/myapp.socket
1692 Alias /myapp/ /tmp/myapp.fcgi/
cb93c9d7 1693
1694 # Or, run at the root
31bdf270 1695 Alias / /tmp/myapp.fcgi/
cb93c9d7 1696
1697=head3 More Info
1698
1699L<Catalyst::Engine::FastCGI>.
1700
1701=head2 Development server deployment
1702
1703The development server is a mini web server written in perl. If you
1704expect a low number of hits or you don't need mod_perl/FastCGI speed,
1705you could use the development server as the application server with a
ad2a47ab 1706lightweight proxy web server at the front. However, consider using
1707L<Catalyst::Engine::HTTP::POE> for this kind of deployment instead, since
1708it can better handle multiple concurrent requests without forking, or can
1709prefork a set number of servers for improved performance.
cb93c9d7 1710
1711=head3 Pros
1712
1713As this is an application server setup, the pros are the same as
1714FastCGI (with the exception of speed).
1715It is also:
1716
1717=head4 Simple
1718
1719The development server is what you create your code on, so if it works
1720here, it should work in production!
1721
1722=head3 Cons
1723
1724=head4 Speed
1725
1726Not as fast as mod_perl or FastCGI. Needs to fork for each request
1727that comes in - make sure static files are served by the web server to
1728save forking.
1729
1730=head3 Setup
1731
1732=head4 Start up the development server
1733
ad2a47ab 1734 script/myapp_server.pl -p 8080 -k -f -pidfile=/tmp/myapp.pid
cb93c9d7 1735
1736You will probably want to write an init script to handle stop/starting
1737the app using the pid file.
1738
1739=head4 Configuring Apache
1740
1741Make sure mod_proxy is enabled and add:
1742
1743 # Serve static content directly
1744 DocumentRoot /var/www/MyApp/root
1745 Alias /static /var/www/MyApp/root/static
1746
1747 ProxyRequests Off
1748 <Proxy *>
1749 Order deny,allow
1750 Allow from all
1751 </Proxy>
1752 ProxyPass / http://localhost:8080/
1753 ProxyPassReverse / http://localhost:8080/
1754
1755You can wrap the above within a VirtualHost container if you want
1756different apps served on the same host.
1757
1758=head2 Quick deployment: Building PAR Packages
1759
1760You have an application running on your development box, but then you
1761have to quickly move it to another one for
1762demonstration/deployment/testing...
1763
1764PAR packages can save you from a lot of trouble here. They are usual Zip
1765files that contain a blib tree; you can even include all prereqs and a
1766perl interpreter by setting a few flags!
1767
1768=head3 Follow these few points to try it out!
1769
17701. Install Catalyst and PAR 0.89 (or later)
1771
1772 % perl -MCPAN -e 'install Catalyst'
1773 ...
1774 % perl -MCPAN -e 'install PAR'
1775 ...
1776
17772. Create a application
1778
1779 % catalyst.pl MyApp
1780 ...
1781 % cd MyApp
1782
1783Recent versions of Catalyst (5.62 and up) include
1784L<Module::Install::Catalyst>, which simplifies the process greatly. From the shell in your application directory:
1785
1786 % perl Makefile.PL
1787 % make catalyst_par
1788
1789Congratulations! Your package "myapp.par" is ready, the following
1790steps are just optional.
1791
17923. Test your PAR package with "parl" (no typo)
1793
1794 % parl myapp.par
1795 Usage:
1796 [parl] myapp[.par] [script] [arguments]
1797
1798 Examples:
1799 parl myapp.par myapp_server.pl -r
1800 myapp myapp_cgi.pl
1801
1802 Available scripts:
1803 myapp_cgi.pl
1804 myapp_create.pl
1805 myapp_fastcgi.pl
1806 myapp_server.pl
1807 myapp_test.pl
1808
1809 % parl myapp.par myapp_server.pl
1810 You can connect to your server at http://localhost:3000
1811
1812Yes, this nifty little starter application gets automatically included.
1813You can also use "catalyst_par_script('myapp_server.pl')" to set a
1814default script to execute.
1815
18166. Want to create a binary that includes the Perl interpreter?
1817
1818 % pp -o myapp myapp.par
1819 % ./myapp myapp_server.pl
1820 You can connect to your server at http://localhost:3000
1821
1822=head2 Serving static content
1823
1824Serving static content in Catalyst used to be somewhat tricky; the use
1825of L<Catalyst::Plugin::Static::Simple> makes everything much easier.
1826This plugin will automatically serve your static content during development,
1827but allows you to easily switch to Apache (or other server) in a
1828production environment.
1829
1830=head3 Introduction to Static::Simple
1831
1832Static::Simple is a plugin that will help to serve static content for your
1833application. By default, it will serve most types of files, excluding some
1834standard Template Toolkit extensions, out of your B<root> file directory. All
1835files are served by path, so if B<images/me.jpg> is requested, then
1836B<root/images/me.jpg> is found and served.
1837
1838=head3 Usage
1839
1840Using the plugin is as simple as setting your use line in MyApp.pm to include:
1841
1842 use Catalyst qw/Static::Simple/;
1843
1844and already files will be served.
1845
1846=head3 Configuring
1847
1848Static content is best served from a single directory within your root
1849directory. Having many different directories such as C<root/css> and
1850C<root/images> requires more code to manage, because you must separately
1851identify each static directory--if you decide to add a C<root/js>
1852directory, you'll need to change your code to account for it. In
1853contrast, keeping all static directories as subdirectories of a main
1854C<root/static> directory makes things much easier to manage. Here's an
1855example of a typical root directory structure:
1856
1857 root/
1858 root/content.tt
1859 root/controller/stuff.tt
1860 root/header.tt
1861 root/static/
1862 root/static/css/main.css
1863 root/static/images/logo.jpg
1864 root/static/js/code.js
1865
1866
1867All static content lives under C<root/static>, with everything else being
1868Template Toolkit files.
1869
1870=over 4
1871
1872=item Include Path
1873
1874You may of course want to change the default locations, and make
1875Static::Simple look somewhere else, this is as easy as:
1876
1877 MyApp->config->{static}->{include_path} = [
1878 MyApp->config->{root},
1879 '/path/to/my/files'
1880 ];
1881
1882When you override include_path, it will not automatically append the
1883normal root path, so you need to add it yourself if you still want
1884it. These will be searched in order given, and the first matching file
1885served.
1886
1887=item Static directories
1888
1889If you want to force some directories to be only static, you can set
1890them using paths relative to the root dir, or regular expressions:
1891
1892 MyApp->config->{static}->{dirs} = [
1893 'static',
1894 qr/^(images|css)/,
1895 ];
1896
1897=item File extensions
1898
1899By default, the following extensions are not served (that is, they will
1900be processed by Catalyst): B<tmpl, tt, tt2, html, xhtml>. This list can
1901be replaced easily:
1902
1903 MyApp->config->{static}->{ignore_extensions} = [
1904 qw/tmpl tt tt2 html xhtml/
1905 ];
1906
1907=item Ignoring directories
1908
1909Entire directories can be ignored. If used with include_path,
1910directories relative to the include_path dirs will also be ignored:
1911
1912 MyApp->config->{static}->{ignore_dirs} = [ qw/tmpl css/ ];
1913
1914=back
1915
1916=head3 More information
1917
1918L<http://search.cpan.org/dist/Catalyst-Plugin-Static-Simple/>
1919
1920=head3 Serving manually with the Static plugin with HTTP::Daemon (myapp_server.pl)
1921
1922In some situations you might want to control things more directly,
1923using L<Catalyst::Plugin::Static>.
1924
1925In your main application class (MyApp.pm), load the plugin:
1926
1927 use Catalyst qw/-Debug FormValidator Static OtherPlugin/;
1928
1929You will also need to make sure your end method does I<not> forward
1930static content to the view, perhaps like this:
1931
1932 sub end : Private {
1933 my ( $self, $c ) = @_;
1934
1935 $c->forward( 'MyApp::View::TT' )
1936 unless ( $c->res->body || !$c->stash->{template} );
1937 }
1938
1939This code will only forward to the view if a template has been
1940previously defined by a controller and if there is not already data in
1941C<$c-E<gt>res-E<gt>body>.
1942
1943Next, create a controller to handle requests for the /static path. Use
1944the Helper to save time. This command will create a stub controller as
1945C<lib/MyApp/Controller/Static.pm>.
1946
1947 $ script/myapp_create.pl controller Static
1948
1949Edit the file and add the following methods:
1950
1951 # serve all files under /static as static files
1952 sub default : Path('/static') {
1953 my ( $self, $c ) = @_;
1954
1955 # Optional, allow the browser to cache the content
1956 $c->res->headers->header( 'Cache-Control' => 'max-age=86400' );
1957
1958 $c->serve_static; # from Catalyst::Plugin::Static
1959 }
1960
1961 # also handle requests for /favicon.ico
1962 sub favicon : Path('/favicon.ico') {
1963 my ( $self, $c ) = @_;
1964
1965 $c->serve_static;
1966 }
1967
1968You can also define a different icon for the browser to use instead of
1969favicon.ico by using this in your HTML header:
1970
1971 <link rel="icon" href="/static/myapp.ico" type="image/x-icon" />
1972
1973=head3 Common problems with the Static plugin
1974
1975The Static plugin makes use of the C<shared-mime-info> package to
1976automatically determine MIME types. This package is notoriously
1977difficult to install, especially on win32 and OS X. For OS X the easiest
1978path might be to install Fink, then use C<apt-get install
1979shared-mime-info>. Restart the server, and everything should be fine.
1980
1981Make sure you are using the latest version (>= 0.16) for best
1982results. If you are having errors serving CSS files, or if they get
1983served as text/plain instead of text/css, you may have an outdated
1984shared-mime-info version. You may also wish to simply use the following
1985code in your Static controller:
1986
1987 if ($c->req->path =~ /css$/i) {
1988 $c->serve_static( "text/css" );
1989 } else {
1990 $c->serve_static;
1991 }
1992
1993=head3 Serving Static Files with Apache
1994
1995When using Apache, you can bypass Catalyst and any Static
1996plugins/controllers controller by intercepting requests for the
1997C<root/static> path at the server level. All that is required is to
1998define a DocumentRoot and add a separate Location block for your static
1999content. Here is a complete config for this application under mod_perl
20001.x:
2001
2002 <Perl>
2003 use lib qw(/var/www/MyApp/lib);
2004 </Perl>
2005 PerlModule MyApp
2006
2007 <VirtualHost *>
2008 ServerName myapp.example.com
2009 DocumentRoot /var/www/MyApp/root
2010 <Location />
2011 SetHandler perl-script
2012 PerlHandler MyApp
2013 </Location>
2014 <LocationMatch "/(static|favicon.ico)">
2015 SetHandler default-handler
2016 </LocationMatch>
2017 </VirtualHost>
2018
2019And here's a simpler example that'll get you started:
2020
2021 Alias /static/ "/my/static/files/"
2022 <Location "/static">
2023 SetHandler none
2024 </Location>
2025
2026=head2 Caching
2027
2028Catalyst makes it easy to employ several different types of caching to
2029speed up your applications.
2030
2031=head3 Cache Plugins
2032
2033There are three wrapper plugins around common CPAN cache modules:
2034Cache::FastMmap, Cache::FileCache, and Cache::Memcached. These can be
2035used to cache the result of slow operations.
2036
2037This very page you're viewing makes use of the FileCache plugin to cache the
2038rendered XHTML version of the source POD document. This is an ideal
2039application for a cache because the source document changes infrequently but
2040may be viewed many times.
2041
2042 use Catalyst qw/Cache::FileCache/;
2043
2044 ...
2045
2046 use File::stat;
2047 sub render_pod : Local {
2048 my ( self, $c ) = @_;
2049
2050 # the cache is keyed on the filename and the modification time
2051 # to check for updates to the file.
2052 my $file = $c->path_to( 'root', '2005', '11.pod' );
2053 my $mtime = ( stat $file )->mtime;
2054
2055 my $cached_pod = $c->cache->get("$file $mtime");
2056 if ( !$cached_pod ) {
2057 $cached_pod = do_slow_pod_rendering();
2058 # cache the result for 12 hours
2059 $c->cache->set( "$file $mtime", $cached_pod, '12h' );
2060 }
2061 $c->stash->{pod} = $cached_pod;
2062 }
2063
2064We could actually cache the result forever, but using a value such as 12 hours
2065allows old entries to be automatically expired when they are no longer needed.
2066
2067=head3 Page Caching
2068
2069Another method of caching is to cache the entire HTML page. While this is
2070traditionally handled by a front-end proxy server like Squid, the Catalyst
2071PageCache plugin makes it trivial to cache the entire output from
2072frequently-used or slow actions.
2073
2074Many sites have a busy content-filled front page that might look something
2075like this. It probably takes a while to process, and will do the exact same
2076thing for every single user who views the page.
2077
2078 sub front_page : Path('/') {
2079 my ( $self, $c ) = @_;
2080
2081 $c->forward( 'get_news_articles' );
2082 $c->forward( 'build_lots_of_boxes' );
2083 $c->forward( 'more_slow_stuff' );
2084
2085 $c->stash->{template} = 'index.tt';
2086 }
2087
2088We can add the PageCache plugin to speed things up.
2089
2090 use Catalyst qw/Cache::FileCache PageCache/;
2091
2092 sub front_page : Path ('/') {
2093 my ( $self, $c ) = @_;
2094
2095 $c->cache_page( 300 );
2096
2097 # same processing as above
2098 }
2099
2100Now the entire output of the front page, from <html> to </html>, will be
2101cached for 5 minutes. After 5 minutes, the next request will rebuild the
2102page and it will be re-cached.
2103
2104Note that the page cache is keyed on the page URI plus all parameters, so
2105requests for / and /?foo=bar will result in different cache items. Also,
2106only GET requests will be cached by the plugin.
2107
2108You can even get that front-end Squid proxy to help out by enabling HTTP
2109headers for the cached page.
2110
2111 MyApp->config->{page_cache}->{set_http_headers} = 1;
2112
2113This would now set the following headers so proxies and browsers may cache
2114the content themselves.
2115
2116 Cache-Control: max-age=($expire_time - time)
2117 Expires: $expire_time
2118 Last-Modified: $cache_created_time
2119
2120=head3 Template Caching
2121
2122Template Toolkit provides support for caching compiled versions of your
2123templates. To enable this in Catalyst, use the following configuration.
2124TT will cache compiled templates keyed on the file mtime, so changes will
2125still be automatically detected.
2126
2127 package MyApp::View::TT;
2128
2129 use strict;
2130 use warnings;
2131 use base 'Catalyst::View::TT';
2132
2133 __PACKAGE__->config(
2134 COMPILE_DIR => '/tmp/template_cache',
2135 );
2136
2137 1;
2138
2139=head3 More Info
2140
2141See the documentation for each cache plugin for more details and other
2142available configuration options.
2143
2144L<Catalyst::Plugin::Cache::FastMmap>
2145L<Catalyst::Plugin::Cache::FileCache>
2146L<Catalyst::Plugin::Cache::Memcached>
2147L<Catalyst::Plugin::PageCache>
2148L<http://search.cpan.org/dist/Template-Toolkit/lib/Template/Manual/Config.pod#Caching_and_Compiling_Options>
2149
2150=head1 Testing
2151
2152Testing is an integral part of the web application development
2153process. Tests make multi developer teams easier to coordinate, and
2154they help ensure that there are no nasty surprises after upgrades or
2155alterations.
2156
2157=head2 Testing
2158
2159Catalyst provides a convenient way of testing your application during
2160development and before deployment in a real environment.
2161
2162C<Catalyst::Test> makes it possible to run the same tests both locally
2163(without an external daemon) and against a remote server via HTTP.
2164
2165=head3 Tests
2166
2167Let's examine a skeleton application's C<t/> directory:
2168
2169 mundus:~/MyApp chansen$ ls -l t/
2170 total 24
2171 -rw-r--r-- 1 chansen chansen 95 18 Dec 20:50 01app.t
2172 -rw-r--r-- 1 chansen chansen 190 18 Dec 20:50 02pod.t
2173 -rw-r--r-- 1 chansen chansen 213 18 Dec 20:50 03podcoverage.t
2174
2175=over 4
2176
2177=item C<01app.t>
2178
2179Verifies that the application loads, compiles, and returns a successful
2180response.
2181
2182=item C<02pod.t>
2183
2184Verifies that all POD is free from errors. Only executed if the C<TEST_POD>
2185environment variable is true.
2186
2187=item C<03podcoverage.t>
2188
2189Verifies that all methods/functions have POD coverage. Only executed if the
2190C<TEST_POD> environment variable is true.
2191
2192=back
2193
2194=head3 Creating tests
2195
2196 mundus:~/MyApp chansen$ cat t/01app.t | perl -ne 'printf( "%2d %s", $., $_ )'
2197 1 use Test::More tests => 2;
2198 2 use_ok( Catalyst::Test, 'MyApp' );
2199 3
2200 4 ok( request('/')->is_success );
2201
2202The first line declares how many tests we are going to run, in this case
2203two. The second line tests and loads our application in test mode. The
2204fourth line verifies that our application returns a successful response.
2205
2206C<Catalyst::Test> exports two functions, C<request> and C<get>. Each can
2207take three different arguments:
2208
2209=over 4
2210
2211=item A string which is a relative or absolute URI.
2212
2213 request('/my/path');
2214 request('http://www.host.com/my/path');
2215
2216=item An instance of C<URI>.
2217
2218 request( URI->new('http://www.host.com/my/path') );
2219
2220=item An instance of C<HTTP::Request>.
2221
2222 request( HTTP::Request->new( GET => 'http://www.host.com/my/path') );
2223
2224=back
2225
2226C<request> returns an instance of C<HTTP::Response> and C<get> returns the
2227content (body) of the response.
2228
2229=head3 Running tests locally
2230
2231 mundus:~/MyApp chansen$ CATALYST_DEBUG=0 TEST_POD=1 prove --lib lib/ t/
2232 t/01app............ok
2233 t/02pod............ok
2234 t/03podcoverage....ok
2235 All tests successful.
2236 Files=3, Tests=4, 2 wallclock secs ( 1.60 cusr + 0.36 csys = 1.96 CPU)
2237
2238C<CATALYST_DEBUG=0> ensures that debugging is off; if it's enabled you
2239will see debug logs between tests.
2240
2241C<TEST_POD=1> enables POD checking and coverage.
2242
2243C<prove> A command-line tool that makes it easy to run tests. You can
2244find out more about it from the links below.
2245
2246=head3 Running tests remotely
2247
2248 mundus:~/MyApp chansen$ CATALYST_SERVER=http://localhost:3000/ prove --lib lib/ t/01app.t
2249 t/01app....ok
2250 All tests successful.
2251 Files=1, Tests=2, 0 wallclock secs ( 0.40 cusr + 0.01 csys = 0.41 CPU)
2252
2253C<CATALYST_SERVER=http://localhost:3000/> is the absolute deployment URI of
2254your application. In C<CGI> or C<FastCGI> it should be the host and path
2255to the script.
2256
2257=head3 C<Test::WWW::Mechanize> and Catalyst
2258
2259Be sure to check out C<Test::WWW::Mechanize::Catalyst>. It makes it easy to
2260test HTML, forms and links. A short example of usage:
2261
2262 use Test::More tests => 6;
2263 use_ok( Test::WWW::Mechanize::Catalyst, 'MyApp' );
2264
2265 my $mech = Test::WWW::Mechanize::Catalyst->new;
2266 $mech->get_ok("http://localhost/", 'Got index page');
2267 $mech->title_like( qr/^MyApp on Catalyst/, 'Got right index title' );
2268 ok( $mech->find_link( text_regex => qr/^Wiki/i ), 'Found link to Wiki' );
2269 ok( $mech->find_link( text_regex => qr/^Mailing-List/i ), 'Found link to Mailing-List' );
2270 ok( $mech->find_link( text_regex => qr/^IRC channel/i ), 'Found link to IRC channel' );
2271
2272=head3 Further Reading
2273
2274=over 4
2275
2276=item Catalyst::Test
2277
2278L<http://search.cpan.org/dist/Catalyst/lib/Catalyst/Test.pm>
2279
2280=item Test::WWW::Mechanize::Catalyst
2281
2282L<http://search.cpan.org/dist/Test-WWW-Mechanize-Catalyst/lib/Test/WWW/Mechanize/Catalyst.pm>
2283
2284=item Test::WWW::Mechanize
2285
2286L<http://search.cpan.org/dist/Test-WWW-Mechanize/Mechanize.pm>
2287
2288=item WWW::Mechanize
2289
2290L<http://search.cpan.org/dist/WWW-Mechanize/lib/WWW/Mechanize.pm>
2291
2292=item LWP::UserAgent
2293
2294L<http://search.cpan.org/dist/libwww-perl/lib/LWP/UserAgent.pm>
2295
2296=item HTML::Form
2297
2298L<http://search.cpan.org/dist/libwww-perl/lib/HTML/Form.pm>
2299
2300=item HTTP::Message
2301
2302L<http://search.cpan.org/dist/libwww-perl/lib/HTTP/Message.pm>
2303
2304=item HTTP::Request
2305
2306L<http://search.cpan.org/dist/libwww-perl/lib/HTTP/Request.pm>
2307
2308=item HTTP::Request::Common
2309
2310L<http://search.cpan.org/dist/libwww-perl/lib/HTTP/Request/Common.pm>
2311
2312=item HTTP::Response
2313
2314L<http://search.cpan.org/dist/libwww-perl/lib/HTTP/Response.pm>
2315
2316=item HTTP::Status
2317
2318L<http://search.cpan.org/dist/libwww-perl/lib/HTTP/Status.pm>
2319
2320=item URI
2321
2322L<http://search.cpan.org/dist/URI/URI.pm>
2323
2324=item Test::More
2325
2326L<http://search.cpan.org/dist/Test-Simple/lib/Test/More.pm>
2327
2328=item Test::Pod
2329
2330L<http://search.cpan.org/dist/Test-Pod/Pod.pm>
2331
2332=item Test::Pod::Coverage
2333
2334L<http://search.cpan.org/dist/Test-Pod-Coverage/Coverage.pm>
2335
2336=item prove (Test::Harness)
2337
2338L<http://search.cpan.org/dist/Test-Harness/bin/prove>
2339
2340=back
2341
2342=head3 More Information
2343
2344L<http://search.cpan.org/perldoc?Catalyst::Plugin::Authorization::Roles>
2345L<http://search.cpan.org/perldoc?Catalyst::Plugin::Authorization::ACL>
2346
2347=head1 AUTHORS
2348
2349Sebastian Riedel C<sri@oook.de>
2350
2351Danijel Milicevic C<me@danijel.de>
2352
2353Viljo Marrandi C<vilts@yahoo.com>
2354
2355Marcus Ramberg C<mramberg@cpan.org>
2356
2357Jesse Sheidlower C<jester@panix.com>
2358
2359Andy Grundman C<andy@hybridized.org>
2360
2361Chisel Wright C<pause@herlpacker.co.uk>
2362
2363Will Hawes C<info@whawes.co.uk>
2364
2365Gavin Henry C<ghenry@perl.me.uk>
2366
2367Kieren Diment C<kd@totaldatasolution.com>
2368
2369=head1 COPYRIGHT
2370
2371This document is free, you can redistribute it and/or modify it
2372under the same terms as Perl itself.
2373