Linux Web Development With Perl and Catalyst MVC Framework

Share Button
Catalyst MVC Framework with Perl

Catalyst MVC Framework with Perl

What is Development with the Catalyst Framework?

This article was written a little while ago in an Article for Linux Journal, about An Intro To Application Development, and it intrigued me on Web Development with the Catalyst Perl MVC Framework.  Now Perl may not be your best bet for all your Web Development solutions, it can be used as an Object Oriented solution for your web pages and apps. Sure HTML5, CSS3, JavaScript, PHP, MySQL are the most popular app and web development solutions today, but it’s always fun to learn new things. So I wanted to learn a little more about this overlooked Web Development Topic.

Perl for Web Development

This thread of StackOverflow, has someone asking the Question, Should I Learn Perl As A Web Developer, that obviously will make a few developers scratch their head and give a snide remark or two.  Debates on StackOverflow can get quite heated at times. Don’t criticize something when you may not know much about it.  Learn more.

How To For Web Development

Here is an article by Henry Van Styn of Intellitree.com on Linux How To’s for Web Development.  Check it out for yourself.  I don’t want to take the entire article so I will try and leave you with a few of the good points and you can visit it for yourself here,  Introduction to App Development with Catalyst and Perl.  Some may say this may not be your best solution, but you should look into broadening your Programming skills with Python, Ruby on Rails, and Perl.  Along with Linux, Apache, MySQL, PHP, JavaScript, etc.  StackOverFlow is always a great place to ask your programming questions.

Here is a little How To from that Article from Henry Van Styn of Intellitree Solutions.  

Linux Planet

Linux Planet

Catalyst Application Layout

Every Catalyst application is a Perl module/library/bundle—exactly like the modules on CPAN. This consists of a package/class namespace and standard structure of files and directories. The Catalyst::Devel package comes with a helper script to create new “skeleton” applications and to initialize the files and directories for you. For example, to create a new application called KillerApp, run the following:

catalyst.pl KillerApp

This creates a new application structure at KillerApp/ with the following subdirectories:

lib/: this is the Perl include directory that stores all the Perl classes (aka packages or modules) for the application. This is added to the Perl lib path at runtime, and the directory structure corresponds to the package/class namespaces. For example, the two classes that are initially created have the following namespaces and corresponding file paths:

  • KillerApp — lib/KillerApp.pm
  • KillerApp::Controller::Root — lib/KillerApp/Controller/Root.pm

These directories also are created but initially are empty:

  • lib/KillerApp/Model/
  • lib/KillerApp/View/

root/: this is where other kinds application-specific files are stored. Static Web files, such as images, CSS and JavaScript go in the subdirectory static, which usually is exposed as the URL /static. Other kinds of files go in here too, such as templates.

script/: this contains application-specific scripts, including the development server (killerapp_server.pl) that you can use to run the application in its own standalone Web server, as well as scripts to deploy the application in a “real” Web server. The helper script killerapp_create.pl creates new model, view and controller component classes.

t/: this is where “tests” go. If you follow a test-driven development process, for every new feature you write, you also will write an automated test case. Tests let you quickly catch regressions that may be introduced in the future. Writing them is a good habit to get into, but that’s beyond the scope of this article.

The created skeleton application is already fully functional, and you can run it using the built-in test server:

cd KillerApp/
script/killerapp_server.pl

This fires up the app in its own dedicated Web server on port 3000. Open http://localhost:3000/ to see the default front page, which initially displays the Catalyst welcome message.

The Request/Response Cycle

All Web applications handle requests and generate responses. The fundamental job of any Web framework/platform/environment is to provide a useful structure to manage this process. Although there are different ways of going about this—from elegant MVC applications to ugly, monolithic CGI scripts—ultimately, they’re all doing the same basic thing:

  • Decide what to call when a request comes in.
  • Supply an API for generating the response.

In Catalyst, this happens in special methods called “actions”. On every request, Catalyst identifies one or more actions and calls them with special arguments, including a reference to the “context” object that provides a convenient and practical API through which everything else is accomplished.

Actions are contained within classes called “controllers”, which live in a special path/namespace in the application (lib/KillerApp/Controller/). The skeleton application sets up one controller (“Root”), but you can create more with the helper script. For example, this creates a new controller class KillerApp::Controller::Something:


script/killerapp_create.pl controller Something

The only reason to have more than one controller is for organization; you can put all your actions in the Root controller with no loss of features or ability. Controllers are just the containers for actions.

In the following sections, I describe how Catalyst decides which actions to call on each request (“dispatch”) and then explain how to use the supplied context object within them.

App Development With Catalyst Framework

App Development With Catalyst Framework

Learn More about this How To with the Following Links at Linux Journal How Tos for Web Dev and Catalyst MVC Perl Framework

1   >>  2  >>  3  >>  4  >>  next ›  >>  last »

More On Programming And Web Development With The Catalyst MVC Framework

What is Catalyst?

Catalyst is an open-source Perl MVC web framework that encourages rapid development and clean design without getting in your way by forcing rules.

We tend to keep things small and simple. This gives us robustness and scalability – your Catalyst-based app also inherits those. No complicated object hierarchies.

Why reinvent the wheel? When you write your app with Catalyst, you don’t have to care much about session handling or authorization. You just use it. CPAN has a vast amount of power, which we bring to you. If you don’t like something in default setup, why not replace it? There Is More Than One Way To Do It. You can choose from a wealth of available models and views, drop in a bunch of plugins and create the setup that fits you best.

Many high-profile sites like the BBC’s iPlayer123peoplemagazines.com and urbia.de are already using Catalyst.

Check out some other sites which are using Catalyst.

Why Catalyst?

Versatile Models

Use a powerful database ORM like DBIx::Class for your model, plain old DBI or even LDAP – Catalyst supports a wide range of models.

Flexible Views

Use whatever templating language you like best: Template::ToolkitMason 2,HTML::Template and many more are fully supported.

Integrated Development server

Catalyst comes with its own lightweight test server for development. It automatically restarts when your sources have changed, so you get instant results!

Works with all major webservers

Catalyst 5.9 has native PSGI/Plack support which makes deployment for most webservers a no-brainer. Plus, there are loads of engines targeting specific servers/protocols like Apache/mod_perl or FastCGI.

Ready-to-use plugins

Don’t re-invent the wheel! Use well-tested plug-ins for session managementuser authenticationcaching and much more.

How do I get started?

  1. Quick Install Guide

    For more details and other platforms read the extended Installing Catalyst guide.

  2. Tutorial

    Learn how to build your first complete Catalyst application with all the nuts’n’bolts of modern web applications.

Get the book

The Definitive Guide to Catalyst

The Definitive Guide to Catalyst book

This book by Kieren Diment, Matt Trout and other core Catalyst developers, published by Apress is now available for purchase from Amazon.com, or get the eBook (PDF) from Apress.

Share Button

You may also like...

Leave a Reply