diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 7d431d5c9..8615b4aab 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -18,6 +18,7 @@ - fixed #11228: Gallery image upload to other users folder permission denied - added USPS International driver. - added #10727: language choice during site adding + - added file globbing to preload.exclude 7.8.4 - Fixed a compatibility problem between WRE and new Spectre code. diff --git a/lib/WebGUI/Pluggable.pm b/lib/WebGUI/Pluggable.pm index 22802dab8..003dda97f 100644 --- a/lib/WebGUI/Pluggable.pm +++ b/lib/WebGUI/Pluggable.pm @@ -66,7 +66,7 @@ These functions are available from this package: Return an array of all the modules in the given namespace. Will search all @INC directories. C is a hashref of options with the following keys - exclude => An arrayref of modules to exclude + exclude => An arrayref of modules to exclude. A module name can include an asterisk to glob. onelevel => If true, only find sub modules (children), no deeper find( "CGI", { onelevel => 1 } ) would match "CGI::Session" but not "CGI::Session::File" @@ -110,6 +110,12 @@ sub find { @modulesHash{ @modules } = ( 1 ) x @modules; delete @modulesHash{ @{ $options->{exclude} } }; @modules = keys %modulesHash; + my @excludePatterns = map { s/(? 8; # Increment this number for each test you create +plan tests => 11; # Increment this number for each test you create #---------------------------------------------------------------------------- # put your tests here @@ -82,7 +82,7 @@ is($dumper->Dump, q|$VAR1 = { }, File::Spec->catfile( $lib, 'WebGUI', 'i18n' ), ); - + cmp_deeply( [ WebGUI::Pluggable::find( 'WebGUI::i18n' ) ], bag( @testFiles ), @@ -100,7 +100,30 @@ is($dumper->Dump, q|$VAR1 = { bag( grep { $_ ne 'WebGUI::i18n::English::WebGUI' } @testFiles ), "find() with exclude", ); - + + cmp_deeply( + [ WebGUI::Pluggable::find( 'WebGUI::i18n', { exclude => [ 'WebGUI::i18n::English::WebGUI*' ] } ) ], + bag( grep { $_ ne 'WebGUI::i18n::English::WebGUI' || $_ ne 'WebGUI::i18n::English::WebGUIProfile' } @testFiles ), + "find() with exclude with glob", + ); + + cmp_deeply( + [ WebGUI::Pluggable::find( 'WebGUI::i18n', { exclude => [ 'WebGUI::i18n::English::WebGUI.*' ] } ) ], + bag( grep { $_ ne 'WebGUI::i18n::English::WebGUI' || $_ ne 'WebGUI::i18n::English::WebGUIProfile' } @testFiles ), + "find() with exclude with regex", + ); + + cmp_deeply( + [ WebGUI::Pluggable::find( 'WebGUI::i18n', { exclude => [ qw/WebGUI::i18n::English::WebGUI.* WebGUI::i18n::English::ShipDriver_USPS*/ ] } ) ], + bag( grep { + $_ ne 'WebGUI::i18n::English::WebGUI' + || $_ ne 'WebGUI::i18n::English::WebGUIProfile' + || $_ ne 'WebGUI::i18n::English::ShipDriver_USPS' + || $_ ne 'WebGUI::i18n::English::ShipDriver_USPSInternational' + } @testFiles ), + "find() with multiple excludes", + ); + cmp_deeply( [ WebGUI::Pluggable::find( 'WebGUI::i18n', { onelevel => 1, return => "name" } ) ], bag( map { /::([^:]+)$/; $1 } grep { /^WebGUI::i18n::[^:]+$/ } @testFiles ),