line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Vparam::Barcode; |
2
|
73
|
|
|
73
|
|
4681825
|
use Mojo::Base -strict; |
|
73
|
|
|
|
|
108740
|
|
|
73
|
|
|
|
|
422
|
|
3
|
73
|
|
|
73
|
|
8128
|
use Mojolicious::Plugin::Vparam::Common; |
|
73
|
|
|
|
|
143
|
|
|
73
|
|
|
|
|
25022
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub check_barcode($) { |
6
|
9
|
50
|
|
9
|
0
|
16
|
return 'Value not defined' unless defined $_[0]; |
7
|
9
|
100
|
|
|
|
23
|
return 'Value not set' unless length $_[0]; |
8
|
8
|
50
|
|
|
|
72
|
return 'Wrong format' unless $_[0] =~ m{^[0-9]+$}; |
9
|
|
|
|
|
|
|
|
10
|
8
|
|
|
|
|
10
|
my $crc = 0; |
11
|
8
|
|
|
|
|
32
|
my @str = reverse split '', $_[0]; |
12
|
8
|
|
|
|
|
17
|
for my $i ( 0 .. $#str ) { |
13
|
98
|
|
|
|
|
93
|
my $digit = $str[$i]; |
14
|
98
|
100
|
|
|
|
122
|
$digit *= 3 if $i % 2; |
15
|
98
|
|
|
|
|
112
|
$crc += $digit; |
16
|
|
|
|
|
|
|
} |
17
|
8
|
100
|
|
|
|
17
|
return 'Checksum error' if $crc % 10; |
18
|
|
|
|
|
|
|
|
19
|
7
|
|
|
|
|
20
|
return 0; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub parse_barcode($) { |
23
|
9
|
|
|
9
|
0
|
10
|
my ($str) = @_; |
24
|
9
|
50
|
|
|
|
17
|
return undef unless defined $str; |
25
|
9
|
|
|
|
|
24
|
s{[^0-9]}{}g for $str; |
26
|
9
|
|
|
|
|
15
|
return $str; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub register { |
30
|
75
|
|
|
75
|
0
|
215
|
my ($class, $self, $app, $conf) = @_; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$app->vtype( |
33
|
|
|
|
|
|
|
barcode => |
34
|
9
|
|
|
9
|
|
17
|
pre => sub { parse_barcode $_[1] }, |
35
|
9
|
|
|
9
|
|
15
|
valid => sub { check_barcode $_[1] }, |
36
|
75
|
|
|
|
|
679
|
); |
37
|
|
|
|
|
|
|
|
38
|
75
|
|
|
|
|
325
|
return; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |