Catman...uggable(3pm)
π Catman...uggable π
okay bestie, gather round, because this is the Catmandu::Pluggable page from the 3pm perl manual, and it's genuinely one of those little gems that makes your whole codebase pop off. it's a role β a role, not a class, she's not like other girls β for classes that need plugin capabilities. that's the whole vibe. you write a class, you let other people plug stuff into it, everybody wins. periodt. β¨
πΈ NAME πΈ
Catmandu::Pluggable β a role for classes that need plugin capabilities π«Ά
β¨ SYNOPSIS β¨
here's the whole thing in action, no cap. read it, it's giving tutorial energy:
package My::Foo::Bar;
use Role::Tiny;
before foo => sub {
print "Before foo!\n";
};
after foo => sub {
print "After foo!\n";
};
sub extra {
print "I can do extra too\n";
}
package My::Foo;
use Moo;
with 'Catmandu::Pluggable';
sub plugin_namespace {
'My::Foo';
}
sub foo {
print "Foo!\n";
}
package main;
my $x = My::Foo->with_plugins('Bar')->new;
# prints:
# Before foo!
# Foo!
# After foo!
$x->foo;
# prints:
# I can do extra too
$x->extra;
so like, My::Foo::Bar is a plugin (it's just a plain old Role::Tiny role that wraps foo with before and after and adds an extra method), and My::Foo is the class that says "yeah I'm pluggable" by doing with 'Catmandu::Pluggable'. then with_plugins('Bar') hands you back a subclass with Bar mixed in. it's giving β¨composableβ¨ and we're obsessed. π
π METHODS π
π plugin_namespace
returns the namespace where all the plugins for your class can be found. that's it, that's the method. she's short and she knows exactly what she's about. π
π with_plugins(NAME)
π with_plugins(NAME,NAME,...)
this is a class method, bestie β call it on the class itself, not on an instance. it returns a subclass of your class with all the plugins you named (NAME-s) implemented. so you hand it one name, or a whole roster of names, and it gives you back a brand new class with all of them baked in. π§
fr fr, NAME can show up more than once in the signature β one plugin, or a whole lineup. whatever you pass is what gets built in.
π SEE ALSO π
go be nosy, these are all part of the same friend group:
Catmandu::BagCatmandu::Plugin::DatestampsCatmandu::Plugin::Versioning
and that's the whole page, babe. this one's running on perl v5.40.1, dated 2026-01-24, from the User Contributed Perl Documentation corner of the 3pm manual β go forth and plug things into other things responsibly. slay π
ππ
π¦ where this page comes from
- ubuntu resolute: libcatmandu-perl 1.2025-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatmandu-perl 1.2025-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms