Allow 'use locale' on systems without locales.
authorKarl Williamson <public@khwilliamson.com>
Wed, 22 Jan 2014 21:23:26 +0000 (14:23 -0700)
committerKarl Williamson <public@khwilliamson.com>
Fri, 24 Jan 2014 01:27:40 +0000 (18:27 -0700)
Instead of throwing an error, just go ahead and do the import.
This will tell Perl internally to use the current underlying locale,
which should be the C locale.  Attempts to change the locale will fail.

This differs slightly from Brian Fraser's patch, in that his didn't
touch $^H, thus 'use locale' was a no-op.  He has told me to apply this
one, which does affect $^H.  The advantage here is that now programs
that are run on platforms with and without locales will behave
similarly, and should run identically if the locale is not switched from
the default.

lib/locale.pm
pod/perldelta.pod

index ed254cc..97b324f 100644 (file)
@@ -1,6 +1,6 @@
 package locale;
 
-our $VERSION = '1.02';
+our $VERSION = '1.03';
 use Config;
 
 $Carp::Internal{ (__PACKAGE__) } = 1;
@@ -47,13 +47,8 @@ Unicode and locales, including UTF-8 locales.
 See L<perllocale> for more detailed information on how Perl supports
 locales.
 
-=head1 NOTE
-
-If your system does not support locales, then loading this module will
-cause the program to die with a message:
-
-    "Your vendor does not support locales, you cannot use the locale
-    module."
+On systems that don't have locales, this pragma will cause your operations
+to behave as if in the "C" locale; attempts to change the locale will fail.
 
 =cut
 
@@ -70,11 +65,6 @@ $locale::not_chars_hint_bits = 0x10;
 sub import {
     shift;  # should be 'locale'; not checked
 
-    if(!$Config{d_setlocale}) {
-        ## No locale support found on this Perl, giving up:
-        die('Your vendor does not support locales, you cannot use the locale module.');
-    }
-
     my $found_not_chars = 0;
     while (defined (my $arg = shift)) {
         if ($arg eq ":not_characters") {
index 8ed60ca..7cc963d 100644 (file)
@@ -25,7 +25,13 @@ XXX New core language features go here.  Summarize user-visible core language
 enhancements.  Particularly prominent performance optimisations could go
 here, but most should go in the L</Performance Enhancements> section.
 
-[ List each enhancement as a =head2 entry ]
+=head2 C<S<use locale>> now compiles on systems without locale ability
+
+Previously doing this caused the program to not compile.  Within its
+scope the program behaves as if in the "C" locale.  Thus programs
+written for platforms that support locales can run on locale-less
+platforms without change.  Attempts to change the locale away from the
+"C" locale will, of course, fail.
 
 =head1 Security