Catalyst is a Perl module that contains the elegant MVC web application framework.
SYNOPSIS
See the Catalyst::Manual distribution for comprehensive documentation and tutorials.
# Install Catalyst::Devel for helpers and other development tools
# use the helper to create a new application
catalyst.pl MyApp
# add models, views, controllers
script/myapp_create.pl model MyDatabase DBIC::Schema create=dynamic dbi:SQLite:/path/to/db
script/myapp_create.pl view MyTemplate TT
script/myapp_create.pl controller Search
# built in testserver -- use -r to restart automatically on changes
# --help to see all available options
script/myapp_server.pl
# command line testing interface
script/myapp_test.pl /yada
### in lib/MyApp.pm
use Catalyst qw/-Debug/; # include plugins here as well
### In lib/MyApp/Controller/Root.pm (autocreated)
sub foo : Global { # called for /foo, /foo/1, /foo/1/2, etc.
my ( $self, $c, @args ) = @_; # args are qw/1 2/ for /foo/1/2
$c->stash->{template} = 'foo.tt'; # set the template
# lookup something from db -- stash vars are passed to TT
$c->stash->{data} =
$c->model('Database::Foo')->search( { country => $args[0] } );
if ( $c->req->params->{bar} ) { # access GET or POST parameters
$c->forward( 'bar' ); # process another action
# do something else after forward returns
}
}
# The foo.tt TT template can use the stash data from the database
[% WHILE (item = data.next) %]
[% item.foo %]
[% END %]
# called for /bar/of/soap, /bar/of/soap/10, etc.
sub bar : Path('/bar/of/soap') { ... }
# called for all actions, from the top-most controller downwards
sub auto : Private {
my ( $self, $c ) = @_;
if ( !$c->user_exists ) { # Catalyst::Plugin::Authentication
$c->res->redirect( '/login' ); # require login
return 0; # abort request and go immediately to end()
}
return 1; # success; carry on to next action
}
# called after all actions are finished
sub end : Private {
my ( $self, $c ) = @_;
if ( scalar @{ $c->error } ) { ... } # handle errors
return if $c->res->body; # already have a response
$c->forward( 'MyApp::View::TT' ); # render template
}
### in MyApp/Controller/Foo.pm
# called for /foo/bar
sub bar : Local { ... }
# called for /blargle
sub blargle : Global { ... }
# an index action matches /foo, but not /foo/1, etc.
sub index : Private { ... }
### in MyApp/Controller/Foo/Bar.pm
# called for /foo/bar/baz
sub baz : Local { ... }
# first Root auto is called, then Foo auto, then this
sub auto : Private { ... }
# powerful regular expression paths are also possible
sub details : Regex('^product/(w+)/details$') {
my ( $self, $c ) = @_;
# extract the (w+) from the URI
my $product = $c->req->captures->[0];
}
Product's homepage
Requirements:
· Perl
What's New in This Release: [ read full changelog ]
· The FCGI script wiil be able to set the process title.
· Chained dispatch has been modified to always prefer paths with the minimum number of captures There were several bugfixes.