Catalyst Tutorial Notes
Notes on the Catalyst Tutorial
Contents
Install Task::Catalyst::Tutorial
Example applications can be found at Catalyst Repository Example Applications (see also: Catalyst Wiki)
MVC
Top BottomMVC is a design pattern keeping the three main areas of an application seperate, so that anyone can be replaced without affecting the other. The three areas are:
- Model: Schematic description of the data
- View: presentation layer
- Controller: program logic connecting data to view
Create Project
Top Bottomuse 'catalyst.pl MyApp' to initialise the application framework - creates MyApp directory and subdirectories required for the project
Start the server with script/myapp_server.pl. Options include:
- -r : restarts the server automatically when controllors change
- -d : starts the server in debug mode - displays lots of information on actions
The Application Class
Top Bottomlib/MyApp.pm
Contains the list of plugins/flags in use by the application. Defaults are -Debug (flag); Catalyst::Plugin::ConfigLoader (provides automatic loader of configuration parameters; Catalyst::Plugin::Static::Simple (provides services for static content, eg CSS and images). Additional Plugins: Catalyst::Plugin::StackTrace (sends errors to the browser); Catalyst::Model::DBI (access databases through traditional DBI interface; Class::DBI (traditional perl ORM engine, providing model objects for relational databases); DBIx::Class (preferred ORM engine).
The Model
Top Bottomuse the Catalyst::Helper::Model::DBIC::Schema helper script to create the model class:
script/myapp_create.pl model MyAppDB DBIC::Schema MyAppDB dbi:SQLite:myapp.db '' '' '{AutoCommit => 1}'where the first 'MyAppDB' is the name of the class to be created (in lib/MyApp/Model) and the second is the name of the schema file to be used to create the model (lib/MyAppDB.pm)
The Controller
Top BottomControllers contain methods that interact with user input. To create a controller for book-related actions:
script/myapp_create.pl controller Books
The View
Top BottomUse the Catalyst::Helper::View::TT or Catalyst::Helper::View::TTSite helper script to create the View:
script/myapp_create.pl view TT TTSite
