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
4 | 4 | |
5 | 5 | use base qw( Exporter ); |
6 | 6 | |
7 | use Carp 'croak'; | |
7 | 8 | use Math::BigInt (); |
8 | 9 | |
9 | 10 | our %EXPORT_TAGS = ( 'all' => [ qw(encode_base36 decode_base36) ] ); |
13 | 14 | |
14 | 15 | sub decode_base36 { |
15 | 16 | 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]}; | |
17 | 18 | |
18 | 19 | my ( $result, $digit ) = ( 0, 0 ); |
19 | 20 | for my $char ( split( //, reverse $base36 ) ) { |
28 | 29 | my ( $number, $padlength ) = @_; |
29 | 30 | $padlength ||= 1; |
30 | 31 | |
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}; | |
33 | 34 | |
34 | 35 | my $result = ''; |
35 | 36 | while ( $number ) { |