package Module::Pluggable::Ordered; use 5.006; use strict; use warnings; require Module::Pluggable; use UNIVERSAL::require; our $VERSION = '1.0'; sub import { my ($self, %args) = @_; my $subname = $args{sub_name} || "plugins"; my $caller = caller; no strict; *{"${caller}::call_plugins"} = sub { my ($thing, $name, @args) = @_; my @plugins = $thing->$subname(); $_->require for @plugins; my $order_name = "${name}_order"; for my $class (sort { $a->$order_name <=> $b->$order_name } grep { $_->can($order_name) } @plugins) { $class->$name(@args); } }; goto &Module::Pluggable::import; } 1; __END__ # Below is stub documentation for your module. You'd better edit it! =head1 NAME Module::Pluggable::Ordered - Call module plugins in a specified order =head1 SYNOPSIS package Foo; use Module::Pluggable::Ordered; Foo->call_plugins("some_event", @stuff); 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!" } And in another: package Foo::Plugin::Two; sub some_event_order { 13 } # I get called relatively early sub some_event { ... } =head1 DESCRIPTION This module behaves exactly the same as C, supporting all of its options, but also mixes in the C method to your class. C acts a little like C; it takes the name of a method, and some parameters. Let's say we call it like so: __PACKAGE__->call_plugins("my_method", @something); C looks at the plugin modules found using C for ones which provide C. It sorts the modules numerically based on the result of this method, and then calls C<$_-Emy_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. =head1 SEE ALSO L, L =head1 AUTHOR Simon Cozens, Esimon@cpan.orgE; please report bugs via the CPAN Request Tracker. =head1 COPYRIGHT AND LICENSE Copyright 2004 by Simon Cozens This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut