Class::Pluggable(3pm)
π Class::Pluggable π
okay bestie, welcome to Class::Pluggable(3pm) β the β¨User Contributed Perl Documentationβ¨ page that's about to make your class go from basic to booked-and-busy. it's a simple pluggable class, and yes, we're doing this together, hand in hand, no cap π«Ά
πΈ NAME πΈ
Class::Pluggable β simple pluggable class. that's it. that's the name. iconic.
β¨ SYNOPSIS β¨
use Class::Pluggable;
use base qw(Class::Pluggable);
# Some::Plugin::Module has sub routin called newAction
add_plugin("Some::Plugin::Module");
newAction(); # Plugged action.
literally that's the whole vibe. you inherit, you plug in a module, and boom β newAction() is just there, like it was always meant to be π
π¦ DESCRIPTION π¦
so this class makes your class pluggable β and by "your class" we mean any sub class of Class::Pluggable. and in this documentation, the word "pluggable" has two meanings, because we're multitalented like that π
meaning number one: it's just simply adding new methods to your pluggable class from other plugin modules. so after you've plugged some modules into your class, you can use their methods exactly the same as your own object's methods. no difference. same energy. slay.
you can see this kind of plugin mechanism in CGI::Application and CGI::Application::Plugin::Session. π
there is one thing that Plugin developers have to know β and listen, this is the important part, don't scroll past it π β the plugin module MUST have @EXPORT_AS_PLUGIN to use this pluggable mechanism. it works almost the same as @EXPORT. but the methods in the @EXPORT_AS_PLUGIN wouldn't be exported to your package. instead, it would be exported to the subclass of Class::Pluggable β and only when you call add_plugin(). so specific. so picky. we love a method with boundaries fr fr.
meaning number two: the so-called hook-mechanism. for example, if you want to allow other modules to do something before and/or after some action, you can do like this:
$self->execute_plugin_method($_, "before_action")
foreach $self->get_plugins();
## do some your own action here.
$self->execute_plugin_method($_, "after_action")
foreach $self->get_plugins();
before. action. after. the three-act structure of your code's main character arc π¬β¨
π METHODS π
here are all methods of Class::Pluggable. every single one. we don't skip.
π add_plugin
$object->add_plugin($pluginName)
this will add a new plugin to your class. and what you added here? that's what gets returned by the get_plugins() method later. it remembers. it's loyal. π«Ά
π get_plugins
@plugins = $object->get_plugins();
it will return all of the plugin names that are already added to YouClass. the whole roster. the full lineup. β
π execute_plugin_method
$result = $object->execute_plugin_method("SomePlugin", "someMethod");
this will execute the method someMethod of SomePlugin. one plugin, one method, one mission. π₯
π execute_all_plugin_method
$object->execute_all_plugin_method("someMethod");
this will execute the method someMethod of all plugins we have. it's almost the same as the following code:
$self->execute_plugin_method($_, "someMethod")
foreach $self->get_plugins();
the difference is executeAllPluginMethod can't return any values. but executePluginMethod can. so likeβ¦ one of them is a void girlie and one of them brings receipts. know which one you're calling bestie π
π add_hook
$object->add_hook("pre-init", "pre_init");
this will add a new hook to your class. whenever run_hook("pre-init") has been called, the method pre_init of all plugins which we have will be executed. every single one of them. synchronized. π
π run_hook
$object->run_hook("pre-init");
this will execute the hook-method of all plugins which we have. go off, plugins. π
π remove_hook
$object->remove_hook("pre-init");
this will delete the hook from YourClass. and after calling this method, you cannot call run_hook("pre-init").
β οΈ if you do? it will die immediately. no warning, no gentle nudge, just π. so be sure before you remove, okay? i'm not mad, i'm just looking out for you.
π SEE ALSO π
...
(that's literally what it says. the mystery. the intrigue. the audacity. iykyk π§)
π AUTHOR π
Ken Takeshige, <ken.takeshige@gmail.com> π
π COPYRIGHT AND LICENSE π
Copyright (C) 2006 by Ken Takeshige
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.
(translation: free to use, free to share, just keep the same terms as Perl itself. generosity! we stan. π)
π POD ERRORS π
hey! the above document had some coding errors, which are explained below:
Around line 211:
You forgot a '=back' before '=head1'
not me exposing the doc's little oopsie in the doc itself π we're keeping it though, because honesty is the vibe.
and that's the whole page bestie β perl v5.32.1, dated 2021-12-26, and it was Class::Pluggable(3pm) all along. go plug something in. you've got this. periodt. πβ¨π¦
π¦ where this page comes from
- debian bookworm: libclass-pluggable-perl 0.022-2.2
- ubuntu jammy: libclass-pluggable-perl 0.022-2.2
- ubuntu noble: libclass-pluggable-perl 0.022-2.2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms