blib/lib/Perlmazing/Perlmazing/commify.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 55 CC 10 SCAR 45.2
CC
10
Cov
0%
main
110.0
BEGIN
2.0
BEGIN
2.0
CRAP 92.0
1 use Perlmazing qw(is_number);
2 use CLDR::Number;
3 my $cldr = CLDR::Number->new(locale => 'en');
4 my $decf = $cldr->decimal_formatter;
5 our @ISA = qw(Perlmazing::Listable);
6  
7 sub main {
8 return unless $_[0];
9 my $n = $_[0];
10 my $point = $decf->{decimal_sign};
11 my $comma = $decf->{group_sign};
12 my $plus = $decf->{plus_sign};
13 my $minus = $decf->{minus_sign};
14 my $sign = substr($n, 0, 1);
15 my $decimals;
16 if ($sign =~ /^([$plus]|[$minus])/) {
17 $n = substr $n, 1;
18 } else {
19 undef $sign;
20 }
21 $n =~ s/[^\d$point$comma]+//g;
22 return unless $n;
23 if ($n =~ /[$point](\d+)$/) {
24 $decimals = $1;
25 $n =~ s/[$point]\d+$//;
26 return if $n =~ /[$point]/;
27 }
28 $n = 0 unless $n;
29 $n = "$sign$n" if $sign;
30 $n =~ s/$comma//g;
31 return unless $n;
32 $n = $decf->format($n);
33 $n .= "${point}${decimals}" if $decimals;
34 $_[0] = $n;
35 }
36  
37 1;