Class::Business::DK::CVR - Danish CVR number class


Business-DK-CVR documentation Contained in the Business-DK-CVR distribution.

Index


Code Index:

NAME

Top

Class::Business::DK::CVR - Danish CVR number class

VERSION

Top

The documentation describes version 0.01 of Class::Business::DK::CVR

SYNOPSIS

Top

    use Class::Business::DK::CVR;

    my $cvr = Class::Business::DK::CVR->new(27355021);

    my $cvr_no = $cvr->get_number();

    my $cvr_no = $cvr->number();

    $cvr->set_number(27355021);

DESCRIPTION

Top

This is an OOP implementation for handling Danish CVR numbers. The class gives you an CVR object, which is validated according to the CVR rules, see: Business::DK::CVR.

SUBROUTINES AND METHODS

Top

new

This is the constructor, it takes a single mandatory parameter, which should be a valid CVR number, if the parameter provided is not valid, the constructor dies.

get_number

This method/accessor returns the CVR number associated with the object.

number

Alias for the get_number accessor, see above.

set_number

This method/mutator sets the a CVR number for a given CVR object, it takes a single mandatory parameter, which should be a valid CVR number, returns true (1) upon success else it dies.

DIAGNOSTICS

Top

* You must provide a CVR number, thrown by set_number and new if no argument is provided.
* Invalid CVR number parameter, thrown by new and set_number if the provided argument is not a valid CVR number.

CONFIGURATION AND ENVIRONMENT

Top

The module requires no special configuration or environment to run.

DEPENDENCIES

Top

* Class::InsideOut
* Business::DK::CVR

INCOMPATIBILITIES

Top

The module has no known incompatibilities.

BUGS AND LIMITATIONS

Top

The module has no known bugs or limitations

TEST AND QUALITY

Top

Coverage of the test suite is at 98.3%

TODO

Top

* Please refer to the TODO file

SEE ALSO

Top

* Business::DK::CVR

BUG REPORTING

Top

Please report issues via CPAN RT:

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

or by sending mail to

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

AUTHOR

Top

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

COPYRIGHT

Top

LICENSE

Top

Business-DK-CVR and related 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).


Business-DK-CVR documentation Contained in the Business-DK-CVR distribution.

package Class::Business::DK::CVR;

# $Id: CVR.pm 6792 2009-11-06 08:13:29Z jonasbn $

use strict;
use warnings;
use Class::InsideOut qw( private register id );
use Carp qw(croak);
use English qw(-no_match_vars);

use Business::DK::CVR qw(validate);

our $VERSION = '0.01';

private number => my %number;    # read-only accessor: number()

sub new {
    my ( $class, $number ) = @_;

    my $self = {};

    bless $self, $class;

    register($self);

    if ($number) {
        $self->set_number($number);
    } else {
        croak 'You must provide a CVR number';
    }

    return $self;
}

sub number { my $self = shift; return $number{ id $self } }

sub get_number { my $self = shift; return $number{ id $self } }

sub set_number {
    my ( $self, $unvalidated_cvr ) = @_;

    my $rv;

    if ($unvalidated_cvr) {
        eval { $rv = validate($unvalidated_cvr); 1; } or 0;

        if ( $EVAL_ERROR or not $rv ) {
            croak 'Invalid CVR number parameter';

        } else {
            $number{ id $self } = $unvalidated_cvr;
            return 1;

        }
    } else {
        croak 'You must provide a CVR number';
    }
}

1;

__END__