MooseX...uggable(3pm)
π¦ MooseX::Object::Pluggable (3pm) β the perl manual page, but make it cute
okay bestie, this is the manual page for MooseX::Object::Pluggable, and yes the header up top is a little mangled (it shows as MooseX...uggable(3pm), the terminal just did a lil truncation thing, ignore her π
). Here's the whole thing, vibes included.
β¨ NAME β¨
MooseX::Object::Pluggable β Make your classes pluggable π«Ά
πΈ VERSION πΈ
version 0.0014
π SYNOPSIS π
like, literally just:
package MyApp;
use Moose;
with 'MooseX::Object::Pluggable';
...
package MyApp::Plugin::Pretty;
use Moose::Role;
sub pretty{ print "I am pretty" }
1;
#
use MyApp;
my $app = MyApp->new;
$app->load_plugin('Pretty');
$app->pretty;
π DESCRIPTION π
So this module is meant to be loaded as a role from Moose-based classes. It will add five methods and four attributes to assist you with the loading and handling of plugins and extensions for plugins. And yeah, I know, this may pollute your namespace β but I took great care in using the least ambiguous names possible. considerate queen behavior, honestly. π
How plugins Work
Plugins and extensions are just Roles by a fancy name. that's it, that's the tea. β
They are loaded at runtime on demand and are instance, not class based. This means that if you have more than one instance of a class they can all have different plugins loaded. This is a feature. (say it with me: it's a feature, not a bug β¨)
Plugin methods are allowed to around, before, after their consuming classes, so it is important to watch for load order as plugins can and will overload each other. You may also add attributes through has.
Please note that when you load at runtime you lose the ability to wrapBUILD, and roles usinghaswill not go through compile time checks likerequiredanddefault. π
Even though override will work, I STRONGLY discourage its use and a warning will be thrown if you try to use it. This is closely linked to the way multiple roles being applied is handled and is not likely to change. override behavior is closely linked to inheritance and thus will likely not work as you expect it in multiple inheritance situations. Point being: save yourself the headache. π§ π
How plugins are loaded
When roles are applied at runtime an anonymous class will wrap your class, and $self->blessed, ref $self and $self->meta->name will no longer return the name of your object; they will instead return the name of the anonymous class created at runtime. See _original_class_name. π«
Usage
For a simple example see the tests included in this distribution.
π Attributes π
_plugin_ns
String. The prefix to use for plugin names provided. MyApp::Plugin is sensible.
_plugin_app_ns
An ArrayRef accessor that automatically dereferences into array on a read call. By default it will be filled with the class name and its precedents. It is used to determine which directories to look for plugins as well as which plugins take precedence upon namespace collisions. This allows you to subclass a pluggable class and still use its plugins while using yours first if they are available. iconic inheritance moment π
_plugin_locator
An automatically built instance of Module::Pluggable::Object used to locate available plugins.
_original_class_name
Because of the way roles apply, $self->blessed, ref $self and $self->meta->name will no longer return what you expect. Instead, upon instantiation, the name of the class instantiated will be stored in this attribute if you need to access the name the class held before any runtime roles were applied. your lil time capsule π°οΈβ¨
π Public Methods π
load_plugins @plugins
load_plugin $plugin
Load the appropriate role for $plugin.
π Private Methods π
There's nothing stopping you from using these, but if you are using them for anything that's not really complicated you are probably doing something wrong. (not me calling you out, I'm just saying π)
_role_from_plugin $plugin
Creates a role name from a plugin name. If the plugin name is prepended with a + it will be treated as a full name returned as is. Otherwise a string consisting of $plugin prepended with the _plugin_ns and the first valid value from _plugin_app_ns will be returned. Example
#assuming appname MyApp and C<_plugin_ns> 'Plugin'
$self->_role_from_plugin("MyPlugin"); # MyApp::Plugin::MyPlugin
_load_and_apply_role @roles
Require $role if it is not already loaded and apply it. This is the meat of this module. π₯©
_build_plugin_app_ns
Automatically builds the _plugin_app_ns attribute with the classes in the class precedence list that are not part of Moose.
_build_plugin_locator
Automatically creates a Module::Pluggable::Object instance with the correct search_path.
meta
Keep tests happy. See Moose.
β SEE ALSO β
Moose, Moose::Role, Class::Inspector
π BUGS π
Holler?
Please report any bugs or feature requests to bug-MooseX-Object-Pluggable at rt.cpan.org, or through the web interface at <http://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Object-Pluggable>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. we love a notification pipeline π
π§ SUPPORT π§
You can find documentation for this module with the perldoc command.
perldoc MooseX-Object-Pluggable
You can also look for information at:
- AnnoCPAN: Annotated CPAN documentation
<http://annocpan.org/dist/MooseX-Object-Pluggable>
- CPAN Ratings
<http://cpanratings.perl.org/d/MooseX-Object-Pluggable>
- RT: CPAN's request tracker
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-Object-Pluggable>
- Search CPAN
<http://search.cpan.org/dist/MooseX-Object-Pluggable>
π«Ά ACKNOWLEDGEMENTS π«Ά
#Moose - Huge number of questions
Matt S Trout <mst@shadowcatsystems.co.uk> - ideas / planning.
Stevan Little - EVERYTHING. Without him this would have never happened.
Shawn M Moore - bugfixes
πΈ AUTHOR πΈ
Guillermo Roditi <groditi@cpan.org>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2007 by Guillermo Roditi <groditi@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
π CONTRIBUTORS π
- Karen Etheridge <ether@cpan.org>
- Shawn M Moore <sartak@gmail.com>
- Yuval Kogman <nothingmuch@woobling.org>
- Robert Boone <robo4288@gmail.com>
- David Steinbrunner <dsteinbrunner@pobox.com>
- Todd Hepler <thepler@employees.org>
and that's the whole page bestie!! π¦ this lil beauty shipped as part of perl v5.34.0 and the page is dated 2022-06-15 β go off, MooseX...uggable(3pm). mwah π
β¨
π¦ where this page comes from
- debian bookworm: libmoosex-object-pluggable-perl 0.0014-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmoosex-object-pluggable-perl 0.0014-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmoosex-object-pluggable-perl 0.0014-2 Β· 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