Business-DK-PO

 view release on metacpan or  search on metacpan

lib/Business/DK/PO.pm  view on Meta::CPAN

        if ( $tmpsum > SUM_THRESHOLD ) {

            #TODO: address this construct
            ## no critic (BuiltinFunctions::ProhibitVoidMap)
            map( { $tmpsum2 += $_ } split( //, $tmpsum ) );
            $tmpsum = $tmpsum2;
        }
        $sum += $tmpsum;
    }

    return $sum;
}

1;

__END__

=pod

=head1 NAME

Business::DK::PO - Danish postal order number validator

=head1 VERSION

This documentation describes version 0.07

=head1 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);


    #Using with Params::Validate

    use Params::Validate qw(:all);
    use Business::DK::PO qw(validatePO);

    sub check_cpr {
        validate( @_,
        { po =>
            { callbacks =>
                { 'validate_po' => sub { validatePO($_[0]); } } } } );

        print $_[1]." is a valid PO\n";

    }

=head1 DESCRIPTION

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

=head1 SUBROUTINES/METHODS

=head2 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):

=over

=item * _argument

=item * _content

=item * _length

=back

If the argument is a valid argument the sum is calculated by B<_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.

=head2 validatePO

A wrapper for L</validate> with a name more suitable for importing, it is less
common and therefor less intrusive.

See L</validate> for details.

=head2 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>



( run in 0.450 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )