Skip to content

Commit d8eb1cd

Browse files
author
uroboro
committed
[Fix 72] generator config is not case-sensitive consistent
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.
1 parent 62814c1 commit d8eb1cd

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

bin/lib/Logos/Generator.pm

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package Logos::Generator;
22
use strict;
3+
use File::Basename;
34
use Logos::Generator::Thunk;
45
use Scalar::Util qw(blessed);
6+
use List::Util qw(any);
57
use Module::Load::Conditional qw(can_load);
68
$Module::Load::Conditional::VERBOSE = 1;
79
our $GeneratorPackage = "";
@@ -40,9 +42,20 @@ sub use {
4042
unshift @INC, $2;
4143
}
4244
$GeneratorPackage = "Logos::Generator::".$generatorName;
43-
::fileError(-1, "I can't find the $generatorName Generator!") if(!can_load(modules => {
44-
$GeneratorPackage."::Generator" => undef
45-
}));
45+
::fileError(-1, "I can't find the '$generatorName' Generator!") if (!can_load(modules => {
46+
$GeneratorPackage . "::Generator" => undef
47+
}));
48+
49+
# Guard against case insensitive filesystems finding the module but not being able to load it
50+
my @availableGeneratorPaths = glob(dirname(__FILE__) . "/Generator/*");
51+
my @availableGenerators = map {basename($_)} @availableGeneratorPaths;
52+
my $generatorDirectoryExists = any {$_ eq $generatorName} @availableGenerators;
53+
54+
if ($generatorDirectoryExists != 1) {
55+
my %generatorNames = map {lc($_) => $_} @availableGenerators;
56+
my $possibleGeneratorName = $generatorNames{lc($generatorName)};
57+
::fileError(-1, "I can't find the '$generatorName' Generator, did you mean '$possibleGeneratorName'?");
58+
}
4659
}
4760

4861
1;

0 commit comments

Comments
 (0)