Skip Menu |
 

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 105185
Status: open
Priority: 0/
Queue: Moose

People
Owner: Nobody in particular
Requestors: BENNING [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: validation of Num fails if LC_NUMERIC is set to locale with comma instead of point
Download (untitled) / with headers
text/plain 644b
If a locale like de_DE is set perl will use a ',' instead of '.' when using the number as string. In this case the validation for Num fails with: Validation failed for 'Num' with value 2,5 Since the validation is done using a regular expression the locale string format is used. perl version: 5.18.1 Moose version: 2.1405 Output of attached test script: $ perl moose-num-test.pl Number is: 2.5 Attribute (number) does not pass the type constraint because: Validation failed for 'Num' with value 2,5 at reader Numbers::number (defined at test.pl line 13) line 13 Numbers::number('Numbers=HASH(0x139e0430)') called at test.pl line 28
Subject: moose-num-test.pl
Download moose-num-test.pl
text/x-perl 431b
#!/usr/bin/perl package Numbers; use Moose; has 'number' => ( is => 'ro', isa => 'Num', lazy => 1, default => sub { my $num = 2.5; return $num; }, ); package main; use strict; use warnings; use POSIX qw( setlocale LC_NUMERIC ); my $num = Numbers->new; print "Number is: ".$num->number."\n"; setlocale( LC_NUMERIC, 'de_DE.UTF-8' ); my $num_de = Numbers->new; print "German number is: ".$num_de->number."\n";
Download (untitled) / with headers
text/plain 113b
May be using perlapis looks_like_number() is an option: https://metacpan.org/pod/Scalar::Util#looks_like_number
Download (untitled) / with headers
text/plain 500b
On 2015-06-12 03:56:50, BENNING wrote: Show quoted text
> If a locale like de_DE is set perl will use a ',' instead of '.' when > using the number as string. > In this case the validation for Num fails with: > > Validation failed for 'Num' with value 2,5 > > Since the validation is done using a regular expression the locale > string format is used. > > perl version: 5.18.1 > Moose version: 2.1405
The problem only exists for perl <= 5.18.4. With perl >= 5.20.0 the validation seems to be locale-independent.
Download (untitled) / with headers
text/plain 739b
On 2015-06-12 13:22:20, SREZIC wrote: Show quoted text
> On 2015-06-12 03:56:50, BENNING wrote:
> > If a locale like de_DE is set perl will use a ',' instead of '.' when > > using the number as string. > > In this case the validation for Num fails with: > > > > Validation failed for 'Num' with value 2,5 > > > > Since the validation is done using a regular expression the locale > > string format is used. > > > > perl version: 5.18.1 > > Moose version: 2.1405
> > The problem only exists for perl <= 5.18.4. With perl >= 5.20.0 the > validation seems to be locale-independent.
I wonder if the type constraints should be considering the locale when considering the validity of an input... I am reluctant to make any changes without some more comments.
Download (untitled) / with headers
text/plain 866b
Am Mo 15. Jun 2015, 15:34:10, ETHER schrieb: Show quoted text
> I wonder if the type constraints should be considering the locale when > considering the validity of an input... I am reluctant to make any > changes without some more comments.
I would expect that the Moose Num type accepts what ever perl would accept (or generates) as a numeric value. But it seams like this behaviour is a bug in perl and was fixed in 5.19.1: -- http://search.cpan.org/dist/perl-5.19.1/pod/perldelta.pod -- * Stringification of NVs are not cached so that the lexical locale controls stringification of the decimal point [perl #108378] [perl #115800] -- The lexical scope of my code is running with "use locale" and uses setlocale to switch to the locale of the user. Some locales use "," (de). The Moose code does not use locale. The stringified version should not be localized in this scope.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.