Module-Pluggable-Ordered-1.5000700 001750 001750 00000000000 10451736157 017142 5ustar00apeironapeiron000000 000000 Module-Pluggable-Ordered-1.5/META.yml000600 001750 001750 00000000602 10451736157 020472 0ustar00apeironapeiron000000 000000 # http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: Module-Pluggable-Ordered version: 1.5 version_from: Ordered.pm installdirs: site requires: Module::Pluggable: 1.9 UNIVERSAL::require: 0 distribution_type: module generated_by: ExtUtils::MakeMaker version 6.30 Module-Pluggable-Ordered-1.5/Changes000644 001750 001750 00000004524 10451734274 020531 0ustar00apeironapeiron000000 000000 Revision history for Perl extension Module::Pluggable::Ordered. 1.5 - Mark Grimes submitted a cool new feature implementing the plugins_ordered() method. This allows plugins to be returned sorted from the plugins() method. Note that this is a numeric sort using the <=> operator. Possible future improvement: allowing a custom sort method. Not sure how this would work; all plugins would have to agree to be sorted this way, and the sort method would need to be passed by the code calling the plugins to be registered properly. - SVN had been broken for a long time. It's working again, albeit at a different URL (albeit albeit on the same machine and in the same physical location in the filesystem). You can snag the code from http://www.coitusmentis.info/repos/Module-Pluggable-Ordered/ . 1.4 - Fixed some nasty bugs in the POD that cropped up in 1.3. DOH! Thanks to Lars Thegler for bringing my attention to the fact that 1.3 was finally publically available on CPAN. - Import some patches which originated in the FreeBSD ports system which fix the module with old versions of Perl (for the most part; I don't want to remove "use warnings" for obvious reasons). - All publically released versions of Module-Pluggable-Ordered are now available via the SVN repository. Feel free to browse around via the web frontend. Tags are under the tags/ subdirectory, and include all public releases. As an aside, if anyone has version 0.01, I'd greatly appreciate being able to add it to the collection. 1.3 - Now under maintainership by Christopher Nehren (note: previous revision history item written by Christopher Nehren). - The latest code is now available via an SVN repository located at http{,s}://www.incunabulum.info/repos/Module-Pluggable-Ordered/ . Anonymous checkouts are allowed; write access will be granted based upon merit of submitted patches. Branches, tags (releases) and other items to follow. 1.2 Sat Jul 17 2004 - Added the package option. 1.1 Sun Jul 11 12:19:57 BST 2004 - Patches from SW to make exclude and only work. 0.01 Wed May 19 16:40:41 2004 - original version; created by h2xs 1.22 with options -AX -b 5.6.0 -n Module::Pluggable::Ordered Module-Pluggable-Ordered-1.5/t000700 001750 001750 00000000000 10451736157 017405 5ustar00apeironapeiron000000 000000 Module-Pluggable-Ordered-1.5/MANIFEST000644 001750 001750 00000000327 10451732312 020353 0ustar00apeironapeiron000000 000000 Changes Makefile.PL MANIFEST Ordered.pm README t/1.t t/2.t t/3.t t/4.t t/modules/Foo/One.pm t/modules/Foo/Three.pm t/modules/Foo/Two.pm META.yml Module meta-data (added by MakeMaker) Module-Pluggable-Ordered-1.5/Ordered.pm000644 001750 001750 00000012031 10451734624 021147 0ustar00apeironapeiron000000 000000 package Module::Pluggable::Ordered; # I really regret this ugliness, but it's needed in the face of backwards # compatibility, and I don't want "code this funky" wandering around CPAN # without warnings if I can help it. :) Those using ancient versions of Perl can # use -w for global warnings. Unfortunately, there's not much else I can do. If # anyone has any suggestions, please do file a bug report. Thanks. BEGIN { if($] >= 5.00600) { require warnings; import warnings; } } use strict; require Module::Pluggable; use UNIVERSAL::require; use vars qw($VERSION); $VERSION = '1.5'; sub import { my ($self, %args) = @_; my $subname = $args{sub_name} || "plugins"; my %only; my %except; %only = map { $_ => 1 } @{$args{'only'}} if defined $args{'only'}; %except = map { $_ => 1 } @{$args{'$except'}} if defined $args{'except'}; my $caller = $args{package} || caller; no strict; *{"${caller}::call_plugins"} = sub { my ($thing, $name, @args) = @_; my @plugins = (); for ($thing->$subname()) { next if (keys %only && !$only{$_} ); next if (keys %except && $except{$_} ); push @plugins, $_; } $_->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); } }; *{"${caller}::${subname}_ordered"} = sub { my $thing = shift; my @plugins = $thing->$subname(); $_->require for @plugins; return map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, ( $_->can('_order') ? $_->_order : 50 ) ] } @plugins; }; goto &Module::Pluggable::import; } 1; __END__ =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); 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 =head1 DESCRIPTION This module behaves exactly the same as C, supporting all of its options, but also mixes in the C and C methods 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. C extends the C method created by C to list the plugins in defined order. It looks for a C<_order> method in the modules found using C, 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 C<_order> subroutine is defined for a module, an arbitrary default value of 50 is used. =head1 OPTIONS The C 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 C and C 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" ]; =head1 SEE ALSO L, L =head1 AUTHOR Simon Cozens, Esimon@cpan.orgE (author emeritus) Christopher Nehren, Eapeiron@cpan.orgE (current maintainer) Please report bugs via the CPAN RT tracker at http://rt.cpan.org. =head1 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. =head1 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. =cut Module-Pluggable-Ordered-1.5/Makefile.PL000644 001750 001750 00000000612 10451732236 021176 0ustar00apeironapeiron000000 000000 use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( NAME => 'Module::Pluggable::Ordered', VERSION_FROM => 'Ordered.pm', # finds $VERSION PREREQ_PM => { Module::Pluggable => 1.9, UNIVERSAL::require => 0 }, # e.g., Module::Name => 1.1 ); Module-Pluggable-Ordered-1.5/README000644 001750 001750 00000003460 10451732236 020110 0ustar00apeironapeiron000000 000000 NAME Module::Pluggable::Ordered - Call module plugins in a specified order 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 { ... } DESCRIPTION This module behaves exactly the same as "Module::Pluggable", supporting all of its options, but also mixes in the "call_plugins" method to your class. "call_plugins" acts a little like "Class::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 using "Module::Pluggable" for ones which provide "my_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. SEE ALSO Module::Pluggable, Class::Trigger AUTHORS Simon Cozens, (author emeritus) Christopher Nehren, (current maintainer) 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 Thanks to Simon Cozens for originally writing this module. Module-Pluggable-Ordered-1.5/t/modules000700 001750 001750 00000000000 10451736157 021055 5ustar00apeironapeiron000000 000000 Module-Pluggable-Ordered-1.5/t/2.t000644 001750 001750 00000000745 10451732235 020023 0ustar00apeironapeiron000000 000000 package Foo; use Test::More tests => 3; use lib 't/modules/'; use Module::Pluggable::Ordered search_dirs => ['t/modules'], search_path => ['Foo'], sub_name => "test_plugins", except => ["Foo::One"]; ok(eq_set([Foo->test_plugins], ["Foo::Two", "Foo::Three"]), "We have two test plugins"); $main::order = 1; Foo->call_plugins("mycallback"); is($main::order, 2, "Only two plugins have been called"); Module-Pluggable-Ordered-1.5/t/3.t000644 001750 001750 00000000721 10451732235 020016 0ustar00apeironapeiron000000 000000 package Foo; use Test::More tests => 3; use lib 't/modules/'; use Module::Pluggable::Ordered search_dirs => ['t/modules'], search_path => ['Foo'], sub_name => "test_plugins", only => ["Foo::Two"]; ok(eq_set([Foo->test_plugins], ["Foo::Two"]), "We have one test plugin"); $main::order = 1; Foo->call_plugins("mycallback"); is($main::order, 2, "Only 1 plugin have been called"); Module-Pluggable-Ordered-1.5/t/4.t000644 001750 001750 00000000553 10451732312 020016 0ustar00apeironapeiron000000 000000 package Foo; use Test::More tests => 1; use lib 't/modules/'; use Module::Pluggable::Ordered search_dirs => ['t/modules'], search_path => ['Foo'], sub_name => "test_plugins"; is_deeply( [Foo->test_plugins_ordered], ["Foo::Two", "Foo::Three", "Foo::One"], 'Three test pluggins in order' ); Module-Pluggable-Ordered-1.5/t/1.t000644 001750 001750 00000000712 10451732235 020014 0ustar00apeironapeiron000000 000000 package Foo; use Test::More tests => 4; use lib 't/modules/'; use Module::Pluggable::Ordered search_dirs => ['t/modules'], search_path => ['Foo'], sub_name => "test_plugins"; ok(eq_set([Foo->test_plugins], ["Foo::One", "Foo::Two", "Foo::Three"]), "We have three test plugins"); $main::order = 1; Foo->call_plugins("mycallback"); is($main::order, 3, "Only two plugins have been called"); Module-Pluggable-Ordered-1.5/t/modules/Foo000700 001750 001750 00000000000 10451736157 021600 5ustar00apeironapeiron000000 000000 Module-Pluggable-Ordered-1.5/t/modules/Foo/Two.pm000644 001750 001750 00000000206 10451732357 022774 0ustar00apeironapeiron000000 000000 package Foo::Two; sub _order { 10 } sub mycallback_order { 0 } sub mycallback { Test::More::is($::order++, 1, "First plugin") } 1; Module-Pluggable-Ordered-1.5/t/modules/Foo/One.pm000644 001750 001750 00000000211 10451732337 022736 0ustar00apeironapeiron000000 000000 package Foo::One; sub _order { 70 }; sub mycallback_order { 20 } sub mycallback { Test::More::is($::order++, 2, "Second plugin") } 1; Module-Pluggable-Ordered-1.5/t/modules/Foo/Three.pm000644 001750 001750 00000000103 10451732235 023261 0ustar00apeironapeiron000000 000000 package Foo::Three; # This doesn't have that callback at all. 1;