diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2015-08-01 22:50:39 -0400 |
---|---|---|
committer | Steve Hay <steve.m.hay@googlemail.com> | 2015-10-30 20:49:46 +0000 |
commit | 2e11e4a36dc269f78dd0e2de9629a6c34644019d (patch) | |
tree | 3f2046b532e329e80c7e8e042e91cfc3793fc9fb | |
parent | b69cc3e4c71f53eca5dfd8e69b9196bf2eae719d (diff) | |
download | perl-2e11e4a36dc269f78dd0e2de9629a6c34644019d.tar.gz |
Check for POSIX locales once.
Makes loc_tools users safe under minitest.
Currently op/quotemeta.t and op/taint.t are failing there.
(cherry picked from commit a274778c55a0011ece54485245cd8622d8f34570)
-rw-r--r-- | t/loc_tools.pl | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/t/loc_tools.pl b/t/loc_tools.pl index bf0396f388..541e08f1b4 100644 --- a/t/loc_tools.pl +++ b/t/loc_tools.pl @@ -11,6 +11,9 @@ # 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 @@ -112,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. @@ -172,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); @@ -296,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; @@ -347,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. |