MooseX:...gPlugins(3)

πŸ¦‹ MooseX::App::WritingPlugins β€” writing plugins for MooseX::App

okay bestie, so this is the MooseX::App::WritingPlugins page, straight out of the User Contributed Perl Documentation πŸ’… and it's literally your whole guide to making your own plugins. no cap, it's shorter than you'd think and honestly? iconic for that.


✨ SYNOPSIS ✨

here's the vibe, in code, exactly as written:

package MooseX::App::Plugin::MyPlugin;

use Moose::Role;

sub plugin_metaroles {
    my ($self,$class) = @_;
    return {
        class   => ['MooseX::App::Plugin::MyPlugin::Meta::Class'],
    }
}

around 'initialize_command_class' => sub {
   ...
};

that's the whole shape of it 🫢 a package, a Moose::Role, a callback, and a method modifier. slay.


πŸŽ€ DESCRIPTION πŸŽ€

so here's the tea: plugins are implemented as Moose roles, and they must live in the MooseX::App::Plugin::* namespace. that's not a suggestion, that's the rule, periodt.

you can alter metaclasses through the 'plugin_metaroles' callback method. and on top of that, you get all the Moose method modifiers β€” around, after, before β€” to change up how MooseX::App behaves, or how its meta classes behave. literally the whole toolkit 🌈


πŸ’« CALLBACKS πŸ’«

plugin_metaroles

this one's an optional callback method. should it exist, it should return a hash reference saying which metaroles get applied to the class metaclass, plus its contained metaclasses and helper classes 🧚

each key should in turn point to an array reference of role names.

it accepts the following keys:

  • class πŸ’–
  • attribute ✨
  • method πŸŽ€
  • wrapped_method πŸ¦‹
  • instance 🌸
  • constructor πŸ’…
  • destructor 🫢
  • error 😭

that's all eight, we're not skipping a single one, bestie πŸ‘‘


πŸ‘‘ METACLASSES πŸ‘‘

most of the MooseX-App behaviour is implemented in metaclass roles. so when you're writing plugins, you will most likely need to alter or augment the behaviour of these roles. the implementation details live in the respective packages β€” go peek, iykyk πŸ”₯

  • MooseX::App::Meta::Role::Class::Base is applied to the base metaclass
  • MooseX::App::Meta::Role::Class::Command is applied to the command metaclass
  • MooseX::App::Meta::Role::Attribute::Option is applied to all attributes in the base and command meta classes
lowkey the move here is to read those three packages before you touch anything, fr fr β€” this page points you at them but the details are theirs, not mine πŸ™ˆ

and that's the page!! no notes, we ate. this little masterpiece is perl v5.42.0 dated 2024-08-09, so go forth and plugin-ify responsibly β­πŸ’œ

πŸ“¦ where this page comes from