Codebase list libmath-base36-perl-upstream / 39eedf9
Switch to croak() instead of die() This is more helpful for the person sending crazy values to the module's methods; it lets them see where *they* sent the value, not where it was sanity checked. Chisel 11 years ago
1 changed file(s) with 4 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
44
55 use base qw( Exporter );
66
7 use Carp 'croak';
78 use Math::BigInt ();
89
910 our %EXPORT_TAGS = ( 'all' => [ qw(encode_base36 decode_base36) ] );
1314
1415 sub decode_base36 {
1516 my $base36 = uc( shift );
16 die "Invalid base36 number ($base36)" if $base36 =~ m{[^0-9A-Z]};
17 croak "Invalid base36 number ($base36)" if $base36 =~ m{[^0-9A-Z]};
1718
1819 my ( $result, $digit ) = ( 0, 0 );
1920 for my $char ( split( //, reverse $base36 ) ) {
2829 my ( $number, $padlength ) = @_;
2930 $padlength ||= 1;
3031
31 die "Invalid base10 number ($number)" if $number =~ m{\D};
32 die "Invalid padding length ($padlength)" if $padlength =~ m{\D};
32 croak "Invalid base10 number ($number)" if $number =~ m{\D};
33 croak "Invalid padding length ($padlength)" if $padlength =~ m{\D};
3334
3435 my $result = '';
3536 while ( $number ) {