=head1 NAME Catalyst::Manual::Tutorial::02_CatalystBasics - Catalyst Tutorial - Chapter 2: Catalyst Application Development Basics =head1 OVERVIEW This is B for the Catalyst tutorial. L =over 4 =item 1 L =item 2 B<02_Catalyst Basics> =item 3 L =item 4 L =item 5 L =item 6 L =item 7 L =item 8 L =item 9 L =item 10 L =back =head1 DESCRIPTION In this chapter of the tutorial, we will create a very basic Catalyst web application, demonstrating a number of powerful capabilities, such as: =over 4 =item * Helper Scripts Catalyst helper scripts that can be used to rapidly bootstrap the skeletal structure of an application. =item * MVC 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 L). In short: =over 4 =item * Model 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. =item * View 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. =item * Controller As suggested by its name, the controller takes user requests and routes them to the necessary model and view. =back =item * ORM 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. =back You can checkout the source code for this example from the catalyst subversion repository as per the instructions in L. =head1 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 C helper (see L for more information on helpers). Also note that as of Catalyst 5.7000, you will not have the helper scripts unless you install both L and L. In this first chapter of the tutorial, use the Catalyst C script to initialize the framework for an application called C: $ 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 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". The C helper script will display the names of the directories and files it creates: Changes # Record of application changes lib # Lib directory for your app's 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 Catalyst will "auto-discover" modules in the Controller, Model, and View directories. When you use the hello_create.pl 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". 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. Run the following command to start up the built-in development web server (make sure you didn't forget the "C" from the previous step): B: The "-r" argument enables reloading on code changes so you don't have to stop and start the server when you update code. See C or C