Skip to content

Commit

Permalink
[Fix 72] generator config is not case-sensitive consistent
Browse files Browse the repository at this point in the history
Perl's `can_load` is case-insensitive which means that the system can find case variations of generator names but `Thunk` later cannot properly load the module.

For now, it detects the typo on the generator name but only warns the user instead of assuming which one they intended, to prevent allowing variations of the names to be used in source code.
  • Loading branch information
uroboro committed Dec 28, 2023
1 parent 62814c1 commit d8eb1cd
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions bin/lib/Logos/Generator.pm
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package Logos::Generator;
use strict;
use File::Basename;
use Logos::Generator::Thunk;
use Scalar::Util qw(blessed);
use List::Util qw(any);
use Module::Load::Conditional qw(can_load);
$Module::Load::Conditional::VERBOSE = 1;
our $GeneratorPackage = "";
Expand Down Expand Up @@ -40,9 +42,20 @@ sub use {
unshift @INC, $2;
}
$GeneratorPackage = "Logos::Generator::".$generatorName;
::fileError(-1, "I can't find the $generatorName Generator!") if(!can_load(modules => {
$GeneratorPackage."::Generator" => undef
}));
::fileError(-1, "I can't find the '$generatorName' Generator!") if (!can_load(modules => {
$GeneratorPackage . "::Generator" => undef
}));

# Guard against case insensitive filesystems finding the module but not being able to load it
my @availableGeneratorPaths = glob(dirname(__FILE__) . "/Generator/*");
my @availableGenerators = map {basename($_)} @availableGeneratorPaths;
my $generatorDirectoryExists = any {$_ eq $generatorName} @availableGenerators;

if ($generatorDirectoryExists != 1) {
my %generatorNames = map {lc($_) => $_} @availableGenerators;
my $possibleGeneratorName = $generatorNames{lc($generatorName)};
::fileError(-1, "I can't find the '$generatorName' Generator, did you mean '$possibleGeneratorName'?");
}
}

1;

0 comments on commit d8eb1cd

Please sign in to comment.