Subject: | validation of Num fails if LC_NUMERIC is set to locale with comma instead of point |
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 |
#!/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";