| 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
| |||||||||||||||||||||||||||||
| 24 | 2650 | my $num = chop $arg; | |||||||||||||||||||||||||||
| 25 | 2650 | ▶ | return if $num lt '0' || $num gt '9'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$num lt 0 or $num gt 9
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
| |||||||||||||||||||||||||||||
| 26 | 2650 | ▶ | if ($even && (($num *= 2) > 9)) {$num = 1 + ($num % 10)} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$even and ($num *= 2) > 9
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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||