diff --git a/lib/WebGUI/Pluggable.pm b/lib/WebGUI/Pluggable.pm index 68eb31726..598c60961 100644 --- a/lib/WebGUI/Pluggable.pm +++ b/lib/WebGUI/Pluggable.pm @@ -70,6 +70,7 @@ Return an array of all the modules in the given namespace. Will search all onelevel => If true, only find sub modules (children), no deeper find( "CGI", { onelevel => 1 } ) would match "CGI::Session" but not "CGI::Session::File" + return => "name" - Return just the last part of the package, so CGI::Session would return "Session" =cut @@ -111,6 +112,12 @@ sub find { @modules = keys %modulesHash; } + ### Return valu + # If "name", just grab the last part + if ( $options->{ return } eq "name" ) { + @modules = map { /::([^:]+)$/; $1 } @modules; + } + return @modules; } diff --git a/t/Pluggable.t b/t/Pluggable.t index 237ac7b05..5de76199c 100644 --- a/t/Pluggable.t +++ b/t/Pluggable.t @@ -41,7 +41,7 @@ use WebGUI::Pluggable; #---------------------------------------------------------------------------- # Tests -plan tests => 7; # Increment this number for each test you create +plan tests => 8; # Increment this number for each test you create #---------------------------------------------------------------------------- # put your tests here @@ -100,7 +100,12 @@ is($dumper->Dump, q|$VAR1 = { bag( grep { $_ ne 'WebGUI::i18n::English::WebGUI' } @testFiles ), "find() with exclude", ); - + + cmp_deeply( + [ WebGUI::Pluggable::find( 'WebGUI::i18n', { onelevel => 1, return => "name" } ) ], + bag( map { /::([^:]+)$/; $1 } grep { /^WebGUI::i18n::[^:]+$/ } @testFiles ), + "find() with return => name", + ); }; #----------------------------------------------------------------------------