File Coverage

blib/lib/Identifier/PL/PESEL.pm
Criterion Covered Total %
statement 22 22 100.0
branch 6 6 100.0
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 35 35 100.0


line stmt bran cond sub pod time code
1             package Identifier::PL::PESEL;
2              
3 2     2   32750 use strict;
  2         4  
  2         48  
4 2     2   6 use warnings;
  2         2  
  2         40  
5              
6 2     2   6 use Carp;
  2         5  
  2         382  
7              
8             =head1 NAME
9              
10             Identifier::PL::PESEL - Validator for polish PESEL number.
11              
12             =head1 VERSION
13              
14             Version 0.2
15              
16             =cut
17              
18             our $VERSION = '0.2';
19              
20             =head1 SYNOPSIS
21              
22             use Identifier::PL::PESEL;
23              
24             my $pesel_number = '02070803628';
25             my $psl = Identifier::PL::PESEL->new();
26             print "OK" if $psl->validate( $pesel_number );
27              
28             =head1 DESCRIPTION
29              
30             More informations about PESEL L
31              
32             =head1 METHODS
33              
34             =head2 new
35              
36             Create new object of C
37              
38             =cut
39              
40             sub new {
41 2     2 1 1744 return bless {}, $_[0];
42             }
43              
44             =head2 validate
45              
46             Validate given PESEL number.
47              
48             Return 1 if number is valid.
49             Otherwise return undef.
50              
51             C will be called if number to validate is missing.
52              
53             =cut
54              
55             sub validate {
56 9     9 1 200 my ( $self, $pesel ) = @_;
57              
58 9 100       36 confess 'Missing pesel parameter' unless defined $pesel;
59              
60 8 100       29 return unless $pesel =~ /^\d{11}$/;
61              
62 3         11 my @p = split '', $pesel;
63              
64 3         4 my $check_sum = pop @p;
65              
66 3         8 my @weight = (1,3,7,9,1,3,7,9,1,3);
67              
68 3         2 my $new_check_sum = 0;
69              
70 3         19 $new_check_sum += $_ * shift @weight for @p;
71 3         3 $new_check_sum %= 10;
72 3         3 $new_check_sum = 10 - $new_check_sum;
73              
74 3 100       10 return 1 if $check_sum == $new_check_sum;
75              
76 2         7 return;
77             }
78              
79             =head1 AUTHOR
80              
81             Andrzej Cholewiusz
82              
83             Private website: L
84              
85             =head1 COPYRIGHT
86              
87             The full text of the license can be found in the
88             LICENSE file included with this module.
89              
90             =cut
91              
92             1;