Skip to content

Commit

Permalink
Optimize code for checking modules
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Oct 25, 2024
1 parent b4dba0f commit c1761c2
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions gedcom
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ BEGIN {
if(scalar(@needfull)) {
my $list = join(' ', @needfull);
print "Installing $list\n";
# system("cpan -i $list");
$ENV{'PERL_MM_USE_DEFAULT'} = 1;
# system("cpan -i $list");
system('perl -MCPAN -e \'CPAN::Shell->install("' . join('", "', @needfull) . '")\'');
}
# $Devel::FIXME::REPAIR_INC = 1;
Expand All @@ -160,26 +160,21 @@ BEGIN {
};
}

foreach my $module(@needfull) {
my $version;
if($module =~ /(.+)\s(.+)$/) {
$module = $1;
$version = $2;
}
if($module =~ /.+\/(.+)/) {
$module = $1;
}
$module =~ s/\-/::/g;
$module =~ s/\.tar\.gz$//;
$module =~ s/::(\d)+$/ $1/;
eval "require $module";
if($@) {
die $@;
}
$module->import();
# if($version && ($module::VERSION < $version)) {
# die "$module: need $version got ", $module::VERSION;
# }
foreach my $module (@needfull) {
my ($name, $version) = $module =~ /(.+?)\s(.+)?$/;
$name ||= $module;

# Extract module name, replacing hyphens with `::` and removing extensions
$name =~ s{.+/}{}; # Remove path if present
$name =~ s{-}{::}g; # Convert hyphens to `::`
$name =~ s{\.tar\.gz$}{}; # Remove file extension
$name =~ s{::(\d+)$}{ $1}; # Adjust version formatting if embedded in module name

eval "require $name" or die $@;
$name->import();

# Uncomment to check version if needed
# die "$name: need $version, got " . $name->VERSION if $version && $name->VERSION < $version;
}

# use IPC::System::Simple;
Expand Down

0 comments on commit c1761c2

Please sign in to comment.