| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Algorithm::CheckDigits::MBase_002; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 19 | use 5.006; | 
|  | 1 |  |  |  |  | 3 |  | 
| 4 | 1 |  |  | 1 |  | 6 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 31 |  | 
| 5 | 1 |  |  | 1 |  | 6 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 25 |  | 
| 6 | 1 |  |  | 1 |  | 4 | use integer; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 4 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 1 |  |  | 1 |  | 48 | use version; our $VERSION = 'v1.3.4'; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 4 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | our @ISA = qw(Algorithm::CheckDigits); | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | sub new { | 
| 13 | 9 |  |  | 9 | 0 | 18 | my $proto = shift; | 
| 14 | 9 |  |  |  |  | 12 | my $type  = shift; | 
| 15 | 9 |  | 33 |  |  | 32 | my $class = ref($proto) || $proto; | 
| 16 | 9 |  |  |  |  | 21 | my $self  = bless({}, $class); | 
| 17 | 9 |  |  |  |  | 26 | $self->{type} = lc($type); | 
| 18 | 9 |  |  |  |  | 39 | return $self; | 
| 19 |  |  |  |  |  |  | } # new() | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | sub is_valid { | 
| 22 | 18 |  |  | 18 | 1 | 58 | my ($self,$number) = @_; | 
| 23 | 18 | 50 |  |  |  | 96 | if ($number =~ /^(.+)(.)$/) { | 
| 24 | 18 |  |  |  |  | 61 | return uc($2) eq $self->_compute_checkdigit($1); | 
| 25 |  |  |  |  |  |  | } | 
| 26 | 0 |  |  |  |  | 0 | return '' | 
| 27 |  |  |  |  |  |  | } # is_valid() | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | sub complete { | 
| 30 | 9 |  |  | 9 | 1 | 731 | my ($self,$number) = @_; | 
| 31 | 9 | 50 |  |  |  | 49 | if ($number =~ /^[ 0-9]+$/) { | 
| 32 | 9 |  |  |  |  | 20 | return  $number . $self->_compute_checkdigit($number); | 
| 33 |  |  |  |  |  |  | } | 
| 34 | 0 |  |  |  |  | 0 | return ''; | 
| 35 |  |  |  |  |  |  | } # complete() | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | sub basenumber { | 
| 38 | 9 |  |  | 9 | 1 | 21 | my ($self,$number) = @_; | 
| 39 | 9 | 50 |  |  |  | 53 | if ($number =~ /^(.+)(.)$/) { | 
| 40 | 9 | 50 |  |  |  | 30 | return $1 if (uc($2) eq $self->_compute_checkdigit($1)); | 
| 41 |  |  |  |  |  |  | } | 
| 42 | 0 |  |  |  |  | 0 | return ''; | 
| 43 |  |  |  |  |  |  | } # basenumber() | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | sub checkdigit { | 
| 46 | 9 |  |  | 9 | 1 | 21 | my ($self,$number) = @_; | 
| 47 | 9 | 50 |  |  |  | 49 | if ($number =~ /^(.+)(.)$/) { | 
| 48 | 9 | 50 |  |  |  | 31 | return $2 if (uc($2) eq $self->_compute_checkdigit($1)); | 
| 49 |  |  |  |  |  |  | } | 
| 50 | 0 |  |  |  |  | 0 | return ''; | 
| 51 |  |  |  |  |  |  | } # checkdigit() | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | sub _compute_checkdigit { | 
| 54 | 45 |  |  | 45 |  | 73 | my $self   = shift; | 
| 55 | 45 |  |  |  |  | 84 | my $number = shift; | 
| 56 |  |  |  |  |  |  |  | 
| 57 | 45 | 50 |  |  |  | 151 | if ($number =~ /^[ 0-9]+$/) { | 
| 58 |  |  |  |  |  |  |  | 
| 59 | 45 |  |  |  |  | 98 | $number =~ s/ //g; | 
| 60 | 45 |  |  |  |  | 141 | my @digits = split(//,$number); | 
| 61 | 45 |  |  |  |  | 67 | my $sum    = 0; | 
| 62 | 45 |  |  |  |  | 63 | my $prod   = 10; | 
| 63 |  |  |  |  |  |  |  | 
| 64 | 45 |  |  |  |  | 119 | for (my $i = 0; $i <= $#digits; $i++) { | 
| 65 |  |  |  |  |  |  |  | 
| 66 | 290 |  | 100 |  |  | 613 | $sum  = (($prod + $digits[$i]) % 10) || 10; | 
| 67 | 290 |  |  |  |  | 549 | $prod = (2 * $sum) % 11; | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | } | 
| 70 | 45 |  |  |  |  | 264 | return (11 - $prod) % 10; | 
| 71 |  |  |  |  |  |  | } | 
| 72 | 0 |  |  |  |  |  | return -1; | 
| 73 |  |  |  |  |  |  | } # _compute_checkdigit() | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | # Preloaded methods go here. | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | 1; | 
| 78 |  |  |  |  |  |  | __END__ |