blib/lib/Perlmazing/Perlmazing/to_number.pm untested

filter: Statementstmt 0.0% 0 / 18 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 30 CC 5 SCAR 30.9
CC
5
Cov
0%
main
30.0
BEGIN
2.0
BEGIN
2.0
CRAP 22.0
1 use Perlmazing qw(is_number to_number croak);
2 our @ISA = qw(Perlmazing::Listable);
3  
4 sub main {
5 no warnings;
6 if (not defined $_[0]) {
7 $_[0] = 0;
8 } elsif (is_number $_[0]) {
9 my $copy = $_[0];
10 # Remove possible _ number separations
11 $copy =~ s/(\d)_(\d)/$1$2/g;
12 # Avoid octal interpretations
13 $copy =~ s/^0+//;
14 my $result = eval "$copy";
15 croak "Unexpected error with to_number(".dumped($copy)."): $@" if $@;
16 $result = 0 unless defined $result;
17 $_[0] = $result;
18 } else {
19 $_[0] =~ s/\D+//g;
20 $_[0] += 0;
21 }
22 }
23  
24 1;