This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
porting/maintainers.t: Skip on EBCDIC
[perl5.git] / t / loc_tools.pl
index 44bf555..541e08f 100644 (file)
@@ -8,13 +8,20 @@
 # anyway later during the scanning process (and besides, some clueless
 # vendor might have them capitalized erroneously anyway).
 
-sub _trylocale ($$$$) { # Adds the locale given by the first parameter to the
-                        # list given by the 3rd iff the platform supports the
-                        # locale in each of the categories given by the 2nd
-                        # parameter, which is either a single category or a
-                        # reference to a list of categories
-                        # The 4th parameter is true if to reject locales that
-                        # aren't apparently fully compatible with Perl.
+# Functions whose names begin with underscore are internal helper functions
+# for this file, and are not to be used by outside callers.
+
+eval { require POSIX; import POSIX 'locale_h'; };
+my $has_posix_locales = defined &POSIX::LC_CTYPE;
+
+sub _trylocale ($$$$) { # For use only by other functions in this file!
+
+    # Adds the locale given by the first parameter to the list given by the
+    # 3rd iff the platform supports the locale in each of the categories given
+    # by the 2nd parameter, which is either a single category or a reference
+    # to a list of categories The 4th parameter is true if to reject locales
+    # that aren't apparently fully compatible with Perl.
+
     my $locale = shift;
     my $categories = shift;
     my $list = shift;
@@ -46,7 +53,7 @@ sub _trylocale ($$$$) { # Adds the locale given by the first parameter to the
     push @$list, $locale;
 }
 
-sub _decode_encodings {
+sub _decode_encodings { # For use only by other functions in this file!
     my @enc;
 
     foreach (split(/ /, shift)) {
@@ -108,12 +115,13 @@ sub locales_enabled(;$) {
     # category, like 'LC_TIME'.  The initial 'LC_' is optional.  It is a fatal
     # error to call this with something that isn't a known category
 
-    use Config;;
+    use Config;
 
     return 0 unless    $Config{d_setlocale}
                         # I (khw) cargo-culted the '?' in the pattern on the
                         # next line.
-                    && $Config{ccflags} !~ /\bD?NO_LOCALE\b/;
+                    && $Config{ccflags} !~ /\bD?NO_LOCALE\b/
+                    && $has_posix_locales;
 
     # Done with the global possibilities.  Now check if any passed in category
     # is disabled.
@@ -168,10 +176,7 @@ sub find_locales ($;$) {  # Returns an array of all the locales we found on the
 
     # Done this way in case this is 'required' in the caller before seeing if
     # this is miniperl.
-    eval { require POSIX; import POSIX 'locale_h'; };
-    unless (defined &POSIX::LC_CTYPE) {
-      return;
-    }
+    return unless $has_posix_locales;
 
     _trylocale("C", $categories, \@Locale, $only_plays_well);
     _trylocale("POSIX", $categories, \@Locale, $only_plays_well);
@@ -292,8 +297,7 @@ sub is_locale_utf8 ($) { # Return a boolean as to if core Perl thinks the input
     # On z/OS, even locales marked as UTF-8 aren't.
     return 0 if ord "A" != 65;
 
-    eval { require POSIX; import POSIX 'locale_h'; };
-    return 0 if ! defined &POSIX::LC_CTYPE;
+    return 0 if ! $has_posix_locales;
     return 0 if ! locales_enabled('LC_CTYPE');
 
     my $locale = shift;
@@ -343,8 +347,7 @@ sub find_utf8_ctype_locale (;$) { # Return the name of a locale that core Perl
     my $locales_ref = shift;
 
     if (! defined $locales_ref) {
-        eval { require POSIX; import POSIX 'locale_h'; };
-        return if ! defined &POSIX::LC_CTYPE;
+        return if ! $has_posix_locales;
 
         my @locales = find_locales(&POSIX::LC_CTYPE(),
                                    1 # Reject iffy locales.