Common/_support.pm

filter: Statementstmt 100% 32 / 32 Branchbran 83.3% 5 / 6 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 91.0% 51 / 56 CC 7 SCAR 12.5
CC
7
Cov
93%
luhn
6.1
import
2.0
BEGIN
1.0
CRAP 3.5
« Common/net.pm ↑ Summary Common/zip.pm »
1 package Regexp::Common::_support;
2  
3 71 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 71 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 71 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 71 ▶no warnings 'syntax';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 71 our $VERSION = '2024080801';
10  
11 #
12 # Returns true/false, depending whether the given the argument
13 # satisfies the LUHN checksum.
14 # See http://www.webopedia.com/TERM/L/Luhn_formula.html.
15 #
16 # Note that this function is intended to be called from regular
17 # expression, so it should NOT use a regular expression in any way.
18 #
19 204 ▶sub luhn {
Subroutine luhn: called CC=6 SCAR=18.0
Pod documented
20 204 my $arg = shift;
21 204 my $even = 0;
22 204 my $sum = 0;
23 204 ▶ while (length $arg) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $arg) 2650 204 2854
24 2650 my $num = chop $arg;
25 2650 ▶ return if $num lt '0' || $num gt '9';
Branch: 1 branch
BranchTrueFalseTotal
if $num lt 0 or $num gt 9 0 2650 2650
Condition33%1/3
$num lt 0 or $num gt 9
l!l&&r!l&&!r
002650
MC/DC0%0/2
$num lt 0 or $num gt 9
$num lt 0 $num gt 9
Truth table33%1/3
A or B
A= $num lt 0B= $num gt 9
ABresult
1X1
011
000
26 2650 ▶ if ($even && (($num *= 2) > 9)) {$num = 1 + ($num % 10)}
Branch: 1 branch
BranchTrueFalseTotal
if ($even and ($num *= 2) > 9) 690 1960 2650
Condition100%3/3
$even and ($num *= 2) > 9
!ll&&!rl&&r
1370590690
MC/DC100%2/2
$even and ($num *= 2) > 9
$even ($num *= 2) > 9
Truth table100%3/3
A and B
A= $evenB= ($num *= 2) > 9
ABresult
0X0
100
111
27 2650 $even = 1 - $even;
28 2650 $sum += $num;
29 }
30 204 !($sum % 10)
31 }
32  
33 72 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
34 72 my $pack = shift;
35 72 my $caller = caller;
36 71 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
37 72 *{$caller . "::" . $_} = \&{$pack . "::" . $_} for @_;
38 }
39  
40  
41 71 1;
42  
43 __END__
« Common/net.pm ↑ Summary Common/zip.pm »