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   347131 use strict;
  4         36  
  4         96  
4 4     4   16 use warnings;
  4         6  
  4         104  
5 4     4   1759 use Class::InsideOut qw( private register id );
  4         22990  
  4         20  
6 4     4   450 use Carp qw(croak);
  4         8  
  4         140  
7 4     4   841 use English qw(-no_match_vars);
  4         5913  
  4         20  
8              
9 4     4   2524 use Business::DK::CVR qw(validate);
  4         11  
  4         990  
10              
11             our $VERSION = '0.10';
12              
13             private number => my %number; # read-only accessor: number()
14              
15             sub new {
16 6     6 1 474 my ( $class, $number ) = @_;
17              
18 6         14 my $self = {};
19              
20 6         14 bless $self, $class;
21              
22 6         27 register($self);
23              
24 6 100       102 if ($number) {
25 5         19 $self->set_number($number);
26             } else {
27 1         20 croak 'You must provide a CVR number';
28             }
29              
30 4         15 return $self;
31             }
32              
33 1     1 1 5 sub number { my $self = shift; return $number{ id $self } }
  1         6  
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 75 my ( $self, $unvalidated_cvr ) = @_;
39              
40 8         12 my $rv;
41              
42 8 100       17 if ($unvalidated_cvr) {
43 7 100       11 eval { $rv = validate($unvalidated_cvr); 1; } or 0;
  7         25  
  6         18  
44              
45 7 100 100     632 if ( $EVAL_ERROR or not $rv ) {
46 2         16 croak 'Invalid CVR number parameter';
47              
48             } else {
49 5         19 $number{ id $self } = $unvalidated_cvr;
50 5         12 return 1;
51              
52             }
53             } else {
54 1         20 croak 'You must provide a CVR number';
55             }
56             }
57              
58             1;
59              
60             __END__