Skip Menu |

This queue is for tickets about the Module-Pluggable CPAN distribution.

Report information
The Basics
Id: 55465
Status: resolved
Priority: 0/
Queue: Module-Pluggable

People
Owner: Nobody in particular
Requestors: leonerd-cpan [...] leonerd.org.uk
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Please allow require-or-die semantics
Hi there, often I use Module::Pluggable, or my own wrapping around it, Module::PluginFinder, to easily support extensions to programs. I find the following pattern keeps coming up: use Module::Pluggable sub_name => "net_types", search_path => [ "Circle::Net" ]; { foreach my $class ( net_types ) { ( my $file = "$class.pm" ) =~ s{::}{/}g; require $file; } } The problem is that if I just use the 'require => 1' option to Module::Pluggable, it tries its best to load all the plugins, skipping over the ones it couldn't load. Sometimes I want the behaviour that any error should be fatal. Perhaps there could be an option to die fatally on the first require failure by use Module::Pluggable require_or_die => 1,... or some-such option name? -- Paul Evans
Show quoted text
> { > foreach my $class ( net_types ) { > ( my $file = "$class.pm" ) =~ s{::}{/}g; > require $file; > } > }
Actually, even this isn't very satisfactory. On my veryslow AMD Geode 233 embedded router, such a pattern adds about 7 seconds to the startup time of a program; inconvenient if it's supposed to be a fairly quick one-shot command. This is because every require() call has to perform a complete @INC search. -- Paul Evans
On Mon May 03 14:16:46 2010, PEVANS wrote: Show quoted text
> Actually, even this isn't very satisfactory. On my veryslow AMD Geode > 233 embedded router, such a pattern adds about 7 seconds to the startup > time of a program; inconvenient if it's supposed to be a fairly quick > one-shot command. This is because every require() call has to perform a > complete @INC search.
I've just created a new branch called triggers https://github.com/simonwistow/Module-Pluggable/tree/triggers that should help with this feature request. Have a look at https://github.com/simonwistow/Module-Pluggable/blob/triggers/t/22trigger.t in this case what you could do is provide a sub routine to either the 'before_require' or 'on_error' triggers. So, something like package MyModule; use Module::Pluggable require => 1, on_error => sub { my ($plugin, $error) = @_; die "$plugin failed to load: '$error'" }; Can you take a look and see if that meets your needs?
Released as 4.1