script/validate_cpr.pl untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod n/a totaltotal 0.0% 0 / 61 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2  
3 use strict;
4 use warnings;
5 use vars qw($VERSION);
6 use Getopt::Long;
7 use English qw(-no_match_vars);
8 use FindBin qw($Bin);
9 use lib "$Bin/../lib";
10  
11 use 5.006; #5.6.0
12  
13 use Class::Business::DK::CPR;
14  
15 $VERSION = '0.02';
16  
17 my $verbose = 0;
18 my $result = GetOptions( 'verbose' => \$verbose );
19  
20 if ( not $ARGV[0] ) {
21 die "usage: validate_cpr.pl [-v] <10 digit CPR number>\n";
22 }
23  
24 my $unvalidated_cpr = $ARGV[0];
25  
26 my $cpr;
27  
28 eval { $cpr = Class::Business::DK::CPR->new($unvalidated_cpr); };
29  
30 if ($EVAL_ERROR) {
31 die "$unvalidated_cpr is not valid\n";
32 }
33 else {
34 if ($verbose) {
35 print $cpr->get_number
36 . ' is valid for algorithms: '
37 . $cpr->get_algorithm;
38 print ', gender indicated is: '
39 . ( $cpr->get_gender % 2 ? 'male' : 'female' );
40 print "\n";
41 }
42 else {
43 print $cpr->get_number . " is valid\n";
44 }
45 }
46  
47 exit 0;