The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
Changes 012
MANIFEST 21
META.yml 12
MYMETA.json 510
MYMETA.yml 240
Makefile.PL 01
README 11
lib/Math/Base36.pm 611
t/02-basic.t 19
t/03-invalid.t 025
10 files changed (This is a version diff) 8662
@@ -1,5 +1,17 @@
 Revision history for Perl extension Math::Base36.
 
+0.14 2015-04-02
+ - Avoid negative repeat count warnings generated from new perls (RT #103266) 
+
+0.13 2015-01-17
+ - handle large base-10 numbers when encoding (GH #2)
+
+0.12 2013-03-29
+ - make errors more descriptive (Chisel Wright)
+
+0.11 2013-03-14
+ - repackaged
+
 0.10 2012-08-16
  - Fix SYNOPSIS (RT #78790)
 
@@ -11,10 +11,9 @@ lib/Math/Base36.pm
 Makefile.PL
 MANIFEST			This list of files
 META.yml
-MYMETA.json
-MYMETA.yml
 README
 t/01-use.t
 t/02-basic.t
+t/03-invalid.t
 t/98-pod_coverage.t
 t/99-pod.t
@@ -4,6 +4,7 @@ author:
   - 'Rune Henssel <perl@henssel.dk>'
 build_requires:
   ExtUtils::MakeMaker: 6.59
+  Test::Exception: 0
   Test::More: 0
 configure_requires:
   ExtUtils::MakeMaker: 6.59
@@ -25,4 +26,4 @@ requires:
 resources:
   license: http://dev.perl.org/licenses/
   repository: http://github.com/bricas/math-base36
-version: 0.10
+version: 0.14
@@ -1,51 +0,0 @@
-{
-   "abstract" : "Encoding and decoding of base36 strings",
-   "author" : [
-      "Rune Henssel <perl@henssel.dk>"
-   ],
-   "dynamic_config" : 0,
-   "generated_by" : "Module::Install version 1.06, CPAN::Meta::Converter version 2.120630",
-   "license" : [
-      "perl_5"
-   ],
-   "meta-spec" : {
-      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
-      "version" : "2"
-   },
-   "name" : "Math-Base36",
-   "no_index" : {
-      "directory" : [
-         "inc",
-         "t"
-      ]
-   },
-   "prereqs" : {
-      "build" : {
-         "requires" : {
-            "ExtUtils::MakeMaker" : "6.59",
-            "Test::More" : "0"
-         }
-      },
-      "configure" : {
-         "requires" : {
-            "ExtUtils::MakeMaker" : "6.59"
-         }
-      },
-      "runtime" : {
-         "requires" : {
-            "Math::BigInt" : "1.60",
-            "perl" : "5.006"
-         }
-      }
-   },
-   "release_status" : "stable",
-   "resources" : {
-      "license" : [
-         "http://dev.perl.org/licenses/"
-      ],
-      "repository" : {
-         "url" : "http://github.com/bricas/math-base36"
-      }
-   },
-   "version" : "0.10"
-}
@@ -1,24 +0,0 @@
----
-abstract: 'Encoding and decoding of base36 strings'
-author:
-  - 'Rune Henssel <perl@henssel.dk>'
-build_requires:
-  ExtUtils::MakeMaker: 6.59
-  Test::More: 0
-configure_requires:
-  ExtUtils::MakeMaker: 0
-dynamic_config: 0
-generated_by: 'ExtUtils::MakeMaker version 6.6302, CPAN::Meta::Converter version 2.120630'
-license: perl
-meta-spec:
-  url: http://module-build.sourceforge.net/META-spec-v1.4.html
-  version: 1.4
-name: Math-Base36
-no_index:
-  directory:
-    - t
-    - inc
-requires:
-  Math::BigInt: 1.60
-  perl: 5.006
-version: 0.10
@@ -11,6 +11,7 @@ all_from 'lib/Math/Base36.pm';
 requires 'Math::BigInt' => '1.60';
 
 test_requires 'Test::More';
+test_requires 'Test::Exception';
 
 repository "http://github.com/bricas/math-base36";
 
@@ -30,7 +30,7 @@ MAINTAINER
 COPYRIGHT AND LICENSE
     Copyright 2002 by Rune Henssel
 
-    Copyright 2007-2012 by Brian Cassidy
+    Copyright 2007-2015 by Brian Cassidy
 
     This library is free software; you can redistribute it and/or modify it
     under the same terms as Perl itself.
@@ -5,16 +5,17 @@ use warnings;
 
 use base qw( Exporter );
 
+use Carp 'croak';
 use Math::BigInt ();
 
 our %EXPORT_TAGS = ( 'all' => [ qw(encode_base36 decode_base36) ] );
 our @EXPORT_OK = ( @{ $EXPORT_TAGS{ 'all' } } );
 
-our $VERSION = '0.10';
+our $VERSION = '0.14';
 
 sub decode_base36 {
     my $base36 = uc( shift );
-    die 'Invalid base36 number' if $base36 =~ m{[^0-9A-Z]};
+    croak "Invalid base36 number ($base36)" if $base36 =~ m{[^0-9A-Z]};
 
     my ( $result, $digit ) = ( 0, 0 );
     for my $char ( split( //, reverse $base36 ) ) {
@@ -29,9 +30,10 @@ sub encode_base36 {
     my ( $number, $padlength ) = @_;
     $padlength ||= 1;
 
-    die 'Invalid base10 number'  if $number    =~ m{\D};
-    die 'Invalid padding length' if $padlength =~ m{\D};
+    croak "Invalid base10 number ($number)"  if $number    =~ m{\D};
+    croak "Invalid padding length ($padlength)" if $padlength =~ m{\D};
 
+    $number = Math::BigInt->new( $number );
     my $result = '';
     while ( $number ) {
         my $remainder = $number % 36;
@@ -39,7 +41,10 @@ sub encode_base36 {
         $number = int $number / 36;
     }
 
-    return '0' x ( $padlength - length $result ) . reverse( $result );
+    my $padding = $padlength - length $result;
+    my $return = reverse( $result );
+    $return = '0' x $padding . $return if $padding > 0;
+    return $return;
 }
 
 1;
@@ -87,7 +92,7 @@ Brian Cassidy E<lt>bricas@cpan.orgE<gt>
 
 Copyright 2002 by Rune Henssel
 
-Copyright 2007-2012 by Brian Cassidy
+Copyright 2007-2015 by Brian Cassidy
 
 This library is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself. 
@@ -1,4 +1,4 @@
-use Test::More tests => 33;
+use Test::More tests => 35;
 
 use strict;
 use warnings;
@@ -43,6 +43,14 @@ use Math::BigInt;
 }
 
 {
+    my $num = '808281277464764060643139600456536293375';
+    my $b36 = 'ZZZZZZZZZZZZZZZZZZZZZZZZZ';
+
+    is( decode_base36( $b36 ), $num, 'decode large number (implicit bigint)' );
+    is( encode_base36( $num ), $b36, 'encode large number (implicit bigint)' );
+}
+
+{
     eval { decode_base36( '(INVALID)' ); };
     ok( $@, 'invalid base36 numbers in decode throw errors' );
 
@@ -0,0 +1,25 @@
+#!perl
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+
+use Math::Base36 ':all';
+
+throws_ok {
+    encode_base36('apple')
+} qr/^Invalid base10 number \(apple\)/,
+    'descriptive error for invalid base10 number';
+
+throws_ok {
+    encode_base36(123456, 'carrot')
+} qr/^Invalid padding length \(carrot\)/,
+    'descriptive error for invalid padding length';
+
+throws_ok {
+    decode_base36('123,456')
+} qr/^Invalid base36 number \(123,456\)/,
+    'descriptive error for invalid base36 number';
+
+done_testing;