Main Navigation

Content

Object Oriented Programming in Perl

Learn Perl Now!
And get a job doing Perl.

Introduction

Object-oriented programming (or OOP for short) is a software-design paradigm that allows for writing more re-usable and more elegant code by declaring classes that define the functionality that their various instances, called objects have.

There's a myth going on that Perl is not an object-oriented language. It's not true and starting from Perl 5 (which has been the standard Perl version since 1994), Perl has had support for a very powerful and flexible object system. While it is true that Perl does not force one to program using object-oriented programming (because it is often an overkill), it does allow OOP when one needs and wants to.

Moose

Moose is a post-modern object system for Perl. It supports a meta-object protocol, has a built-in type system, support roles, and is considered the modern way to do object-oriented programming in Perl. The Moose homepage contains a lot of information about it including introductory talks, articles, and links.

Moo

Moo is an object system for Perl, which provides a large subset of Moose’s functionality, but with a considerably reduced initial process loading time (which has been a frequent complaint about Moose), and is dependent only on pure-Perl modules (making it capable of being handled by App-Fatpacker).

Best of all, it is fully compatible with Moose, and one can safely mix Moose code and Moo code. If you’re interested in Moo also look at MooX::late which is a Moo extension that makes Moo more Moose-like.

Moo provides the class building features of Moose but not the meta-programming (and if you do not care about meta-programming - you can probably use Moo instead of Moose.)

Tutorials

Modern Perl (the Book)

Has an "Objects" chapter.

Beginning Perl

The 11th chapter of this book for Perl beginners (including absolute beginners) covers Objects. This book was written by one of the foremost Perl experts.

Perl for Perl Newbies Series

The third talk in the series explains objects in detail, although from a very low level and how they work behind the scenes.

Perldoc Tutorials

These are the Perldoc OOP tutorials that ship with Perl:

  • perlmod - The Perl Modules Introduction
  • perlootut - Object-Oriented Programming in Perl Tutorial
  • perlobj - The Perl Objects Man-Page

Share/Bookmark

Footer