PerlSchool · Perl School Publishing

Design Patterns
in Modern Perl

Practical Patterns for Everyday Perl - all 23 Gang of Four patterns, implemented in real, runnable Perl.

294 pages 23 GoF patterns 3 OO styles: bless, Moo, class PDF, EPUB & paperback
Cover of Design Patterns in Modern Perl by Mohammad Sajid Anwar

About the book

Patterns as theory made tedious. This book makes them runnable.

Design Patterns in Modern Perl shows how classic object-oriented patterns look in today's Perl. Using core Perl, Moo, and Object::Pad, Mohammad Sajid Anwar builds real, tested examples, helping you choose patterns sensibly and write cleaner, more maintainable code.

Every chapter follows the same shape: the problem the pattern solves, a worked example, complete implementations across three object systems, and the unit tests and benchmarks to go with them.

  • 01 Traditional bless, via Class::Mite
  • 02 Moo, the lightweight modern standard
  • 03 Core class / Object::Pad, Perl's newest OO syntax
Patterns covered23
Creational5
Structural7
Behavioural11
FormatPDF / EPUB / Paperback

Table of contents

What's inside

The three pattern families, laid out the way the book builds them - one package per family, one chapter per pattern.

package Creational;
  1. 01 Abstract Factory p.41
  2. 02 Builder p.57
  3. 03 Factory Method p.74
  4. 04 Prototype p.84
  5. 05 Singleton p.96
package Structural;
  1. 01 Adapter p.103
  2. 02 Bridge p.117
  3. 03 Composite p.129
  4. 04 Filter p.136
  5. 05 Decorator p.150
  6. 06 Facade p.161
  7. 07 Proxy p.170
package Behavioural;
  1. 01 Chain of Responsibility p.181
  2. 02 Command p.192
  3. 03 Interpreter p.204
  4. 04 Iterator p.212
  5. 05 Mediator p.222
  6. 06 Memento p.232
  7. 07 Observer p.240
  8. 08 State p.254
  9. 09 Strategy p.263
  10. 10 Template p.272
  11. 11 Visitor p.281
use FrontMatter;  // Dedication, Foreword, Introduction & Getting Started
Dedicationp.7
Acknowledgementsp.9
Forewordp.11
Introduction: Historyp.15
What is a Design Pattern?p.16
Why are Design Patterns useful?p.16
What problems do they solve?p.17
The Gang of Fourp.18
Who should read this?p.18
Choice of OOP Frameworksp.21
Environment Setupp.29
Introduction to Class::Mitep.31
Test Driven Developmentp.36
About the Bookp.293

OOP Frameworks

Pattern Implementation Matrix

Below is a chart listing the implementations of each design pattern in the various OOP frameworks. Only four of the patterns were implemented using the experimental class feature.

Name bless Moo Object::Pad class
Abstract Factory
Builder
Factory Method
Prototype
Singleton
Adapter
Bridge
Composite
Filter
Decorator
Facade
Proxy
Chain of Responsibility
Command
Interpreter
Iterator
Mediator
Memento
Observer
State
Strategy
Template
Visitor

Reviews

What readers say

★★★★★
Just by leafing through the table of contents, you realize it's a great book.
Mariano Spadaccini - Verified Purchase, Amazon (Italy)
Photo of Mohammad Sajid Anwar

The author

Mohammad Sajid Anwar

Mohammad Sajid Anwar is an India-born software developer now based in the United Kingdom. His career in technology began in Jamshedpur and later took him to Mumbai before he settled in London in 2000, building his expertise through the dot-com boom and its aftermath. With a background in mathematics, he has focused much of his technical work on elegant, reliable solutions in Perl.

Sajid is a prolific CPAN author (PAUSE id MANWAR), known especially for the Map::Tube ecosystem for modelling urban transport networks, extensive calendrical libraries, and tools for the Dancer2 web framework. In 2023 he received the White Camel Award for outstanding service to the Perl community. He founded and runs The Weekly Challenge and has served as a co-editor of the Perl Weekly newsletter for more than six years.

Get the book

Bring the Gang of Four into your Perl.

DRM-free PDF & EPUB on Leanpub, or a paperback on Amazon.