File Coverage

blib/lib/Business/PL/NIP.pm
Criterion Covered Total %
statement 25 25 100.0
branch 2 4 50.0
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 33 36 91.6


line stmt bran cond sub pod time code
1             package Business::PL::NIP;
2              
3 1     1   555 use strict;
  1         2  
  1         23  
4 1     1   4 use warnings;
  1         1  
  1         30  
5              
6 1     1   739 use Exporter::Easy ( OK => [ qw(is_valid_nip) ] );
  1         1662  
  1         7  
7 1     1   128 use Carp qw(croak);
  1         1  
  1         70  
8 1     1   5 use List::Util qw(sum);
  1         1  
  1         311  
9              
10             our $VERSION = '0.03';
11              
12             my @weights = qw(6 5 7 2 3 4 5 6 7);
13              
14             sub is_valid_nip {
15              
16 2     2 0 10 my $nip = shift;
17              
18 2 50       6 croak "No NIP number provided" unless $nip;
19 2         5 $nip =~ s/^PL//;
20 2 50       9 return unless $nip =~ /^[0-9]{10}$/;
21              
22 2         11 my @nip = split "", $nip;
23 2         4 my $check_sum = pop @nip;
24              
25 2         6 my $verify_check_sum += sum( map { $nip[$_] * $weights[$_] } 0..$#nip );
  18         44  
26              
27 2         5 $verify_check_sum %= 11;
28              
29 2         13 return $verify_check_sum == $check_sum;
30             }
31              
32              
33              
34             1;
35              
36             __END__