GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Algorithm::CheckDigits(3) User Contributed Perl Documentation Algorithm::CheckDigits(3)

Algorithm::CheckDigits - Perl extension to generate and test check digits

  perl -MAlgorithm::CheckDigits -e Algorithm::CheckDigits::print_methods

or

  use Algorithm::CheckDigits;
  
  @ml = Algorithm::CheckDigits->method_list();
  %md = Algorithm::CheckDigits->method_descriptions();

  $isbn = CheckDigits('ISBN');

  if ($isbn->is_valid('3-930673-48-7')) {
        # do something
  }

  $cn = $isbn->complete('3-930673-48');     # $cn = '3-930673-48-7'

  $cd = $isbn->checkdigit('3-930673-48-7'); # $cd = '7'

  $bn = $isbn->basenumber('3-930673-48-7'); # $bn = '3-930673-48'

This module provides a number of methods to test and generate check digits. For more information have a look at the web site www.pruefziffernberechnung.de (german).

Returns an object of an appropriate Algorithm::CheckDigits class for the given algorithm.

Dies with an error message if called with an unknown algorithm.

See below for the available algorithms. Every object understands the following methods:

is_valid($number)
Returns true or false if $number contains/contains no valid check digit.
complete($number)
Returns a string representation of $number completed with the appropriate check digit.
checkdigit($number)
Extracts the check digit from $number if $number contains a valid check digit.
basenumber($number)
Extracts the basenumber from $number if $number contains a valid check digit.

Register a module that provides the same four methods as above. This function returns a handle with which the registered module can be instantiated.

The first argument $module is the module to be used for this plugin. This argument is mandatory. Do not register 'Algorithm::CheckDigits'.

The second argument is a short description of the algorithm. If it is omitted, the string "algorithm of module $module" will be taken.

The third argument is the preferred key for this algorithm. The "plug_in()" function does not guarantee to register the algorithm with this key. Instead it returns the key under which the algorithm is registered.

See "REGISTERING PLUGINS" for more information on registering plugins.

Returns a list of known methods for check digit computation.

Returns a hash of descriptions for the known methods for check digit computations. The keys of the hash are the values returned by "method_list()".

Returns a list of known methods for check digit computation.

You may use the following to find out which methods your version of Algorithm::CheckDigits provides and where to look for further information.

 perl -MAlgorithm::CheckDigits -e Algorithm::CheckDigits::print_methods

At the moment these methods to compute check digits are provided: (vatrn - VAT Return Number, in german ustid UmsatzSTeuer-ID)
euronote
European bank notes, see Algorithm::CheckDigits::M09_001.
amex, bahncard, diners, discover, enroute, eurocard, happydigits, isin, jcb, klubkarstadt, mastercard, miles&more, visa, imei, imeisv
See Algorithm::CheckDigits::M10_001.
siren, siret
See Algorithm::CheckDigits::M10_002.
ismn
See Algorithm::CheckDigits::M10_003.
ean, iln, isbn13, nve, 2aus5
See Algorithm::CheckDigits::M10_004.
identcode_dp, leitcode_dp
See Algorithm::CheckDigits::M10_005.
rentenversicherung
See Algorithm::CheckDigits::M10_006.
sedol
See Algorithm::CheckDigits::M10_008.
betriebsnummer
See Algorithm::CheckDigits::M10_009.
postscheckkonti
See Algorithm::CheckDigits::M10_010.
ups
See Algorithm::CheckDigits::M10_011.
hkid, isbn, issn, nhs_gb, ustid_pt, vat_sl, wagonnr_br
See Algorithm::CheckDigits::M11_001.
pzn
See Algorithm::CheckDigits::M11_002.
pkz
See Algorithm::CheckDigits::M11_003.
cpf, titulo_eleitor
See Algorithm::CheckDigits::M11_004.
ccc_es
See Algorithm::CheckDigits::M11_006.
ustid_fi, vatrn_fi
See Algorithm::CheckDigits::M11_007.
ustid_dk, vatrn_dk
See Algorithm::CheckDigits::M11_008.
nric_sg
See Algorithm::CheckDigits::M11_009.
ahv_ch
See Algorithm::CheckDigits::M11_010.
ustid_nl, vatrn_nl
See Algorithm::CheckDigits::M11_011.
bwpk_de
See Algorithm::CheckDigits::M11_012.
ustid_gr, vatrn_gr
See Algorithm::CheckDigits::M11_013.
esr5_ch
See Algorithm::CheckDigits::M11_015.
ustid_pl, vatrn_pl
See Algorithm::CheckDigits::M11_016.
ecno, ec-no, einecs, elincs
See Algorithm::CheckDigits::M11_017.
isan
See Algorithm::CheckDigits::M16_001.
dni_es
See Algorithm::CheckDigits::M23_001.
ustid_ie, vatrn_ie
See Algorithm::CheckDigits::M23_002.
code_39
See Algorithm::CheckDigits::M43_001.
ustid_lu, vatrn_lu
See Algorithm::CheckDigits::M89_001.
ustid_be, vatrn_be
See Algorithm::CheckDigits::M97_001.
iban
See Algorithm::CheckDigits::M97_002.
upc
See Algorithm::CheckDigits::MBase_001.
blutbeutel, bzue_de, ustid_de, vatrn_de
See Algorithm::CheckDigits::MBase_002.
sici
See Algorithm::CheckDigits::MBase_003.
pa_de
See Algorithm::CheckDigits::MXX_001.
cas
See Algorithm::CheckDigits::MXX_002.
dem
Old german bank notes (DEM), see Algorithm::CheckDigits::MXX_003.
ustid_at, vatrn_at
See Algorithm::CheckDigits::MXX_004.
esr9_ch
See Algorithm::CheckDigits::MXX_005.
verhoeff
Verhoeff scheme, see Algorithm::CheckDigits::MXX_006 or Algorithm::Verhoeff

This module exports the Function "CheckDigits()" that is used to create an instance of a checker with the given algorithm.

Brian T. Wightman was the first, asking me to add a plugin registry to Algorithm::CheckDigits and so I added the function "plug_in()" that does just this, registering plug in modules to be used just like the modules in the distribution of this module.

Providing some means to add additional algorithms without the need to change the module has the benefit that the user of those additional algorithms may easily use them with the same interface as the other algorithms without having to wait for a new version, that may or may not include the wanted algorithm.

But there is a problem: the user must be able to select the new algorithms like he did with the other ones. And the catch is: since these new algorithms are developed independently there is no guarantee that no more than one module applies for the same handle. I could have implemented some simple strategies like last one wins (the module that registers last for a given handle is the one that is choosen) or first one wins (the first registered module is choosen). Instead I went for something more complex to assure that every module that wants to get registered will be registered and that every registered module will be accessible by the same handle as long as the program runs. To make this work "plug_in()" sees the third argument only as a hint how the handle should look like, when a module is registered. It returns the real handle with which the algorithm can be instantiated. That means a developer of a plugin module cannot make the handle immediately available like I did for the modules in the distribution. Instead there should be something like a public variable or function that returns the handle as it came back from the "plug_in()" function.

This could go like this in the module:

 package Algorithm::XyZ;

 use Algorithm::CheckDigits;

 our $xyz = Algorithm::CheckDigits::plug_in('Algorithm::XyZ',
                                            'XyZ check digits',
                                            'xyz');

And the user of this algorithm would write something like this:

 use Algorithm::CheckDigits;
 use Algorithm::XyZ;

 my $cd = CheckDigits($Algorithm::XyZ::xyz);

 if ($cd->is_valid($some_number)) {
     # do something
 }

Please have a look at the plugin tests in the test directory (t/plugin*.t) and the accompanying modules (t/PluginLib*.pm) for example usage. You may also try to load an additional module with the scripts in bin and cgi-bin and look for the additional algorithms in the output:

 perl -Ilib -It -MPluginLibA bin/checkdigits.pl list

 perl -Ilib -It -MPluginLibA cgi-bin/checkdigits.cgi

I would like to ask you to use any namespace below or outside but not direct Algorithm::CheckDigits. That means for instance for the XyZ algorithm, Algorithm::XyZ would be fine, Algorithm::CheckDigits::Plugin::XyZ or Algorithm::CheckDigits::X::XyZ would be fine too. But Algorithm::CheckDigits::XyZ could collide with some future version of the Algorithm::CheckDigits distribution, so please avoid this namespace.

perl, www.pruefziffernberechnung.de.

The function "plug_in()" dies if you try to register the module 'Algorithm::CheckDigits'.

Please report any bugs or feature requests to "bug-algorithm-checkdigits@rt.cpan.org", or through the web interface at <http://rt.cpan.org>.

Mathias Weidner, "mamawe@cpan.org"

Petri Oksanen made me aware that CheckDigits('IMEI') would invoke no test at all since there was no entry for this in the methods hash.

Brian T. Wightman made me think about and implement the plugin interface.

Copyright 2004-2020 by Mathias Weidner

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

2022-04-09 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.