| 1 | package Identifier::PL::PESEL; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 3 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | Identifier::PL::PESEL - Validator for polish PESEL number. | ||||||||||
| 11 | |||||||||||
| 12 | =head1 VERSION | ||||||||||
| 13 | |||||||||||
| 14 | Version 0.3 | ||||||||||
| 15 | |||||||||||
| 16 | =cut | ||||||||||
| 17 | |||||||||||
| 18 | 3 | our $VERSION = '0.3'; | |||||||||
| 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<https://en.wikipedia.org/wiki/PESEL> | ||||||||||
| 31 | |||||||||||
| 32 | =head1 METHODS | ||||||||||
| 33 | |||||||||||
| 34 | =head2 new | ||||||||||
| 35 | |||||||||||
| 36 | Create new object of C<Identifier::PL::PESEL> | ||||||||||
| 37 | |||||||||||
| 38 | =cut | ||||||||||
| 39 | |||||||||||
| 40 | sub new { | ||||||||||
| 41 | 2 | ▶ | return bless {}, $_[0]; | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 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<Carp::confess> will be called if number to validate is missing. | ||||||||||
| 52 | |||||||||||
| 53 | =cut | ||||||||||
| 54 | |||||||||||
| 55 | sub validate { | ||||||||||
| 56 | 9 | ▶ | my ( $self, $pesel ) = @_; | ||||||||
|
Subroutine
validate: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 57 | |||||||||||
| 58 | 9 | ▶ | confess 'Missing pesel parameter' unless defined $pesel; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | |||||||||||
| 60 | 8 | ▶ | return unless $pesel =~ /^\d{11}$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | |||||||||||
| 62 | 3 | my @p = split '', $pesel; | |||||||||
| 63 | |||||||||||
| 64 | 3 | my $check_sum = pop @p; | |||||||||
| 65 | |||||||||||
| 66 | 3 | my @weight = (1,3,7,9,1,3,7,9,1,3); | |||||||||
| 67 | |||||||||||
| 68 | 3 | my $new_check_sum = 0; | |||||||||
| 69 | |||||||||||
| 70 | 3 | $new_check_sum += $_ * shift @weight for @p; | |||||||||
| 71 | 3 | $new_check_sum %= 10; | |||||||||
| 72 | 3 | $new_check_sum = 10 - $new_check_sum; | |||||||||
| 73 | |||||||||||
| 74 | 3 | ▶ | return 1 if $check_sum == $new_check_sum; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | |||||||||||
| 76 | 2 | return; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | =head1 AUTHOR | ||||||||||
| 80 | |||||||||||
| 81 | Andrzej Cholewiusz | ||||||||||
| 82 | |||||||||||
| 83 | =head1 COPYRIGHT | ||||||||||
| 84 | |||||||||||
| 85 | The full text of the license can be found in the | ||||||||||
| 86 | LICENSE file included with this module. | ||||||||||
| 87 | |||||||||||
| 88 | =cut | ||||||||||
| 89 | |||||||||||
| 90 | 3 | 1; | |||||||||