Skip Menu |

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

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

People
Owner: simonw [...] cpan.org
Requestors: barbie [...] missbarbell.co.uk
Cc:
AdminCc:

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



Subject: override or add to search_path after import
Once you use the module, the import method creates the plugins() method. However, it only references the opts{search_path} when its called. If I wanted to extend this search_path after the initial import, I have to put up with 'Subroutine plugins redefined' warnings and reimport :( My thought was whether you could create an accessor within the import, so that I only need call something like $self->search_path( add => 'My::New::Path'), where the keyword could be something like new/add. Attached is a patch for v2.6, which is woefully incomplete (no POD or tests), but hopefully it gives you a starting point ;)
--- C:\wip\diffs\Module-Pluggable\Module-Pluggable-2.6/lib/Module/Pluggable.pm Wed Feb 2 14:52:46 2005 +++ C:\wip\diffs\Module-Pluggable\Module-Pluggable-2.6-barbie/lib/Module/Pluggable.pm Fri Feb 4 15:00:59 2005 @@ -382,9 +382,19 @@ }; + my $searchsub = sub { + my $self = shift; + my ($action,@paths) = @_; + push @{$opts{'search_path'}}, @paths if($action eq 'add'); + $opts{'search_path'} } = \@paths if($action eq 'new'); + return $opts{'search_path'}; + }; + + no strict 'refs'; *{"$pkg\::$sub"} = $subroutine; + *{"$pkg\::search_path"} = $searchsub; }