commit:     0d1716def24bdc9a0bc90030bd952e08284b6451
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sun Jan 11 08:20:01 2026 +0000
Commit:     Kerin Millar <kfm <AT> plushkava <DOT> net>
CommitDate: Sun Jan 11 08:59:46 2026 +0000
URL:        https://gitweb.gentoo.org/proj/locale-gen.git/commit/?id=0d1716de

Use lexical subroutines where applicable

Given that lexical subroutines have been a stable feature since the
release of Perl v5.26, one might as well use them. Some might find the
code easier to digest as a result.

Both mkconfig and the parse_config() subroutine of locale-gen are
touched by this change.

Link: https://perldoc.perl.org/5.26.0/perlsub#Lexical-Subroutines
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>

 locale-gen | 22 +++++++++++-----------
 mkconfig   |  6 +++---
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/locale-gen b/locale-gen
index 508eedf..d79a60e 100644
--- a/locale-gen
+++ b/locale-gen
@@ -343,11 +343,11 @@ sub parse_config ($fh, $path, $supported_by, $be_strict) {
        my @locales;
        my $line;
 
-       # Set up a helper routine to throw for validation errors.
-       my $thrower = sub ($error, $is_fatal = 0) {
+       # Set up a helper routine to raise validation errors.
+       my sub invalidate ($error, $is_malformed = 0) {
                my $message = sprintf '%s at %s[%d]: %s',
                        $error, $path, $., render_printable($line);
-               if ($be_strict || $is_fatal) {
+               if ($be_strict || $is_malformed) {
                        die "$PROGRAM: $message\n";
                } else {
                        print_warning("WARNING! $message\n");
@@ -355,10 +355,10 @@ sub parse_config ($fh, $path, $supported_by, $be_strict) {
        };
 
        # Set up a helper routine to issue warnings regarding the UTF8 misnomer.
-       my $utf8_warner = sub ($i) {
+       my sub warn_for_utf8 ($key) {
                print_warning(sprintf
                        "WARNING! UTF8 should be written as UTF-8 in field #%d 
at %s[%d]: %s\n",
-                       $i, $path, $., render_printable($line));
+                       $key, $path, $., render_printable($line));
        };
 
        # Select an appropriate adjective for errors of validation.
@@ -383,27 +383,27 @@ sub parse_config ($fh, $path, $supported_by, $be_strict) {
                if (0 < (@fields = split /\h+/, trim_line($line), 3) < 3 && ! 
grep +( m/\// ), @fields) {
                        ($locale, $charmap) = ($fields[0], $fields[1] // 
'UTF-8');
                } else {
-                       $thrower->('Malformed locale declaration', 1);
+                       invalidate('Malformed locale declaration', 1);
                }
 
                # Handle "UTF8" as a special case. Though glibc tolerates it,
                # locale-gen would otherwise not because there is no charmap
                # file by that name. This code will eventually be removed.
                if ($locale =~ s/\.UTF\K8(?=@|\z)/-8/) {
-                       $utf8_warner->(1);
+                       warn_for_utf8(1);
                }
                if ($charmap =~ s/^UTF\K8\z/-8/) {
-                       $utf8_warner->(2);
+                       warn_for_utf8(2);
                }
 
                # Validate both locale and character map before accepting.
                my $is_aliasable;
                if (! $supported_by->{$locale}) {
-                       $thrower->("$adjective locale");
+                       invalidate("$adjective locale");
                } elsif (! $supported_by->{''}{$charmap}) {
-                       $thrower->("$adjective charmap");
+                       invalidate("$adjective charmap");
                } elsif (! defined($is_aliasable = 
$supported_by->{$locale}{$charmap})) {
-                       $thrower->("$adjective locale/charmap combination");
+                       invalidate("$adjective locale/charmap combination");
                }
 
                # Strip the codeset part from the locale, if any. The names of

diff --git a/mkconfig b/mkconfig
index 7216348..3ae983e 100755
--- a/mkconfig
+++ b/mkconfig
@@ -30,7 +30,7 @@ use File::Slurper qw(read_dir read_lines read_text);
 
        my $locale;
 
-       my $thrower = sub ($format) {
+       my sub abort ($format) {
                my $path = catfile($prefix, '/usr/share/i18n/locales', $locale);
                die sprintf "mkconfig: $format", $path;
        };
@@ -50,9 +50,9 @@ use File::Slurper qw(read_dir read_lines read_text);
                # Compose a commented entry which also has a trailing comment,
                # indicating the language and territory in plain English.
                if (! exists $attr_by->{$locale}) {
-                       $thrower->("Aborting because the '%s' file is 
missing\n");
+                       abort("Aborting because the '%s' file is missing\n");
                } elsif (! $attr_by->{$locale}->%*) {
-                       $thrower->("Aborting because no language attribute was 
found in '%s'\n");
+                       abort("Aborting because no language attribute was found 
in '%s'\n");
                } else {
                        my ($comment, $territory) = 
$attr_by->{$locale}->@{'language', 'territory'};
                        if (length $territory) {

Reply via email to