<link>
tag in the document. The Webmention endpoint is listed as an absolute URL.The emoji below show Reacji responses, created by people posting a comment linking to this post with an in-reply-to
property, whose text is a single emoji character.
The profile icons below are the author photos from people who have posted a "like" post on their site, where their post links to this post with the like-of
property.
The profile icons below are the author photos from people who have posted a "repost" of this post on their site, where their post links to this post with the repost-of
property.
The profile icons below are the author photos from people who have posted a bookmark of this post on their site, where their post links to this post with the bookmark-of
property.
The comments below are replies to this post, and marked up their link to the post with the in-reply-to
property.
The mentions below linked to this post, but did not include this post's URL as an in-reply-to
property.
Revisiting Perl Object-Oriented Programming (OOP) in 2025: A Modern Take
Back in November 2002, I published a blog post titled Camel POOP – Perl Object-Oriented Programming. It was my attempt to demystify Perl’s OOP capabilities for developers who might not have realised just how flexible and powerful the language could be. Fast forward to 2025, and while much has changed in the tech world, Perl still holds its ground as a versatile and reliable programming language. I thought it was about time to revisit that old post, take a fresh look at Perl OOP, and explore how modern practices have shaped the way we write Perl today.
The Longevity of Perl in 2025
Perl has a way of surprising people. It’s still actively developed, and its latest version, Perl 5.40.0 (released in 2024), brought some fantastic updates, including native
try/catch
exception handling and the__CLASS__
keyword. Even as other languages gain popularity, Perl continues to be a go-to tool for text processing, web development, and system administration. Its object-oriented programming features may not be the flashiest, but they remain as practical and flexible as ever.What’s New in Perl OOP?
1. Modern Object Systems: Moo, Moose, and Mo
If you’ve spent any time in the Perl community recently, you’ve probably heard of Moo, Moose, or even Mo. These lightweight object systems have become the standard for many developers, offering cleaner syntax and more powerful features than Perl’s built-in OOP capabilities.
For instance, here’s how you’d create a
Person
class using Moo:Moo automatically generates accessors, handles attribute validation, and makes your code more concise. Compare that to manually defining accessors in my original post—it’s clear how much time and effort you can save with modern tools.
2. Better Error Handling with
try/catch
Back in 2002, error handling in Perl often involved using
eval
, which could get messy and hard to read. The addition of nativetry/catch
syntax in Perl 5.40.0 changes that. It’s simple and elegant:This is a huge improvement for writing more maintainable and readable code.
3. Inheritance Made Easy with Moo or Moose
In my original post, I discussed using
@ISA
for inheritance. While it works, it’s a bit clunky. Modern object systems like Moose make this much smoother. Here’s an example:With Moose, you don’t need to worry about manually overriding methods or handling inheritance quirks. It just works, and it works beautifully.
4. Type Validation with Type::Tiny
Another modern addition to Perl development is the use of type constraints. Using
Type::Tiny
, you can ensure your attributes have the correct data types:This is incredibly useful for catching errors early and making your code more robust.
Reflecting on the Basics
Packages and Namespaces
The concept of packages hasn’t changed much since 2002, but modern Perl developers often use
namespace::autoclean
to prevent namespace pollution:Bless and Raw OOP
Using
bless
directly still works and is sometimes useful for quick scripts or minimal dependencies. However, in most cases, modern object systems like Moo or Moose makebless
unnecessary for day-to-day development.Why Modernise?
Looking back at my original post, I’m struck by how much of it is still relevant today. Perl’s core OOP features haven’t changed, but the ecosystem around them has evolved dramatically. By adopting modern tools and techniques, you can:
– Write code that’s easier to read and maintain.
– Reduce boilerplate and focus on solving real problems.
– Take advantage of Perl’s latest features for better performance and reliability.
Bridging the Past and Present
It’s been fun revisiting my old blog post and reflecting on how far Perl’s OOP capabilities have come. If you’re still using Perl for your projects, I encourage you to explore tools like Moo, Moose, and Type::Tiny. They’ll make your life as a developer so much easier.
If you’re curious about the basics, feel free to check out my original post. It’s a nice reminder of how Perl OOP works under the hood. And if you’ve got thoughts or questions about modern Perl practices, I’d love to hear from you in the comments below!
Like this: