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