blib/lib/Algorithm/CheckDigits/M11_009.pm

filter: Statementstmt 92.0% 46 / 50 Branchbran 60.0% 6 / 10 Conditioncond 60.0% 6 / 10 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 11 / 11 Podpod 80.0% 4 / 5 totaltotal 81.5% 75 / 92 CC 10 SCAR 9.0
CC
10
Cov
83%
basenumber
4.6
complete
3.1
is_valid
2.1
CRAP 2.5
« blib/lib/Algorithm/CheckDigits/M09_001.pm ↑ Summary blib/lib/Algorithm/CheckDigits/MXX_005.pm »
1 package Algorithm::CheckDigits::M11_009;
2  
3 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use version; our $VERSION = 'v1.3.6';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our @ISA = qw(Algorithm::CheckDigits);
11  
12 2 my @weight = ( 2, 7, 6, 5, 4, 3, 2 );
13  
14 2 my @keys = ('', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'Z', 'J' );
15  
16 2 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod undocumented
17 2 my $proto = shift;
18 2 my $type = shift;
19 2 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
20 2 my $self = bless({}, $class);
21 2 $self->{type} = lc($type);
22 2 return $self;
23 } # new()
24  
25 4 ▶sub is_valid {
Subroutine is_valid: called CC=2 SCAR=7.6
Pod documented
26 4 my ($self,$number) = @_;
27 4 ▶ if ($number =~ /^([fgst])?(\d{7})([a-jz])$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($number =~ /^([fgst])?(\d{7})([a-jz])$/i) 4 0 4
28 4 return (uc($3) eq $self->_compute_checkdigits($2));
29 }
30 0 return ''
31 } # is_valid()
32  
33 2 ▶sub complete {
Subroutine complete: called CC=3 SCAR=11.3
Pod documented
34 2 my ($self,$number) = @_;
35 2 ▶ if($number =~ /^([fgst])?(\d{7})$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($number =~ /^([fgst])?(\d{7})$/i) 2 0 2
36 2 ▶ my $prefix = $1 || '';
Condition100%2/2
$1 || ''
l!l
11
MC/DC100%1/1
$1 || ''
$1
Truth table100%2/2
A
A= $1
Aresult
11
00
37 2 return $prefix . $2 . $self->_compute_checkdigits($2);
38 }
39 0 return '';
40 } # complete()
41  
42 2 ▶sub basenumber {
Subroutine basenumber: called CC=4 SCAR=15.2
Pod documented
43 2 my ($self,$number) = @_;
44 2 ▶ if( $number =~ /^([fgst])?(\d{7})([a-jz])$/i
Branch: 1 branch
BranchTrueFalseTotal
if ($number =~ /^([fgst])?(\d{7})([a-jz])$/i and uc $3 eq $self->_compute_checkdigits($2)) 2 0 2
Condition33%1/3
$number =~ /^([fgst])?(\d{7})([a-jz])$/i and uc $3 eq $self->_compute_checkdigits($2)
!ll&&!rl&&r
002
MC/DC0%0/2
$number =~ /^([fgst])?(\d{7})([a-jz])$/i and uc $3 eq $self->_compute_checkdigits($2)
$number =~ /^([fgst])?(\d{7})([a-jz])$/i uc $3 eq $self->_compute_checkdigits($2)
Truth table33%1/3
A and B
A= $number =~ /^([fgst])?(\d{7})([a-jz])$/iB= uc $3 eq $self->_compute_checkdigits($2)
ABresult
0X0
100
111
45 and uc($3) eq $self->_compute_checkdigits($2)) {
46 2 ▶ my $prefix = $1 || '';
Condition100%2/2
$1 || ''
l!l
11
MC/DC100%1/1
$1 || ''
$1
Truth table100%2/2
A
A= $1
Aresult
11
00
47 2 return $prefix . $2;
48 }
49 0 return '';
50 } # basenumber()
51  
52 2 ▶sub checkdigit {
Subroutine checkdigit: called CC=2 SCAR=7.6
Pod documented
53 2 my ($self,$number) = @_;
54 2 ▶ if ($number =~ /^([fgst])?(\d{7})([a-jz])$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($number =~ /^([fgst])?(\d{7})([a-jz])$/i) 2 0 2
55 2 return $self->_compute_checkdigits($2);
56 }
57 0 return undef;
58 } # checkdigit()
59  
60 10 ▶sub _compute_checkdigits {
Subroutine _compute_checkdigits: called CC=2 SCAR=6.9
61 10 my $self = shift;
62  
63 10 my @digits = split(//,shift);
64 10 my $sum = 0;
65 10 ▶ for (my $i = 0; $i <= $#digits; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#digits) 70 10 80
66 70 $sum += $weight[$i] * $digits[$i];
67 }
68 10 $sum %= 11;
69 10 return $keys[11 - $sum];
70 } # _compute_checkdigit()
71  
72 # Preloaded methods go here.
73  
74 2 1;
75 __END__
« blib/lib/Algorithm/CheckDigits/M09_001.pm ↑ Summary blib/lib/Algorithm/CheckDigits/MXX_005.pm »