.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Catalyst::Manual::Tutorial::02_CatalystBasics 3pm" .TH Catalyst::Manual::Tutorial::02_CatalystBasics 3pm 2024-03-30 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Catalyst::Manual::Tutorial::02_CatalystBasics \- Catalyst Tutorial \- Chapter 2: Catalyst Application Development Basics .SH OVERVIEW .IX Header "OVERVIEW" This is \fBChapter 2 of 10\fR for the Catalyst tutorial. .PP Tutorial Overview .IP 1. 4 Introduction .IP 2. 4 \&\fB02_Catalyst Basics\fR .IP 3. 4 More Catalyst Basics .IP 4. 4 Basic CRUD .IP 5. 4 Authentication .IP 6. 4 Authorization .IP 7. 4 Debugging .IP 8. 4 Testing .IP 9. 4 Advanced CRUD .IP 10. 4 Appendices .SH DESCRIPTION .IX Header "DESCRIPTION" In this chapter of the tutorial, we will create a very basic Catalyst web application, demonstrating a number of powerful capabilities, such as: .IP \(bu 4 Helper Scripts .Sp Catalyst helper scripts that can be used to rapidly bootstrap the skeletal structure of an application. .IP \(bu 4 MVC .Sp Model/View/Controller (MVC) provides an architecture that facilitates a clean "separation of control" between the different portions of your application. Given that many other documents cover this subject in detail, MVC will not be discussed in depth here (for an excellent introduction to MVC and general Catalyst concepts, please see Catalyst::Manual::About). In short: .RS 4 .IP \(bu 4 Model .Sp The model usually represents a data store. In most applications, the model equates to the objects that are created from and saved to your SQL database. .IP \(bu 4 View .Sp The view takes model objects and renders them into something for the end user to look at. Normally this involves a template-generation tool that creates HTML for the user's web browser, but it could easily be code that generates other forms such as PDF documents, e\-mails, spreadsheets, or even "behind the scenes" formats such as XML and JSON. .IP \(bu 4 Controller .Sp As suggested by its name, the controller takes user requests and routes them to the necessary model and view. .RE .RS 4 .RE .IP \(bu 4 ORM .Sp The use of Object-Relational Mapping (ORM) technology for database access. Specifically, ORM provides an automated and standardized means to persist and restore objects to/from a relational database and will automatically create our Catalyst model for use with a database. .PP You can checkout the source code for this example from the catalyst subversion repository as per the instructions in Catalyst::Manual::Tutorial::01_Intro. .SH "CREATE A CATALYST PROJECT" .IX Header "CREATE A CATALYST PROJECT" Catalyst provides a number of helper scripts that can be used to quickly flesh out the basic structure of your application. All Catalyst projects begin with the \fIcatalyst.pl\fR helper (see Catalyst::Helper for more information on helpers). Also note that as of Catalyst 5.7000, you will not have the helper scripts unless you install both Catalyst::Runtime and Catalyst::Devel. .PP In this first chapter of the tutorial, use the Catalyst \fIcatalyst.pl\fR script to initialize the framework for an application called \f(CW\*(C`Hello\*(C'\fR: .PP .Vb 9 \& $ catalyst.pl Hello \& created "Hello" \& created "Hello/script" \& created "Hello/lib" \& created "Hello/root" \& ... \& created "Hello/script/hello_create.pl" \& Change to application directory and Run "perl Makefile.PL" to make sure your install is complete \& $ cd Hello .Ve .PP Note: If you are using Strawberry Perl on Win32, drop the ".pl" from the end of the "catalyst.pl" command and simply use "catalyst Hello". .PP The \fIcatalyst.pl\fR helper script will display the names of the directories and files it creates: .PP .Vb 10 \& Changes # Record of application changes \& lib # Lib directory for your app\*(Aqs Perl modules \& Hello # Application main code directory \& Controller # Directory for Controller modules \& Model # Directory for Models \& View # Directory for Views \& Hello.pm # Base application module \& Makefile.PL # Makefile to build application \& hello.conf # Application configuration file \& README # README file \& root # Equiv of htdocs, dir for templates, css, javascript \& favicon.ico \& static # Directory for static files \& images # Directory for image files used in welcome screen \& script # Directory for Perl scripts \& hello_cgi.pl # To run your app as a cgi (not recommended) \& hello_create.pl # To create models, views, controllers \& hello_fastcgi.pl # To run app as a fastcgi program \& hello_server.pl # The normal development server \& hello_test.pl # Test your app from the command line \& t # Directory for tests \& 01app.t # Test scaffold \& 02pod.t \& 03podcoverage.t .Ve .PP Catalyst will "auto-discover" modules in the Controller, Model, and View directories. When you use the \fIhello_create.pl\fR script it will create Perl module scaffolds in those directories, plus test files in the "t" directory. The default location for templates is in the "root" directory. The scripts in the script directory will always start with the lowercased version of your application name. If your app is MaiTai, then the create script would be "maitai_create.pl". .PP Though it's too early for any significant celebration, we already have a functioning application. We can use the Catalyst supplied script to start up a development server and view the default Catalyst page in your browser. All scripts in the script directory should be run from the base directory of your application, so change to the Hello directory. .PP Run the following command to start up the built-in development web server (make sure you didn't forget the "\f(CW\*(C`cd Hello\*(C'\fR" from the previous step): .PP \&\fBNote\fR: The "\-r" argument enables reloading on code changes so you don't have to stop and start the server when you update code. See \&\f(CW\*(C`perldoc script/hello_server.pl\*(C'\fR or \f(CW\*(C`script/hello_server.pl \-\-help\*(C'\fR for additional options you might find helpful. Most of the rest of the tutorial will assume that you are using "\-r" when you start the development server, but feel free to manually start and stop it (use \&\f(CW\*(C`Ctrl\-C\*(C'\fR to breakout of the dev server) if you prefer. .PP .Vb 7 \& $ script/hello_server.pl \-r \& [debug] Debug messages enabled \& [debug] Statistics enabled \& [debug] Loaded plugins: \& .\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-. \& | Catalyst::Plugin::ConfigLoader 0.30 | \& \*(Aq\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\*(Aq \& \& [debug] Loaded dispatcher "Catalyst::Dispatcher" \& [debug] Loaded engine "Catalyst::Engine" \& [debug] Found home "/home/catalyst/Hello" \& [debug] Loaded Config "/home/catalyst/Hello/hello.conf" \& [debug] Loaded components: \& .\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-. \& | Class | Type | \& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-+ \& | Hello::Controller::Root | instance | \& \*(Aq\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\*(Aq \& \& [debug] Loaded Private actions: \& .\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-. \& | Private | Class | Method | \& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-+ \& | /default | Hello::Controller::Root | default | \& | /end | Hello::Controller::Root | end | \& | /index | Hello::Controller::Root | index | \& \*(Aq\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\*(Aq \& \& [debug] Loaded Path actions: \& .\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-. \& | Path | Private | \& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+ \& | / | /index | \& | / | /default | \& \*(Aq\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\*(Aq \& \& [info] Hello powered by Catalyst 5.90002 \& HTTP::Server::PSGI: Accepting connections at http://0:3000/ .Ve .PP Point your web browser to (substituting a different hostname or IP address as appropriate) and you should be greeted by the Catalyst welcome screen (if you get some other welcome screen or an "Index" screen, you probably forgot to specify port 3000 in your URL). Information similar to the following should be appended to the logging output of the development server: .PP .Vb 10 \& [info] Hello powered by Catalyst 5.90002 \& HTTP::Server::PSGI: Accepting connections at http://0:3000/ \& [info] *** Request 1 (0.067/s) [19026] [Tue Aug 30 17:24:32 2011] *** \& [debug] "GET" request for "/" from "192.168.245.2" \& [debug] Path is "/" \& [debug] Response Code: 200; Content\-Type: text/html; charset=utf\-8; Content\-Length: 5613 \& [info] Request took 0.040895s (24.453/s) \& .\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-. \& | Action | Time | \& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-+ \& | /index | 0.000916s | \& | /end | 0.000877s | \& \*(Aq\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\*(Aq .Ve .PP \&\fBNote\fR: Press \f(CW\*(C`Ctrl\-C\*(C'\fR to break out of the development server if necessary. .SH "HELLO WORLD" .IX Header "HELLO WORLD" .SS "The Simplest Way" .IX Subsection "The Simplest Way" The Root.pm controller is a place to put global actions that usually execute on the root URL. Open the \fIlib/Hello/Controller/Root.pm\fR file in your editor. You will see the "index" subroutine, which is responsible for displaying the welcome screen that you just saw in your browser. .PP .Vb 2 \& sub index :Path :Args(0) { \& my ( $self, $c ) = @_; \& \& # Hello World \& $c\->response\->body( $c\->welcome_message ); \& } .Ve .PP Later on you'll want to change that to something more reasonable, such as a "404" message or a redirect, but for now just leave it alone. .PP The "\f(CW$c\fR" here refers to the Catalyst context, which is used to access the Catalyst application. In addition to many other things, the Catalyst context provides access to "response" and "request" objects. (See Catalyst::Runtime, Catalyst::Response, and Catalyst::Request) .PP \&\f(CW\*(C`$c\->response\->body\*(C'\fR sets the HTTP response (see Catalyst::Response), while \&\f(CW\*(C`$c\->welcome_message\*(C'\fR is a special method that returns the welcome message that you saw in your browser. .PP The "\f(CW\*(C`:Path :Args(0)\*(C'\fR" after the method name are attributes which determine which URLs will be dispatched to this method. (You might see ":Private" if you are using an older version of Catalyst, but using that with "default" or "index" is currently deprecated. If so, you should also probably upgrade before continuing the tutorial.) .PP Some MVC frameworks handle dispatching in a central place. Catalyst, by policy, prefers to handle URL dispatching with attributes on controller methods. There is a lot of flexibility in specifying which URLs to match. This particular method will match all URLs, because it doesn't specify the path (nothing comes after "Path"), but will only accept a URL without any args because of the "\f(CW:Args(0)\fR". .PP The default is to map URLs to controller names, and because of the way that Perl handles namespaces through package names, it is simple to create hierarchical structures in Catalyst. This means that you can create controllers with deeply nested actions in a clean and logical way. For example, the URL \f(CW\*(C`http://hello.com/admin/articles/create\*(C'\fR maps to the package \f(CW\*(C`Hello::Controller::Admin::Articles\*(C'\fR, and the \f(CW\*(C`create\*(C'\fR method. .PP While you leave the \f(CW\*(C`script/hello_server.pl \-r\*(C'\fR command running the development server in one window (don't forget the "\-r" at the end!), open another window and add the following subroutine to your \&\fIlib/Hello/Controller/Root.pm\fR file: .PP .Vb 2 \& sub hello :Global { \& my ( $self, $c ) = @_; \& \& $c\->response\->body("Hello, World!"); \& } .Ve .PP \&\fBTIP\fR: See Appendix 1 for tips on removing the leading spaces when cutting and pasting example code from POD-based documents. .PP Notice in the window running the Development Server that you should get output similar to the following: .PP .Vb 2 \& Saw changes to the following files: \& \- /home/catalyst/Hello/lib/Hello/Controller/Root.pm (modify) \& \& Attempting to restart the server \& ... \& [debug] Loaded Private actions: \& .\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-. \& | Private | Class | Method | \& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-+ \& | /default | Hello::Controller::Root | default | \& | /end | Hello::Controller::Root | end | \& | /index | Hello::Controller::Root | index | \& | /hello | Hello::Controller::Root | hello | \& \*(Aq\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\*(Aq \& ... .Ve .PP The development server noticed the change in \f(CW\*(C`Hello::Controller::Root\*(C'\fR and automatically restarted itself. .PP Go to to see "Hello, World!". Also notice that the newly defined 'hello' action is listed under "Loaded Private actions" in the development server debug output. .SS "Hello, World! Using a View and a Template" .IX Subsection "Hello, World! Using a View and a Template" In the Catalyst world a "View" itself is not a page of XHTML or a template designed to present a page to a browser. Rather, it is the module that determines the \fItype\fR of view \-\- HTML, PDF, XML, etc. For the thing that generates the \fIcontent\fR of that view (such as a Template Toolkit template file), the actual templates go under the "root" directory. .PP To create a TT view, run: .PP .Vb 1 \& $ script/hello_create.pl view HTML TT .Ve .PP This creates the \fIlib/Hello/View/HTML.pm\fR module, which is a subclass of Catalyst::View::TT. .IP \(bu 4 The "view" keyword tells the create script that you are creating a view. .IP \(bu 4 The first argument "HTML" tells the script to name the View module "HTML.pm", which is a commonly used name for TT views. You can name it anything you want, such as "MyView.pm". If you have more than one view, be sure to set the default_view in Hello.pm (See Catalyst::View::TT for more details on setting this). .IP \(bu 4 The final "TT" tells Catalyst the \fItype\fR of the view, with "TT" indicating that you want to use a Template Toolkit view. .PP If you look at \fIlib/Hello/View/HTML.pm\fR you will find that it only contains a config statement to set the TT extension to ".tt". .PP Now that the HTML.pm "View" exists, Catalyst will autodiscover it and be able to use it to display the view templates using the "process" method that it inherits from the Catalyst::View::TT class. .PP Template Toolkit is a very full-featured template facility, with excellent documentation at , but since this is not a TT tutorial, we'll stick to only basic TT usage here (and explore some of the more common TT features in later chapters of the tutorial). .PP Create a \fIroot/hello.tt\fR template file (put it in the \f(CW\*(C`root\*(C'\fR under the \&\f(CW\*(C`Hello\*(C'\fR directory that is the base of your application). Here is a simple sample: .PP .Vb 3 \&

\& This is a TT view template, called \*(Aq[% template.name %]\*(Aq. \&

.Ve .PP [% and %] are markers for the TT parts of the template. Inside you can access Perl variables and classes, and use TT directives. In this case, we're using a special TT variable that defines the name of the template file (\fIhello.tt\fR). The rest of the template is normal HTML. .PP Change the hello method in \fIlib/Hello/Controller/Root.pm\fR to the following: .PP .Vb 2 \& sub hello :Global { \& my ( $self, $c ) = @_; \& \& $c\->stash(template => \*(Aqhello.tt\*(Aq); \& } .Ve .PP This time, instead of doing \f(CW\*(C`$c\->response\->body()\*(C'\fR, you are setting the value of the "template" hash key in the Catalyst "stash", an area for putting information to share with other parts of your application. The "template" key determines which template will be displayed at the end of the request cycle. Catalyst controllers have a default "end" action for all methods which causes the first (or default) view to be rendered (unless there's a \f(CW\*(C`$c\->response\->body()\*(C'\fR statement). So your template will be magically displayed at the end of your method. .PP After saving the file, the development server should automatically restart (again, the tutorial is written to assume that you are using the "\-r" option \-\- manually restart it if you aren't), and look at in your web browser again. You should see the template that you just created. .PP \&\fBTIP:\fR If you keep the server running with "\-r" in a "background window," don't let that window get totally hidden... if you have a syntax error in your code, the debug server output will contain the error information. .PP \&\fBNote:\fR You will probably run into a variation of the "stash" statement above that looks like: .PP .Vb 1 \& $c\->stash\->{template} = \*(Aqhello.tt\*(Aq; .Ve .PP Although this style is still relatively common, the approach we used previous is becoming more common because it allows you to set multiple stash variables in one line. For example: .PP .Vb 2 \& $c\->stash(template => \*(Aqhello.tt\*(Aq, foo => \*(Aqbar\*(Aq, \& another_thing => 1); .Ve .PP You can also set multiple stash values with a hashref: .PP .Vb 2 \& $c\->stash({template => \*(Aqhello.tt\*(Aq, foo => \*(Aqbar\*(Aq, \& another_thing => 1}); .Ve .PP Any of these formats work, but the \f(CW\*(C`$c\->stash(name => value);\*(C'\fR style is growing in popularity \-\- you may wish to use it all the time (even when you are only setting a single value). .SH "CREATE A SIMPLE CONTROLLER AND AN ACTION" .IX Header "CREATE A SIMPLE CONTROLLER AND AN ACTION" Create a controller named "Site" by executing the create script: .PP .Vb 1 \& $ script/hello_create.pl controller Site .Ve .PP This will create a \fIlib/Hello/Controller/Site.pm\fR file (and a test file). If you bring Site.pm up in your editor, you can see that there's not much there to see. .PP In \fIlib/Hello/Controller/Site.pm\fR, add the following method: .PP .Vb 2 \& sub test :Local { \& my ( $self, $c ) = @_; \& \& $c\->stash(username => \*(AqJohn\*(Aq, \& template => \*(Aqsite/test.tt\*(Aq); \& } .Ve .PP Notice the "Local" attribute on the \f(CW\*(C`test\*(C'\fR method. This will cause the \&\f(CW\*(C`test\*(C'\fR action (now that we have assigned an "action type" to the method it appears as a "controller action" to Catalyst) to be executed on the "controller/method" URL, or, in this case, "site/test". We will see additional information on controller actions throughout the rest of the tutorial, but if you are curious take a look at "Actions" in Catalyst::Manual::Intro. .PP It's not actually necessary to set the template value as we do here. By default TT will attempt to render a template that follows the naming pattern "controller/method.tt", and we're following that pattern here. However, in other situations you will need to specify the template (such as if you've "forwarded" to the method, or if it doesn't follow the default naming convention). .PP We've also put the variable "username" into the stash, for use in the template. .PP Make a subdirectory "site" in the "root" directory. .PP .Vb 1 \& $ mkdir root/site .Ve .PP Create a new template file in that directory named \fIroot/site/test.tt\fR and include a line like: .PP .Vb 1 \&

Hello, [% username %]!

.Ve .PP Once the server automatically restarts, notice in the server output that \&\f(CW\*(C`/site/test\*(C'\fR is listed in the Loaded Path actions. Go to in your browser and you should see your test.tt file displayed, including the name "John" that you set in the controller. .PP You can jump to the next chapter of the tutorial here: More Catalyst Basics .SH AUTHORS .IX Header "AUTHORS" Gerda Shank, \f(CW\*(C`gerda.shank@gmail.com\*(C'\fR Kennedy Clark, \f(CW\*(C`hkclark@gmail.com\*(C'\fR .PP Feel free to contact the author for any errors or suggestions, but the best way to report issues is via the CPAN RT Bug system at . .PP Copyright 2006\-2011, Kennedy Clark, under the Creative Commons Attribution Share-Alike License Version 3.0 ().