| 1 | package Regexp::Common::CC; | ||||||||||||||||||||||||||||
| 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 | ▶ | use Regexp::Common qw /pattern clean no_defaults/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 71 | ▶ | use Regexp::Common::_support qw /luhn/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 71 | our $VERSION = '2024080801'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 71 | my @cards = ( | |||||||||||||||||||||||||||
| 15 | # Name Prefix Length mod 10 | ||||||||||||||||||||||||||||
| 16 | [Mastercard => '5[1-5]', 16, 1], | ||||||||||||||||||||||||||||
| 17 | [Visa => '4', [13, 16], 1], | ||||||||||||||||||||||||||||
| 18 | [Amex => '3[47]', 15, 1], | ||||||||||||||||||||||||||||
| 19 | # Carte Blanche | ||||||||||||||||||||||||||||
| 20 | ['Diners Club' => '3(?:0[0-5]|[68])', 14, 1], | ||||||||||||||||||||||||||||
| 21 | [Discover => '6011', 16, 1], | ||||||||||||||||||||||||||||
| 22 | [enRoute => '2(?:014|149)', 15, 0], | ||||||||||||||||||||||||||||
| 23 | [JCB => [['3', 16, 1], | ||||||||||||||||||||||||||||
| 24 | ['2131|1800', 15, 1]]], | ||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 71 | foreach my $card (@cards) { | |||||||||||||||||||||||||||
| 29 | 497 | my ($name, $prefix, $length, $mod) = @$card; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # Skip the harder ones for now. | ||||||||||||||||||||||||||||
| 32 | 497 | ▶ | next if ref $prefix || ref $length; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $prefix or ref $length
MC/DC100%2/2
ref $prefix or ref $length
ref $prefix
ref $length
Truth table100%3/3
A or B
A= ref $prefixB= ref $length
| |||||||||||||||||||||||||||||
| 33 | 355 | ▶ | next unless $mod; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 284 | my $times = $length + $mod; | |||||||||||||||||||||||||||
| 36 | pattern name => [CC => $name], | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | create => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||
| 38 | 71 | ▶ | use re 'eval'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | qr <((?=($prefix))[0-9]{$length}) | ||||||||||||||||||||||||||||
| 40 | (?(?{Regexp::Common::_support::luhn $1})|(?!))>x | ||||||||||||||||||||||||||||
| 41 | 0 | } | |||||||||||||||||||||||||||
| 42 | 284 | ; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 71 | 1; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | __END__ | ||||||||||||||||||||||||||||