mirror of
https://github.com/pragma-/pbot.git
synced 2025-02-02 15:34:05 +01:00
Add support for using an optional name
field to override language
Since Perl modules cannot use certain characters in the module name, such as the '+' character, modules cannot have names like "c++". Using a `name` field allows us to use, e.g., "cpp" as the module name and "c++" as the language name to invoke that module.
This commit is contained in:
parent
137a29cd3c
commit
14ebbe2533
@ -12,14 +12,32 @@ eval {
|
|||||||
use lib 'languages';
|
use lib 'languages';
|
||||||
require "$language.pm";
|
require "$language.pm";
|
||||||
} or do {
|
} or do {
|
||||||
print "Language '$language' is not supported.\n";
|
my @modules = glob 'languages/*.pm';
|
||||||
|
my $found = 0;
|
||||||
|
my ($languages, $comma) = ('', '');
|
||||||
|
|
||||||
my @languages = glob 'languages/*.pm';
|
foreach my $module (sort @modules) {
|
||||||
print "Supported languages are: ";
|
$module = basename $module;
|
||||||
print join(", ", grep { $_ = basename $_; $_ =~ s/.pm$//; $_ !~ m/^_/ } sort @languages);
|
$module =~ s/.pm$//;
|
||||||
print "\n";
|
next if $module =~ m/^_/;
|
||||||
|
require "$module.pm";
|
||||||
|
my $mod = $module->new;
|
||||||
|
|
||||||
exit;
|
if (exists $mod->{name} and $mod->{name} eq $language) {
|
||||||
|
$language = $module;
|
||||||
|
$found = 1;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
|
||||||
|
$module = $mod->{name} if exists $mod->{name};
|
||||||
|
$languages .= "$comma$module";
|
||||||
|
$comma = ', ';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not $found) {
|
||||||
|
print "Language '$language' is not supported.\nSupported languages are: $languages\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
my $nick = shift @ARGV // (print "Missing nick argument.\n" and die);
|
my $nick = shift @ARGV // (print "Missing nick argument.\n" and die);
|
||||||
|
Loading…
Reference in New Issue
Block a user