Catman...uggable(3pm)

πŸ“¦
version 1.2025 Β· 4 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– 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::Bag
  • Catmandu::Plugin::Datestamps
  • Catmandu::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