=head1 Running CGI Scripts Under Catalyst It is possible to run most CGI scripts under Catalyst using the modules L and L. Why would you want to do this? Assuming you have a legacy CGI application, you may want to: =over 4 =item * integrate and package a CGI script into your Catalyst application, so you can (for example) use the Catalyst Authentication framework. =item * have a Perl CGI script compiled on startup and cached, as with L, but in a FastCGI environment rather than with mod_perl under Apache. =back port a simple mod_perl application to Catalyst. =head2 An Example Let's get the wwwboard application from the NMS project (L) running under L. We'll call the L application C. First, make a C directory in your app, then copy the file C there. Put the files C and C into C. Edit the configuration block in C to: $basedir = WWWBoard->path_to('root/static'); $baseurl = 'http://localhost:3000/'; $cgi_url = 'http://localhost:3000/cgi-bin/wwwboard.pl'; Next, make a Controller for running your CGIs: package WWWBoard::Controller::Board; use strict; use warnings; use parent 'Catalyst::Controller::CGIBin'; 1; Tell Static::Simple to not ignore C<.html> files in C: __PACKAGE__->config( name => 'WWWBoard', static => { ignore_extensions => [ 'tt' ], }, ); Rewire some URLs to the files the CGI will generate in C: __PACKAGE__->config->{namespace} = ''; sub index : Path Args(0) { my ($self, $c) = @_; $c->serve_static_file($c->path_to('/root/static/wwwboard.html')); } sub board_html : Path('wwwboard.html') Args(0) { my ($self, $c) = @_; $c->serve_static_file($c->path_to('/root/static/wwwboard.html')); } sub faq_html : Path('faq.html') Args(0) { my ($self, $c) = @_; $c->serve_static_file($c->path_to('/root/static/faq.html')); } sub messages :Local Args { my ($self, $c, @args) = @_; $c->serve_static_file($c->path_to('/root/static/messages', @args)); } Start the server, and you will be taken to a functional message board. Even non-Perl CGIs will work, but of course these will not be pre-compiled. =head2 Porting mod_perl Apps The CGI environment is a bit closer to mod_perl than the regular L Controller environment, e.g. you can print to C. The first step would be to rewrite your handler sub to take C<$c> instead of C<$r> as a parameter, and replace the Apache request methods with the equivalent L framework methods. Replacing things like L with L is also fairly trivial. Then your URL handler would look like: use parent 'Catalyst::Controller::WrapCGI'; require My::ModPerl::Handler; sub my_handler : Local { my ($self, $c, @args) = @_; $self->cgi_to_response($c, sub { My::ModPerl::Handler::handler($c); }); } =head2 Other Examples Justin Hunter (arcanez) has gotten the Movable Type blogging software running under Catalyst. It is available here: L. Hans Dieter Pearcey (confound) has gotten the Bugzilla bug-tracking project running under Catalyst. It is available here: L. =head1 AUTHOR Caelum: Rafael Kitover