sub action2 : Private { ... } $str = $req->referer Quick Reference Card only accessible within application via forward method $str = $req->secure Revision 0.06 for Catalyst version 5.30 sub action3 : Path(’path’) { ... } $str = $req->snippets Andrew Ford literal action matches specified URL $str = $req->upload refcards.comTM sub action4 : Regex(’regex’) { ... } $href = $req->uploads Catalyst is an elegant web application framework written in globally matches URLs that match regex $str = $req->uri (see catalyst.perl.org and the Catalyst module on CPAN). There are four built-in private actions: $str = $req->user $str = $req->user_agent The information in this refcard is abbreviated and simplified – re- sub begin : Private { ... } fer to the documentation for full details. called at start of request before matching actions Response methods sub auto : Private { ... } Creating a Catalyst Application $resp = $c->response Catalyst includes a helper script to bootstrap a new application: special action run after begin in each class from app down sub default : Private { ... } $str = $resp->body([$str]) $ catalyst.pl My::App called if no other action matches $str = $resp->content_encoding([$str]) sub end : Private { ... } $str = $resp->content_length([$str]) This creates a application directory My-App with skeleton module, called at end of request after all matching actions $str = $resp->content_type([$str]) build, and test files and a number of helper scripts, including one $href = $resp->cookies to launch a test server: Context methods $str = $resp->header([$name [=> $value]]) Each action subroutine is invoked with two parameters – the $href = $resp->headers $ cd My-App component object reference or class name and a context object $str = $resp->output([$str]) # alias for $resp->body $ script/my_app_server.pl (conventionally designated $c). [ [ ]] ... $str = $resp->redirect( $location , $status ) You can connect to your server at http://host.domain:3000/ $obj = $c->config $val = $resp->status([$status]) $c->forward($action [, @args]) $obj = $c->log([$newobj]) Log methods Application Structure $obj = $c->plugin($name, $class, @args) $log = $c->log The generated application module is structured like this (with $req = $c->request # or $c->req $log->levels(@levels) comments and documentation omitted for brevity): $resp = $c->response # or $c->res $log->enable(@levels) $href = $c->stash $log->disable(@levels) package My::App; $bool = $log->is_debug use Catalyst qw/-Debug/; Methods for plugin writers $log->debug($message) $obj = $c->dispatcher $bool = $log->is_info My::App->config( name => ’My::App’ ); $obj = $c->engine $log->info($message) My::App->setup; $aref = $c->get_action($name, $namespace, $inherit) $bool = $log->is_warn $log->warn($message) sub default : Private { Request methods $bool = $c->is_error my ( $self, $c ) = @_; $req = $c->request # or $c->req $c->res->output(’Congratulations, ’ . $log->error($message) ’My::App is on Catalyst!’); $str = $req->action $bool = $log->is_fatal } $str = $req->address $log->fatal($message) $str = $req->arguments # or $req->args Catalyst loads any component modules it finds within the subdi- $str = $req->base Utility Functions (Catalyst::Utils) rectories: M (or Model), V (or View), or C (or Controller). $str = $req->body $aref = attrs($coderef) catalyst.pl creates another helper script for generating skeleton $str = $req->content_encoding $str = class2appclass($class) components modules: $str = $req->content_length $str = class2classprefix($class) $str = $req->content_type $str = class2classsuffix($class) $ script/my_app_create.pl {M|V|C} Class \ $str = $req->cookie($name) $str = class2env($class) [helper arg ...] @ary = $req->cookies $str = class2prefix($class) $str = $req->header $str = class2tempdir($class [, $create]) Actions $str = $req->headers $str = home($class) The behaviour of a Catalyst application is defined by its actions, $str = $req->hostname $str = prefix($class, $action) subroutines marked with attributes defined in the application or $str = $req->input $str = reflect_actions($class) component modules: $str = $req->match $str = request($str) sub action1 : Global { ... } $str = $req->method $val = $req->param([$name]) top-level action mapped to application base URL Plugins sub action2 : Local { ... } $href = $req->parameters # or $req->params ‘namespace-prefixed’ – sub name prefixed by component $str = $req->path URL $str = $req->protocol 1 2 3 A refcards.comTM quick reference card. refcards.com is a trademark of Ford & Ltd. Published by Ford & Mason Ltd. © 2005 Andrew Ford and Ford & Mason Ltd. All rights reserved. Permission is granted to print and duplicate this card for personal or individual, internal business use. Download from refcards.com.

Catalyst Quick Reference Card Revision 0.06 for Catalyst version 5.30 [July 2005]

4 5 6