blib/lib/Identifier/PL/PESEL.pm

filter: Statementstmt 100% 24 / 24 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 100% 37 / 37 SCAR 16.1
CC
5
Cov
100%
validate
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.0
↑ Summary
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.2
15  
16 =cut
17  
18 3 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<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
BranchTrueFalseTotal
unless defined $pesel 1 8 9
59  
60 8 ▶ return unless $pesel =~ /^\d{11}$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $pesel =~ /^\d{11}$/ 5 3 8
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
BranchTrueFalseTotal
if $check_sum == $new_check_sum 1 2 3
75  
76 2 return;
77 }
78  
79 =head1 AUTHOR
80  
81 Andrzej Cholewiusz
82  
83 Private website: L<http://cholewiusz.com>
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 3 1;
↑ Summary