line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Vparam::ISIN; |
2
|
72
|
|
|
72
|
|
549195
|
use Mojo::Base -strict; |
|
72
|
|
|
|
|
7790
|
|
|
72
|
|
|
|
|
479
|
|
3
|
72
|
|
|
72
|
|
7420
|
use Mojolicious::Plugin::Vparam::Common qw(char_shift); |
|
72
|
|
|
|
|
143
|
|
|
72
|
|
|
|
|
48119
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub check_isin($) { |
6
|
10
|
50
|
|
10
|
0
|
25
|
return 'Value not defined' unless defined $_[0]; |
7
|
10
|
100
|
|
|
|
30
|
return 'Value not set' unless length $_[0]; |
8
|
9
|
50
|
|
|
|
46
|
return 'Wrong format' unless $_[0] =~ m{^[A-Z0-9]+$}; |
9
|
|
|
|
|
|
|
|
10
|
9
|
|
|
|
|
19
|
my $str = $_[0]; |
11
|
9
|
|
|
|
|
22
|
my $ch = char_shift(); |
12
|
9
|
|
|
|
|
30
|
s{([A-Z])}{(ord($1)-$ch)}eg for $str; |
|
15
|
|
|
|
|
52
|
|
13
|
9
|
|
|
|
|
16
|
my $crc = 0; |
14
|
9
|
|
|
|
|
55
|
my @str = reverse split '', $str; |
15
|
9
|
|
|
|
|
25
|
for my $i ( 0 .. $#str ) { |
16
|
130
|
|
|
|
|
161
|
my $digit = $str[$i]; |
17
|
130
|
100
|
|
|
|
229
|
$digit *= 2 if $i % 2; |
18
|
130
|
100
|
|
|
|
235
|
$digit -= 9 if $digit > 9; |
19
|
130
|
|
|
|
|
169
|
$crc += $digit; |
20
|
|
|
|
|
|
|
} |
21
|
9
|
100
|
|
|
|
22
|
return 'Checksum error' if $crc % 10; |
22
|
|
|
|
|
|
|
|
23
|
8
|
|
|
|
|
30
|
return 0; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub check_maestro { |
27
|
3
|
50
|
|
3
|
0
|
7
|
return 'Value not defined' unless defined $_[0]; |
28
|
3
|
100
|
|
|
|
13
|
return 'Value not set' unless length $_[0]; |
29
|
2
|
50
|
|
|
|
10
|
return 'Wrong format' unless $_[0] =~ m{^\d+$}; |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
7
|
return 0; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub check_creditcard { |
35
|
5
|
50
|
|
5
|
0
|
11
|
return 'Value not defined' unless defined $_[0]; |
36
|
5
|
100
|
|
|
|
15
|
return 'Value not set' unless length $_[0]; |
37
|
4
|
100
|
|
|
|
21
|
return 'Wrong format' unless $_[0] =~ m{^\d+$}; |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
7
|
return 0; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub parse_isin($) { |
43
|
15
|
|
|
15
|
0
|
27
|
my ($str) = @_; |
44
|
15
|
50
|
|
|
|
34
|
return undef unless defined $str; |
45
|
15
|
|
|
|
|
72
|
s{[^a-zA-Z0-9]}{}g for $str; |
46
|
15
|
|
|
|
|
60
|
return uc $str; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub parse_maestro($) { |
50
|
3
|
|
|
3
|
0
|
6
|
my ($str) = @_; |
51
|
3
|
50
|
|
|
|
7
|
return undef unless defined $str; |
52
|
3
|
|
|
|
|
19
|
s{\D+}{}g for $str; |
53
|
3
|
|
|
|
|
9
|
return $str; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub parse_creditcard($) { |
57
|
5
|
|
|
5
|
0
|
11
|
return parse_isin $_[0]; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub register { |
61
|
74
|
|
|
74
|
0
|
221
|
my ($class, $self, $app, $conf) = @_; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$app->vtype( |
64
|
|
|
|
|
|
|
isin => |
65
|
10
|
|
|
10
|
|
22
|
pre => sub { parse_isin $_[1] }, |
66
|
10
|
|
|
10
|
|
22
|
valid => sub { check_isin $_[1] }, |
67
|
74
|
|
|
|
|
698
|
); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$app->vtype( |
70
|
|
|
|
|
|
|
maestro => |
71
|
3
|
|
|
3
|
|
8
|
pre => sub { parse_maestro $_[1] }, |
72
|
3
|
|
|
3
|
|
8
|
valid => sub { check_maestro $_[1] }, |
73
|
74
|
|
|
|
|
646
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$app->vtype( |
76
|
|
|
|
|
|
|
creditcard => |
77
|
5
|
|
|
5
|
|
11
|
pre => sub { parse_creditcard $_[1] }, |
78
|
5
|
|
|
5
|
|
11
|
valid => sub { check_creditcard $_[1] }, |
79
|
74
|
|
|
|
|
623
|
); |
80
|
|
|
|
|
|
|
|
81
|
74
|
|
|
|
|
271
|
return; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |