Business::DK::PO - a danish postal order code generator/validator


NAME

Business::DK::PO - a danish postal order code generator/validator

Back to Top


VERSION

This documentation describes version 0.04

Back to Top


SYNOPSIS

        use Business::DK::PO qw(validate);
        my $rv;
        eval {
                $rv = validate(1234563891234562);
        };
        
        if ($@) {
                die "Code is not of the expected format - $@";
        }
        
        if ($rv) {
                print "Code is valid";
        } else {
                print "Code is not valid";
        }
        use Business::DK::PO qw(calculate);
        my $code = calculate(1234);

Back to Top


DESCRIPTION

The postal orders and postal order codes are used by the danish postal service PostDanmark.

Back to Top


FUNCTIONS

validate

The function takes a single argument, a 16 digit postal order code.

The function returns 1 (true) in case of a valid postal order code argument and 0 (false) in case of an invalid postal order code argument.

The validation function goes through the following steps.

Validation of the argument is done using the functions (all described below in detail):

_argument
_content
_length

If the argument is a valid argument the sum is calculated by _calculate_sum based on the argument and the controlcifers array.

The sum returned is checked using a modulus caluculation and based on its validity either 1 or 0 is returned.

calculate

The function takes a single argument, an integer indicating a unique reference number you can use to identify an order. Suggestions are invoice number, order number or similar.

The number provided must be between 1 and 15 digits long, meaning a number between 1 and 999 trillions.

The function returns a postal order code consisting of the number given as argument appended with a control cifer to make the code valid (See: b<validate>

The calculation function goes through the following steps.

Validation of the argument is done using the functions (all described below in detail):

_argument
_content
_length

If the argument is a valid argument the sum is calculated by _calculate_sum based on the argument and the controlcifers array.

Based on the sum the argument the controlcifer is calculated and appended so that the argument becomes a valid postal order code.

The calculated and valid code is then returned, left-padded with zeroes to make it 16 digits long (SEE: validate).

Back to Top


PRIVATE FUNCTIONS

_argument

This function is called from either validate or calculate if an argument is not provided.

It dies with an error message indicating the exceptional situation and attempts to guide the user to providing a sensible input.

The _argument function takes two arguments:

minimum length required of number (mandatory)
maximum length required of number (optional)

The arguments are used in the error message issued with die, since this method always dies.

_content

This function validates the content of the argument, it croaks if the argument is not an integer (consisting of digits only).

_length

This function validates the length of the argument, it dies if the argument does not fit wihtin the boundaries specified by the arguments provided:

The _length function takes the following arguments:

number (mandatory), the number to be validated
minimum length required of number (mandatory)
maximum length required of number (optional)

_calculate_sum

This function takes an integer and calculates the sum bases on the the controlcifer array.

Back to Top


EXPORTS

Business::DK::PO exports on request:

validate
calculate
_argument
_content
_length
_calculate_sum

Back to Top


TESTS

Coverage of the test suite is at 100%

Back to Top


BUGS

Please report issues via CPAN RT:

  http://rt.cpan.org/NoAuth/Bugs.html?Dist=Business-DK-PO

or by sending mail to

  bug-Business-DK-PO@rt.cpan.org

Back to Top


SEE ALSO

http://www.bgbank.dk/bfBlankethaandbog
bin/calculate_po.pl
bin/validate_po.pl

Back to Top


AUTHOR

Jonas B. Nielsen, (jonasbn) - <jonasbn@cpan.org>

Back to Top


COPYRIGHT

Business-DK-PO is (C) by Jonas B. Nielsen, (jonasbn) 2006

Business-DK-PO is released under the artistic license

The distribution is licensed under the Artistic License, as specified by the Artistic file in the standard perl distribution (http://www.perl.com/language/misc/Artistic.html).

Back to Top

 Business::DK::PO - a danish postal order code generator/validator