O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required


Book Description

Accelerating Perl Web Application Development

  • Understand the Catalyst Framework and MVC architecture

  • Build and test a site with Catalyst

  • Detailed walkthroughs to create sample applications

  • Extend Catalyst through plug-ins

In Detail Many web applications are implemented in a way that makes developing them painful and repetitive. Catalyst is an open-source Perl-based Model-View-Controller framework that aims to solve this problem by reorganizing your web application to design and implement it in a natural, maintainable, and testable manner, making web development fun, fast, and rewarding. Everything that your web application needs to do is only written once; you connect to the database in one place, have configuration in one place, etc. Then, you just write actions for each URL that your application needs, without worrying about the database connections or HTML to produce. Catalyst will handle the details so you can worry about writing your application. Catalyst is designed to be reliable. There are hundreds of production applications and thousands of users. The code is well-tested, and new releases almost always maintain compatibility with applications written for older versions. You don't have to worry about Catalyst breaking your application and slowing down your development. It just works. Most importantly, Catalyst has a thriving community. You can ask a question on the IRC channel and get a response at almost any time of the day. This book embodies Catalyst's philosophies of Do It Yourself and Don't Repeat Yourself. What you will learn from this book?
  • Installing and setting up Catalyst

  • How MVC works in Catalyst, explained with a simple example

  • Using the Template toolkit to generate HTML output

  • Designing a database schema and accessing a SQLite database

  • Creating a CRUD interface to a database

  • Using FormBuilder to define auto-generating and self-validating forms

  • Creating easy-to-maintain configuration files

  • Importing CVS files into a database

  • Paginating search results

  • Using the session plug-in to add sessions to an application

  • Authentication and authorization, explored by implementing page-level and record-level control

  • Building an editable web interface

  • Features of DBIC for easy handling of data

  • Interfacing to your data:

    • Mixing a procedural interface with a relational DBIx::Class interface

    • Writing a database interface without DBIx::Class

    • Building a custom Model without using any database

  • Adding a REST API to allow other applications to access your application

  • Adding AJAX interactivity to your application

  • Incorporating RSS feeds in your application

  • Automated testing and the "Test-Driven Development" methodology, discussed in depth

  • Techniques to test your Catalyst application easily

  • Writing tests for applications developed in this book with Mechanize and Selenium

  • Packaging your application:

    • Manage dependencies and create packages easily using Makefile.PL

    • Create a unique configuration for each environment

    • How to set up for a variety of web servers

    • How to make your application a self-contained file (PAR)

Approach This book will guide you through the features of Catalyst using real-world examples and systematic code snippets. Who this book is written for? This book is for web developers with basic Perl skills who are new to Catalyst. If you are excited by Ruby on Rails but would like the features of Rails with the familiarity of Perl, pick this book and get started.

Table of Contents

  1. Catalyst
    1. Catalyst
    2. Credits
    3. About the Author
    4. About the Reviewers
    5. Preface
      1. What This Book Covers
      2. What You Need for This Book
      3. Conventions
      4. Reader Feedback
      5. Customer Support
        1. Downloading the Example Code for the Book
        2. Errata
        3. Questions
    6. 1. Introduction to Catalyst
      1. Catalyst Application Architecture
        1. Extensibility
        2. Reusability
        3. Flexibility
        4. Reliability
      2. Installing Catalyst
        1. CPAN
      3. Where to go for Help?
      4. Summary
    7. 2. Creating a Catalyst Application
      1. Creating the Application Skeleton
      2. MyApp Directory Structure
        1. Files in the MyApp Directory
        2. Files in the lib Directory
        3. Files in the root Directory
        4. Files in the script Directory
        5. Files in the t Directory
      3. Adding a View
        1. Using a Template To Render the Page
        2. Some Technical Details
      4. Adding a Database
        1. Installing SQLite
        2. Creating a Database Schema
        3. Creating a Database Model for Catalyst
        4. Using the Model
      5. Summary
    8. 3. Building a Real Application
      1. Environment Setup
      2. Database Design
      3. Understanding the Interface to the Database
      4. TTSite
        1. Creating the Index Page
        2. Creating a "Not Found" Page
      5. Viewing People
      6. Basic CRUD
      7. Forms
      8. Finishing Up
      9. Summary
    9. 4. Expanding the Application
      1. Configuration Files
        1. Configuring the Address Book
      2. Sessions
        1. Adding Sessions to the Address Book
        2. Sessions in the Database
      3. Using Components from Outside Catalyst
      4. Searching and Paging
      5. Authentication and Authorization
        1. Authentication
        2. Authorization
        3. Adding Authentication and Authorization to the Address Book
        4. Summary
    10. 5. Building a More Advanced Application
      1. The Application
        1. Background
      2. Creating the Database
        1. Populating the Database
      3. Extracting the Data
        1. Chained ResultSets
        2. Custom ResultSets
      4. Putting the Data on the Web
      5. Summary
    11. 6. Building Your Own Model
      1. Extending a DBIx::Class Model
        1. Custom Methods Without Raw SQL
        2. Calling Database Functions
      2. Creating a Database Model from Scratch
      3. Implementing a Filesystem Model
        1. Tweaking the Model
        2. Request Context Inside the Model
        3. Maintainable Models
        4. Other Components
      4. Summary
    12. 7. Hot Web Topics
      1. REST
        1. Getting some REST
          1. REST Controller
          2. REST Authentication
          3. Adding an Entity
          4. REST Easy
      2. AJAX
        1. Getting Started
          1. Jemplate
        2. Implementing AJAX
      3. RSS
      4. Summary
    13. 8. Testing
      1. Mechanics
      2. Testing ChatStat
        1. Testing a Database
        2. Testing the Web Interface
      3. Testing the Address Book
        1. Logging In
        2. Testing Forms
        3. Testing JavaScript
      4. Summary
    14. 9. Deployment
      1. Basics
        1. PAR Deployment
        2. Configuration Management
      2. Configuring a Web Server
        1. Apache
          1. FastCGI
          2. Static Content
          3. mod_perl
          4. Performance Considerations
        2. Development Server and perlbal
      3. Summary