From a2757494af615a31e4af572195cc202c3cd67ed2 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Wed, 17 Sep 2008 15:38:01 +0000 Subject: [PATCH] use Module::Find instead of enumerating over the files --- docs/gotcha.txt | 5 +++++ lib/WebGUI/AssetLineage.pm | 7 ++----- lib/WebGUI/Form/FieldType.pm | 11 ++++++----- lib/WebGUI/Help/Macros.pm | 12 +++--------- lib/WebGUI/International.pm | 12 ++++-------- sbin/testEnvironment.pl | 1 + 6 files changed, 21 insertions(+), 27 deletions(-) diff --git a/docs/gotcha.txt b/docs/gotcha.txt index df83d776d..9acb260dd 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -7,6 +7,11 @@ upgrading from one version to the next, or even between multiple versions. Be sure to heed the warnings contained herein as they will save you many hours of grief. +7.6.0 +-------------------------------------------------------------------- + * WebGUI now requires Module::Find version 0.06 or greater. + + 7.5.21 -------------------------------------------------------------------- * Previous versions of WebGUI used the wrong day of the week for diff --git a/lib/WebGUI/AssetLineage.pm b/lib/WebGUI/AssetLineage.pm index 46a4a8320..ec1c7446e 100644 --- a/lib/WebGUI/AssetLineage.pm +++ b/lib/WebGUI/AssetLineage.pm @@ -564,11 +564,8 @@ sub getLineageSql { my $tables = "asset left join assetData on asset.assetId=assetData.assetId "; if (exists $rules->{joinClass}) { my $className = $rules->{joinClass}; - my $file = $className; - $file =~ s{::}{/}g; - $file .= '.pm'; - if (!exists $INC{ $file }) { ##Alread loaded? - eval{ require $file }; + (my $module = $className . '.pm') =~ s{::|'}{/}g; + if ( ! eval { require $module; 1 }) { $self->session->errorHandler->fatal("Couldn't compile asset package: ".$className.". Root cause: ".$@) if ($@); } foreach my $definition (@{$className->definition($self->session)}) { diff --git a/lib/WebGUI/Form/FieldType.pm b/lib/WebGUI/Form/FieldType.pm index 79fd327d1..77ca7ae97 100644 --- a/lib/WebGUI/Form/FieldType.pm +++ b/lib/WebGUI/Form/FieldType.pm @@ -20,6 +20,7 @@ use Tie::IxHash; use WebGUI::International; use WebGUI::Pluggable; use WebGUI::Utility; +use Module::Find qw(findsubmod); =head1 NAME @@ -112,15 +113,15 @@ sub getTypes { my $self = shift; my @types = @{$self->get('types')}; unless (scalar(@types)) { - opendir(DIR,$self->session->config->getWebguiRoot."/lib/WebGUI/Form/"); - foreach my $type (readdir(DIR)) { - if ($type =~ s/^(.*)\.pm$/$1/) { - if (WebGUI::Pluggable::instanciate('WebGUI::Form::'.ucfirst($type),'isDynamicCompatible')) { + my @classes = findsubmod 'WebGUI::Form'; + for my $class (@classes) { + if ($class =~ /^WebGUI::Form::(.*)/) { + my $type = $1; + if (WebGUI::Pluggable::instanciate($class, 'isDynamicCompatible')) { push @types, $type; } } } - closedir(DIR); } my %fields = (); foreach my $type (@types) { diff --git a/lib/WebGUI/Help/Macros.pm b/lib/WebGUI/Help/Macros.pm index c0fcc065a..a3aad78ca 100644 --- a/lib/WebGUI/Help/Macros.pm +++ b/lib/WebGUI/Help/Macros.pm @@ -1,5 +1,6 @@ package WebGUI::Help::Macros; use strict; +use Module::Find qw(findsubmod); our $HELP = { @@ -7,15 +8,8 @@ our $HELP = { title => 'macros list title', body => sub { my $session = shift; - my $dir = join '/', $session->config->getWebguiRoot, "lib", "WebGUI", "Macro"; - opendir( DIR, $dir ) or $session->errorHandler->fatal("Can't open Macro directory: $dir!"); - my @macros = (); - foreach my $dir (readdir(DIR)) { - next unless $dir =~ /\.pm$/; - $dir =~ s/\.pm//; - push @macros, $dir; - } - closedir(DIR); + my @macroModules = findsubmod 'WebGUI::Macro'; + my @macros = map { /^WebGUI::Macro::(.*)/; $1 } @macroModules; ##Build list of enabled macros, by namespace, by reversing session hash: my %configMacros = %{ $session->config->get("macros") }; diff --git a/lib/WebGUI/International.pm b/lib/WebGUI/International.pm index 80dcb58c4..20a1f737b 100644 --- a/lib/WebGUI/International.pm +++ b/lib/WebGUI/International.pm @@ -18,6 +18,7 @@ package WebGUI::International; use strict qw(vars subs); use WebGUI::Session; use WebGUI::Pluggable; +use Module::Find qw(findsubmod); =head1 NAME @@ -185,15 +186,10 @@ Returns a hash reference to the languages installed on this WebGUI system. sub getLanguages { my ($self) = @_; my $hashRef; - my $dir = $self->session->config->getWebguiRoot."/lib/WebGUI/i18n"; - opendir my $dh, $dir or $self->session->errorHandler->fatal("Can't open I18N directory! ".$dir); - while (my $file = readdir($dh)) { - next - unless $file =~ s/\.pm$//; - my $language = $file; - $hashRef->{$language} = $self->getLanguage($language, "label"); + for my $lang ( findsubmod 'WebGUI::i18n' ) { + $lang =~ s/^WebGUI::i18n:://; + $hashRef->{$lang} = $self->getLanguage($lang, "label"); } - closedir $dh; return $hashRef; } diff --git a/sbin/testEnvironment.pl b/sbin/testEnvironment.pl index ef8ab7d69..94267168e 100644 --- a/sbin/testEnvironment.pl +++ b/sbin/testEnvironment.pl @@ -114,6 +114,7 @@ checkModule("Path::Class", '0.16' ); checkModule("Exception::Class", "1.23" ); checkModule("List::MoreUtils", "0.22" ); checkModule("File::Path", "2.04" ); +checkModule("Module::Find", "0.06" ); ###################################