line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Business::PL::NIP; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
363
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
432
|
use Exporter::Easy ( OK => [ qw(is_valid_nip) ] ); |
|
1
|
|
|
|
|
1171
|
|
|
1
|
|
|
|
|
5
|
|
7
|
1
|
|
|
1
|
|
85
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
8
|
1
|
|
|
1
|
|
4
|
use List::Util qw(sum); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
319
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
3
|
|
|
3
|
0
|
5
|
my ( $class, %args ) = @_; |
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
|
|
13
|
bless \%args => $class; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my @weights = qw(6 5 7 2 3 4 5 6 7); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub is_valid { |
21
|
4
|
|
|
4
|
0
|
8
|
my ($self,%args) = @_; |
22
|
|
|
|
|
|
|
|
23
|
4
|
|
33
|
|
|
19
|
my $nip = $self->{nip} || $args{nip}; |
24
|
|
|
|
|
|
|
|
25
|
4
|
50
|
|
|
|
6
|
croak "No NIP number provided" unless $nip; |
26
|
4
|
|
|
|
|
6
|
$nip =~ s/^PL//; |
27
|
4
|
50
|
|
|
|
13
|
croak "NIP number invalid" unless $nip =~ /^[0-9]{10}$/; |
28
|
|
|
|
|
|
|
|
29
|
4
|
|
|
|
|
15
|
my @nip = split "", $nip; |
30
|
4
|
|
|
|
|
6
|
my $check_sum = pop @nip; |
31
|
|
|
|
|
|
|
|
32
|
4
|
|
|
|
|
10
|
my $verify_check_sum += sum( map { $nip[$_] * $weights[$_] } 0..$#nip ); |
|
36
|
|
|
|
|
55
|
|
33
|
|
|
|
|
|
|
|
34
|
4
|
|
|
|
|
6
|
$verify_check_sum %= 11; |
35
|
|
|
|
|
|
|
|
36
|
4
|
|
|
|
|
20
|
return $verify_check_sum == $check_sum; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub is_valid_nip { |
41
|
2
|
|
|
2
|
0
|
9
|
my $nip = shift; |
42
|
|
|
|
|
|
|
|
43
|
2
|
|
|
|
|
10
|
return __PACKAGE__->new->is_valid(nip => $nip); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__END__ |