-
-
02 Jul 2006 12:33:55 UTC
- Distribution: Module-Pluggable-Ordered
- Module version: 1.5
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Issues (3)
- Testers (2702 / 80 / 0)
- Kwalitee
Bus factor: 1- 87.50% Coverage
- License: unknown
- Activity
24 month- Tools
- Download (4.76KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
++ed by:1 non-PAUSE user- Dependencies
- Module::Pluggable
- UNIVERSAL::require
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Module::Pluggable::Ordered - Call module plugins in a specified order
SYNOPSIS
package Foo; use Module::Pluggable::Ordered; Foo->call_plugins("some_event", @stuff); for my $plugin (Foo->plugins()){ $plugin->method(); }
Meanwhile, in a nearby module...
package Foo::Plugin::One; sub some_event_order { 99 } # I get called last of all sub some_event { my ($self, @stuff) = @_; warn "Hello!" } sub _order { 99 } # I get listed by plugins_ordered() last
And in another:
package Foo::Plugin::Two; sub some_event_order { 13 } # I get called relatively early sub some_event { ... } sub _order { 10 } # I get listed by plugins_ordered() early
DESCRIPTION
This module behaves exactly the same as
Module::Pluggable
, supporting all of its options, but also mixes in thecall_plugins
andplugins_ordered
methods to your class.call_plugins
acts a little likeClass::Trigger
; it takes the name of a method, and some parameters. Let's say we call it like so:__PACKAGE__->call_plugins("my_method", @something);
call_plugins
looks at the plugin modules found usingModule::Pluggable
for ones which providemy_method_order
. It sorts the modules numerically based on the result of this method, and then calls$_->my_method(@something)
on them in order. This produces an effect a little like the System V init process, where files can specify where in the init sequence they want to be called.plugins_ordered
extends theplugins
method created byModule::Pluggable
to list the plugins in defined order. It looks for a_order
method in the modules found usingModule::Pluggable
, and returns the modules sorted numerically in that order. For example:my @plugins = __PACKAGE__->plugins();
The resulting array of plugins will be sorted. If no
_order
subroutine is defined for a module, an arbitrary default value of 50 is used.OPTIONS
The
package
option can be used to put the pluggability into another package, to be used for modules building on the functionality of this one.It also provides the
only
andexcept
options.# will only return the Foo::Plugin::Quux plugin use Module::Pluggable::Ordered only => [ "Foo::Plugin::Quux" ]; # will not return the Foo::Plugin::Quux plugin use Module::Pluggable::Ordered except => [ "Foo::Plugin::Quux" ];
SEE ALSO
Module::Pluggable, Class::Trigger
AUTHOR
Simon Cozens, <simon@cpan.org> (author emeritus)
Christopher Nehren, <apeiron@cpan.org> (current maintainer)
Please report bugs via the CPAN RT tracker at http://rt.cpan.org.
COPYRIGHT AND LICENSE
Copyright 2004 by Simon Cozens
Copyright 2004 by Christopher Nehren (current copyright holder)
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
ACKNOWLEDGEMENTS
Thank you to Simon Cozens for originally writing this module.
Thanks to Lars Thegler for indirectly alerting me to the fact that my POD was horribly broken, for providing patches to make this module work with Perl versions < 5.6, for maintaining the port up to version 1.3, and for allowing me to take maintainership for versions 1.3 onwards.
Module Install Instructions
To install Module::Pluggable::Ordered, copy and paste the appropriate command in to your terminal.
cpanm Module::Pluggable::Ordered
perl -MCPAN -e shell install Module::Pluggable::Ordered
For more information on module installation, please visit the detailed CPAN module installation guide.