This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
loc_tools.pl: FIx to work on Android
authorKarl Williamson <public@khwilliamson.com>
Thu, 23 Jan 2014 17:52:38 +0000 (10:52 -0700)
committerKarl Williamson <public@khwilliamson.com>
Thu, 23 Jan 2014 18:00:44 +0000 (11:00 -0700)
Thanks to Brian Fraser for finding this and suggesting the kernel of
the patch.

The code to try to handle platforms without the POSIX module didn't work
properly.  This code had just been moved, unchanged, here from
lib/locale.t; it never got executed previously due to a skip_all.

This patch also makes sure minitest doesn't fail, and adds some comments

t/loc_tools.pl

index 45377a0..a3d8407 100644 (file)
@@ -1,12 +1,13 @@
 # Common tools for test files files to find the locales which exist on the
-# system.
+# system.  Caller should have defined ok() for the unlikely event that setup
+# here fails, and should have verified that this isn't miniperl before calling
+# the functions.
 
 # Note that it's okay that some languages have their native names
 # capitalized here even though that's not "right".  They are lowercased
 # 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 2nd iff the platform supports the locale,
                     # and it is not already on the list
@@ -57,13 +58,8 @@ sub _decode_encodings {
 sub find_locales {  # Returns an array of all the locales we found on the
                     # system
 
-
-    my $have_setlocale = 0;
-    eval {
-        require POSIX;
-        import POSIX ':locale_h';
-        $have_setlocale++;
-    };
+    use Config;;
+    my $have_setlocale = $Config{d_setlocale};
 
     # Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
     # and mingw32 uses said silly CRT
@@ -79,6 +75,10 @@ sub find_locales {  # Returns an array of all the locales we found on the
 
     return unless $have_setlocale;
 
+    # Done this way in case this is 'required' in the caller before seeing if
+    # this is miniperl.
+    require POSIX; import POSIX 'locale_h';
+
     _trylocale("C", \@Locale);
     _trylocale("POSIX", \@Locale);
     foreach (0..15) {