File Coverage

blib/lib/Class/Business/DK/CVR.pm
Criterion Covered Total %
statement 41 41 100.0
branch 8 8 100.0
condition 3 3 100.0
subroutine 10 10 100.0
pod 4 4 100.0
total 66 66 100.0


line stmt bran cond sub pod time code
1             package Class::Business::DK::CVR;
2              
3 4     4   427042 use strict;
  4         43  
  4         128  
4 4     4   21 use warnings;
  4         8  
  4         122  
5 4     4   2230 use Class::InsideOut qw( private register id );
  4         28565  
  4         26  
6 4     4   509 use Carp qw(croak);
  4         9  
  4         174  
7 4     4   1022 use English qw(-no_match_vars);
  4         7373  
  4         23  
8              
9 4     4   3202 use Business::DK::CVR qw(validate);
  4         14  
  4         1245  
10              
11             our $VERSION = '0.12';
12              
13             private number => my %number; # read-only accessor: number()
14              
15             sub new {
16 6     6 1 571 my ( $class, $number ) = @_;
17              
18 6         16 my $self = {};
19              
20 6         15 bless $self, $class;
21              
22 6         33 register($self);
23              
24 6 100       124 if ($number) {
25 5         20 $self->set_number($number);
26             } else {
27 1         15 croak 'You must provide a CVR number';
28             }
29              
30 4         14 return $self;
31             }
32              
33 1     1 1 7 sub number { my $self = shift; return $number{ id $self } }
  1         8  
34              
35 1     1 1 5 sub get_number { my $self = shift; return $number{ id $self } }
  1         7  
36              
37             sub set_number {
38 8     8 1 94 my ( $self, $unvalidated_cvr ) = @_;
39              
40 8         16 my $rv;
41              
42 8 100       22 if ($unvalidated_cvr) {
43 7 100       11 eval { $rv = validate($unvalidated_cvr); 1; } or 0;
  7         24  
  6         21  
44              
45 7 100 100     727 if ( $EVAL_ERROR or not $rv ) {
46 2         18 croak 'Invalid CVR number parameter';
47              
48             } else {
49 5         26 $number{ id $self } = $unvalidated_cvr;
50 5         16 return 1;
51              
52             }
53             } else {
54 1         16 croak 'You must provide a CVR number';
55             }
56             }
57              
58             1;
59              
60             __END__