Algorithm-LUHN_XS
view release on metacpan or search on metacpan
"is_valid_rff: 2 secs ( 1.97 usr 0.08 sys) 48.78/s"
Algorithm::LUHN_XS varies from 38x to 48x times faster than the
original pure perl Algorithm::LUHN module. The is_valid() routine is
100% compatible with the original, returning either '1' for success
or the empty string '' for failure. The is_valid_fast() routine
returns 1 for success and 0 for failure. Finally, the is_valid_rff()
function also returns 1 for success and 0 for failure, but only
works with numeric input. If you supply any alpha characters, it
will return 0.
check_digit NUM
This function returns the checksum of the given number. If it cannot
calculate the check_digit it will return undef and set
$Algorithm::LUHN_XS::ERROR to contain the reason why. This is much
faster than the check_digit routine in the pure perl Algorithm::LUHN
module, but only about half as fast as the check_digit_fast()
function in this module, due to the need to return both integers and
undef, which isn't fast with XS.
check_digit_fast NUM
This function returns the checksum of the given number. If it cannot
calculate the check digit it will return -1 and set
$Algorithm::LUHN_XS::ERROR to contain the reason why. It's about 20%
faster than check_digit() because the XS code in this case only has
to return integers.
check_digit_rff NUM
This function returns the checksum of the given number.
It's about 50% faster than check_digit() because it doesn't support
the valid_chars() function, and only produces a valid output for
numeric input. If you pass it input with alpha characters, it will
return -1. Works great for Credit Cards, but not for things like
CUSIP identifiers <https://en.wikipedia.org/wiki/CUSIP>.
valid_chars LIST
By default this module only recognizes 0..9 as valid characters, but
sometimes you want to consider other characters as valid, e.g.
Standard & Poor's identifers may contain 0..9, A..Z, @, #, *. This
function allows you to add additional characters to the accepted
list.
LIST is a mapping of "character" => "value". For example, Standard &
Poor's maps A..Z to 10..35 so the LIST to add these valid characters
would be (A, 10, B, 11, C, 12, ...)
Please note that this *adds* or *re-maps* characters, so any
characters already considered valid but not in LIST will remain
valid.
If you do not provide LIST, this function returns the current valid
character map.
Note that the check_digit_rff() and is_valid_rff() functions do not
support the valid_chars() function. Both only support numeric
inputs, and map them to their literal values.
CAVEATS
This module, because of how valid_chars() stores data in the XS portion,
is NOT thread safe.
The _fast and _rff versions of is_valid() and check_digit() don't have
the same return values for failure as the original Algorithm::LUHN
module. Specifically:
* is_valid_fast() and is_valid_rff() return 0 on failure, but
is_valid() returns the empty string.
* check_digit_fast() and check_digit_rff() return -1 on failure, but
check_digit() returns undef.
Also, be careful with passing long numbers around. Perl will, depending
on the context, convert things like 12345678912345 to
1.2345678912345e+1. Try to keep things in "string context".
SEE ALSO
Algorithm::LUHN is the original pure perl module this is based on.
Algorithm::CheckDigits provides a front-end to a large collection of
modules for working with check digits.
Business::CreditCard provides three functions for checking credit card
numbers. Business::CreditCard::Object provides an OO interface to those
functions.
Business::CardInfo provides a class for holding credit card details, and
has a type constraint on the card number, to ensure it passes the LUHN
check.
Business::CCCheck provides a number of functions for checking credit
card numbers.
Regexp::Common supports combined LUHN and issuer checking against a card
number.
Algorithm::Damm implements a different kind of check digit algorithm,
the Damm algorithm <https://en.wikipedia.org/wiki/Damm_algorithm> (Damm,
not Damn).
Math::CheckDigits implements yet another approach to check digits.
Neil Bowers has also written a review of LUHN modules
<http://neilb.org/reviews/luhn.html>, which covers them in more detail
than this section.
REPOSITORY
<https://github.com/krschwab/Algorithm-LUHN_XS>
AUTHOR
This module was written by Kerry Schwab
(http://search.cpan.org/search?author=KSCHWAB).
COPYRIGHT
Copyright (c) 2018 Kerry Schwab. All rights reserved. Derived from
Algorithm::LUHN, which is (c) 2001 by Tim Ayers.
LICENSE
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
( run in 0.681 second using v1.01-cache-2.11-cpan-524268b4103 )