bin/checkdigits.pl

filter: Statementstmt 72.2% 39 / 54 Branchbran 46.4% 13 / 28 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 65.9% 62 / 94 CC 5 SCAR 13.8
CC
5
Cov
63%
determine_algorithm
10.2
__ANON__
2.1
BEGIN
1.0
CRAP 4.0
« blib/lib/Algorithm/CheckDigits/M10_001.pm ↑ Summary blib/lib/Algorithm/CheckDigits/MXX_004.pm »
1 #!/usr/bin/perl -w
2 # vim: set ts=4 sw=4 tw=78 et si:
3 #
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use Algorithm::CheckDigits;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 ▶use version; our $VERSION = qv('v1.3.6');
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 my %opt;
13  
14 5 GetOptions(\%opt, 'algorithm=s', 'help', 'man');
15  
16 5 ▶pod2usage(-exitstatus => 0, -input => \*DATA) if $opt{help};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"help"} 1 4 5
17 4 ▶pod2usage(-exitstatus => 0, -verbose => 2, -input => \*DATA) if $opt{man};
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"man"} 1 3 4
18  
19 3 ▶my $cmd = shift || 'check';
Condition50%1/2
shift @ARGV || 'check'
l!l
30
MC/DC0%0/1
shift @ARGV || 'check'
shift @ARGV
Truth table50%1/2
A
A= shift @ARGV
Aresult
11
00
20  
21 3 ▶pod2usage(0) unless $cmd;
Branch: 1 branch
BranchTrueFalseTotal
unless $cmd 0 3 3
22  
23 3 ▶if ($cmd =~ /^list(_alg(orithms)?)?$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /^list(_alg(orithms)?)?$/i) 0 3 3
24 0 my %descr = Algorithm::CheckDigits::method_descriptions();
25 0 for my $method (Algorithm::CheckDigits->method_list()) {
26 0 print $method, ': ', $descr{$method}, "\n";
27 }
28 0 exit 0;
29 }
30 3 ▶if ($cmd =~ /^descr(ibe)?$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /^descr(ibe)?$/i) 0 3 3
31 0 ▶ while (my $method = shift @ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $method = shift @ARGV) 0 0 0
32 0 print join(': ',Algorithm::CheckDigits->method_descriptions($method))
33 , "\n";
34 }
35 0 exit 0;
36 }
37  
38 3 my $algorithm = determine_algorithm(\%opt);
39  
40 3 my $cd = CheckDigits($algorithm);
41  
42 3 ▶my $complete = sub { $cd->complete($_[0]); };
Subroutine __ANON__: called CC=1 SCAR=0.0
43 3 ▶my $check = sub { $cd->is_valid($_[0]) ? "valid" : "not valid"; };
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$cd->is_valid($_[0]) ? : 1 0 1
44 3 ▶my $checkdigit = sub { $cd->checkdigit($_[0]); };
Subroutine __ANON__: called CC=1 SCAR=0.0
45  
46 3 my %cmdtable = (
47 complete => $complete,
48 check => $check,
49 checkdigit => $checkdigit,
50 );
51  
52 3 ▶if (my $action = $cmdtable{$cmd}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $action = $cmdtable{$cmd}) { } 3 0 3
53 3 ▶ if (0 < scalar @ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 < scalar @ARGV) { } 3 0 3
54 3 ▶ while (my $number = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $number = shift @ARGV) 3 3 6
55 3 printf "%s\n", $action->($number);
56 }
57 }
58 else {
59 0 print STDERR "Reading numbers from STDIN\n";
60 0 ▶ while (my $number = <>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $number = readline ARGV)) 0 0 0
61 0 $number =~ s/\s+$//;
62 0 printf "%s\n", $action->($number);
63 }
64 }
65 }
66 else {
67 0 pod2usage(1);
68 }
69  
70 #----- only functions following -----
71 3 ▶sub determine_algorithm {
Subroutine determine_algorithm: called CC=4 SCAR=23.2
72 3 my $opt = shift;
73  
74 3 ▶ return $opt->{algorithm} if $opt->{algorithm};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"algorithm"} 3 0 3
75  
76 0 ▶ if ($0 =~ /^checkdigit(?:s)?-?(.*)$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($0 =~ /^checkdigit(?:s)?-?(.*)$/i) 0 0 0
77 0 ▶ return $1 ? $1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 0 0 0
78 }
79 0 return $0;
80 } # determine algorithm()
81  
82 __END__
« blib/lib/Algorithm/CheckDigits/M10_001.pm ↑ Summary blib/lib/Algorithm/CheckDigits/MXX_004.pm »