Subject: | Unexpected behaviour with CC_digits |
The documentation for CC_digits() says:
Returns false if the card number fails the check digit match
(except for enRoute which does not require a check digit)
otherwise returns exact text identifying the card issuer that is one of
But this description is a bit ambiguous ...
If you read just the first part:
Returns false if the card number fails the check digit match
Then you might expect the following number:
1000000000007060
To not return false, as it does satisfy the LUHN check.
This fails because it doesn't match any of the number ranges you check, so it returns the
default value, defined with the following line at the start of CC_digits().
my $type = '';
This is the one situation where your module disagrees with the other LUHN implementations.
I think you have two choices:
(1) stick with the current behaviour, but update the documentation
to make it clearer what exactly the function does.
(2) change the function to return 1 or some other true value. Eg default my $type = 1;
(3) (bonus choice!) have two functions: one which does a luhn check, and one which returns
the issuer, if the number is valid AND there is an issuer.
Personally I'd do the following:
- add a CC_luhn_check() which does the strict LUHN check
- add a CC_issuer() function which calls LUHN check, and returns the issuer, if there is one
- make the current CC_digits() be an alias for CC_issuer(), for backwards compatibility.
In the doc you could say that CC_digits() might eventually go away.