line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2003-2022 by [Mark Overmeer ]. |
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 2.03. |
5
|
|
|
|
|
|
|
# This code is part of distribution Math-Polygon. Meta-POD processed with |
6
|
|
|
|
|
|
|
# OODoc into POD and HTML manual-pages. See README.md |
7
|
|
|
|
|
|
|
# Copyright Mark Overmeer. Licensed under the same terms as Perl itself. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package User::Identity; |
10
|
3
|
|
|
3
|
|
57637
|
use vars '$VERSION'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
196
|
|
11
|
|
|
|
|
|
|
$VERSION = '1.01'; |
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
17
|
use base 'User::Identity::Item'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
567
|
|
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
80
|
|
16
|
3
|
|
|
3
|
|
19
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
72
|
|
17
|
|
|
|
|
|
|
|
18
|
3
|
|
|
3
|
|
14
|
use Carp; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
168
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
3
|
|
|
3
|
|
3254
|
use overload '""' => 'fullName'; |
|
3
|
|
|
|
|
2791
|
|
|
3
|
|
|
|
|
19
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#----------------------------------------- |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my @attributes = qw/charset courtesy birth full_name formal_name |
27
|
|
|
|
|
|
|
firstname gender initials language nickname prefix surname titles /; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub init($) |
30
|
7
|
|
|
7
|
0
|
14
|
{ my ($self, $args) = @_; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
exists $args->{$_} && ($self->{'UI_'.$_} = delete $args->{$_}) |
33
|
7
|
|
100
|
|
|
186
|
foreach @attributes; |
34
|
|
|
|
|
|
|
|
35
|
7
|
|
|
|
|
36
|
$self->SUPER::init($args); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub type() { 'user' } |
39
|
|
|
|
|
|
|
|
40
|
4
|
|
|
4
|
1
|
16
|
sub user() { shift } |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
1
|
50
|
|
1
|
1
|
7
|
sub charset() { shift->{UI_charset} || $ENV{LC_CTYPE} } |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub nickname() |
47
|
5
|
|
|
5
|
1
|
739
|
{ my $self = shift; |
48
|
5
|
50
|
|
|
|
15
|
$self->{UI_nickname} || $self->name; |
49
|
|
|
|
|
|
|
# TBI: If OS-specific info exists, then username |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub firstname() |
54
|
9
|
|
|
9
|
1
|
15
|
{ my $self = shift; |
55
|
9
|
100
|
|
|
|
35
|
$self->{UI_firstname} || ucfirst $self->nickname; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub initials() |
60
|
6
|
|
|
6
|
1
|
240
|
{ my $self = shift; |
61
|
|
|
|
|
|
|
return $self->{UI_initials} |
62
|
6
|
100
|
|
|
|
18
|
if defined $self->{UI_initials}; |
63
|
|
|
|
|
|
|
|
64
|
4
|
50
|
|
|
|
6
|
if(my $firstname = $self->firstname) |
65
|
4
|
|
|
|
|
6
|
{ my $i = ''; |
66
|
4
|
|
|
|
|
22
|
while( $firstname =~ m/(\w+)(\-)?/g ) |
67
|
12
|
|
|
|
|
25
|
{ my ($part, $connect) = ($1,$2); |
68
|
12
|
|
100
|
|
|
33
|
$connect ||= '.'; |
69
|
12
|
|
|
|
|
25
|
$part =~ m/^(chr|th|\w)/i; |
70
|
12
|
|
|
|
|
40
|
$i .= ucfirst(lc $1).$connect; |
71
|
|
|
|
|
|
|
} |
72
|
4
|
|
|
|
|
19
|
return $i; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
1
|
1
|
4
|
sub prefix() { shift->{UI_prefix} } |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
1
|
|
|
1
|
1
|
4
|
sub surname() { shift->{UI_surname} } |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub fullName() |
84
|
10
|
|
|
10
|
1
|
29
|
{ my $self = shift; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
return $self->{UI_full_name} |
87
|
10
|
50
|
|
|
|
27
|
if defined $self->{UI_full_name}; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my ($first, $prefix, $surname) |
90
|
10
|
|
|
|
|
26
|
= @$self{ qw/UI_firstname UI_prefix UI_surname/}; |
91
|
|
|
|
|
|
|
|
92
|
10
|
50
|
66
|
|
|
35
|
$surname = ucfirst $self->nickname if defined $first && ! defined $surname; |
93
|
10
|
50
|
66
|
|
|
27
|
$first = $self->firstname if !defined $first && defined $surname; |
94
|
|
|
|
|
|
|
|
95
|
10
|
|
|
|
|
18
|
my $full = join ' ', grep {defined $_} ($first,$prefix,$surname); |
|
30
|
|
|
|
|
61
|
|
96
|
|
|
|
|
|
|
|
97
|
10
|
100
|
|
|
|
25
|
$full = $self->firstname unless length $full; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# TBI: if OS-specific knowledge, then unix GCOS? |
100
|
|
|
|
|
|
|
|
101
|
10
|
|
|
|
|
36
|
$full; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub formalName() |
106
|
3
|
|
|
3
|
1
|
6
|
{ my $self = shift; |
107
|
|
|
|
|
|
|
return $self->{UI_formal_name} |
108
|
3
|
50
|
|
|
|
8
|
if defined $self->{UI_formal_name}; |
109
|
|
|
|
|
|
|
|
110
|
3
|
|
|
|
|
11
|
my $initials = $self->initials; |
111
|
|
|
|
|
|
|
|
112
|
3
|
|
|
|
|
5
|
my $firstname = $self->{UI_firstname}; |
113
|
3
|
50
|
|
|
|
8
|
$firstname = "($firstname)" if defined $firstname; |
114
|
|
|
|
|
|
|
|
115
|
15
|
|
|
|
|
33
|
my $full = join ' ', grep {defined $_} |
116
|
|
|
|
|
|
|
$self->courtesy, $initials |
117
|
3
|
|
|
|
|
7
|
, @$self{ qw/UI_prefix UI_surname UI_titles/ }; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
my %male_courtesy |
122
|
|
|
|
|
|
|
= ( mister => 'en' |
123
|
|
|
|
|
|
|
, mr => 'en' |
124
|
|
|
|
|
|
|
, sir => 'en' |
125
|
|
|
|
|
|
|
, 'de heer' => 'nl' |
126
|
|
|
|
|
|
|
, mijnheer => 'nl' |
127
|
|
|
|
|
|
|
, dhr => 'nl' |
128
|
|
|
|
|
|
|
, herr => 'de' |
129
|
|
|
|
|
|
|
); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
my %male_courtesy_default |
132
|
|
|
|
|
|
|
= ( en => 'Mr.' |
133
|
|
|
|
|
|
|
, nl => 'De heer' |
134
|
|
|
|
|
|
|
, de => 'Herr' |
135
|
|
|
|
|
|
|
); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
my %female_courtesy |
138
|
|
|
|
|
|
|
= ( miss => 'en' |
139
|
|
|
|
|
|
|
, ms => 'en' |
140
|
|
|
|
|
|
|
, mrs => 'en' |
141
|
|
|
|
|
|
|
, madam => 'en' |
142
|
|
|
|
|
|
|
, mevr => 'nl' |
143
|
|
|
|
|
|
|
, mevrouw => 'nl' |
144
|
|
|
|
|
|
|
, frau => 'de' |
145
|
|
|
|
|
|
|
); |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
my %female_courtesy_default |
148
|
|
|
|
|
|
|
= ( en => 'Madam' |
149
|
|
|
|
|
|
|
, nl => 'Mevrouw' |
150
|
|
|
|
|
|
|
, de => 'Frau' |
151
|
|
|
|
|
|
|
); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub courtesy() |
154
|
3
|
|
|
3
|
1
|
3
|
{ my $self = shift; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
return $self->{UI_courtesy} |
157
|
3
|
50
|
|
|
|
7
|
if defined $self->{UI_courtesy}; |
158
|
|
|
|
|
|
|
|
159
|
3
|
50
|
|
|
|
5
|
my $table |
|
|
100
|
|
|
|
|
|
160
|
|
|
|
|
|
|
= $self->isMale ? \%male_courtesy_default |
161
|
|
|
|
|
|
|
: $self->isFemale ? \%female_courtesy_default |
162
|
|
|
|
|
|
|
: return undef; |
163
|
|
|
|
|
|
|
|
164
|
3
|
|
|
|
|
7
|
my $lang = lc $self->language; |
165
|
3
|
100
|
|
|
|
13
|
return $table->{$lang} if exists $table->{$lang}; |
166
|
|
|
|
|
|
|
|
167
|
1
|
|
|
|
|
12
|
$lang =~ s/\..*//; # "en_GB.utf8" --> "en-GB" and retry |
168
|
1
|
50
|
|
|
|
4
|
return $table->{$lang} if exists $table->{$lang}; |
169
|
|
|
|
|
|
|
|
170
|
1
|
|
|
|
|
7
|
$lang =~ s/[-_].*//; # "en_GB.utf8" --> "en" and retry |
171
|
1
|
|
|
|
|
3
|
$table->{$lang}; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# TBI: if we have a courtesy, we may detect the language. |
176
|
|
|
|
|
|
|
# TBI: when we have a postal address, we may derive the language from |
177
|
|
|
|
|
|
|
# the country. |
178
|
|
|
|
|
|
|
# TBI: if we have an e-mail addres, we may derive the language from |
179
|
|
|
|
|
|
|
# that. |
180
|
|
|
|
|
|
|
|
181
|
3
|
100
|
|
3
|
1
|
12
|
sub language() { shift->{UI_language} || 'en' } |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
3
|
|
|
3
|
1
|
238
|
sub gender() { shift->{UI_gender} } |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub isMale() |
188
|
6
|
|
|
6
|
1
|
9
|
{ my $self = shift; |
189
|
|
|
|
|
|
|
|
190
|
6
|
100
|
|
|
|
12
|
if(my $gender = $self->{UI_gender}) |
191
|
5
|
|
|
|
|
28
|
{ return $gender =~ m/^[mh]/i; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
1
|
50
|
|
|
|
3
|
if(my $courtesy = $self->{UI_courtesy}) |
195
|
0
|
|
|
|
|
0
|
{ $courtesy = lc $courtesy; |
196
|
0
|
|
|
|
|
0
|
$courtesy =~ s/[^\s\w]//g; |
197
|
0
|
0
|
|
|
|
0
|
return 1 if exists $male_courtesy{$courtesy}; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
1
|
|
|
|
|
3
|
undef; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub isFemale() |
205
|
4
|
|
|
4
|
1
|
5
|
{ my $self = shift; |
206
|
|
|
|
|
|
|
|
207
|
4
|
100
|
|
|
|
12
|
if(my $gender = $self->{UI_gender}) |
208
|
3
|
|
|
|
|
14
|
{ return $gender =~ m/^[vf]/i; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
1
|
50
|
|
|
|
3
|
if(my $courtesy = $self->{UI_courtesy}) |
212
|
0
|
|
|
|
|
0
|
{ $courtesy = lc $courtesy; |
213
|
0
|
|
|
|
|
0
|
$courtesy =~ s/[^\s\w]//g; |
214
|
0
|
0
|
|
|
|
0
|
return 1 if exists $female_courtesy{$courtesy}; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
1
|
|
|
|
|
3
|
undef; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
221
|
1
|
|
|
1
|
1
|
4
|
sub dateOfBirth() { shift->{UI_birth} } |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub birth() |
225
|
0
|
|
|
0
|
1
|
|
{ my $birth = shift->dateOfBirth; |
226
|
0
|
|
|
|
|
|
my $time; |
227
|
|
|
|
|
|
|
|
228
|
0
|
0
|
|
|
|
|
if($birth =~ m/^\s*(\d{4})[-\s]*(\d{2})[-\s]*(\d{2})\s*$/) |
229
|
|
|
|
|
|
|
{ # Pre-formatted. |
230
|
0
|
|
|
|
|
|
return sprintf "%04d%02d%02d", $1, $2, $3; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
0
|
|
|
|
|
|
eval "require Date::Parse"; |
234
|
0
|
0
|
|
|
|
|
unless($@) |
235
|
0
|
|
|
|
|
|
{ my ($day,$month,$year) = (Date::Parse::strptime($birth))[3,4,5]; |
236
|
0
|
0
|
|
|
|
|
if(defined $year) |
237
|
0
|
0
|
0
|
|
|
|
{ return sprintf "%04d%02d%02d" |
238
|
|
|
|
|
|
|
, ($year + 1900) |
239
|
|
|
|
|
|
|
, (defined $month ? $month+1 : 0) |
240
|
|
|
|
|
|
|
, ($day || 0); |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
# TBI: Other date parsers |
245
|
|
|
|
|
|
|
|
246
|
0
|
|
|
|
|
|
undef; |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
sub age() |
251
|
0
|
0
|
|
0
|
1
|
|
{ my $birth = shift->birth or return; |
252
|
|
|
|
|
|
|
|
253
|
0
|
|
|
|
|
|
my ($year, $month, $day) = $birth =~ m/^(\d{4})(\d\d)(\d\d)$/; |
254
|
0
|
|
|
|
|
|
my ($today, $tomonth, $toyear) = (localtime)[3,4,5]; |
255
|
0
|
|
|
|
|
|
$tomonth++; |
256
|
|
|
|
|
|
|
|
257
|
0
|
|
|
|
|
|
my $age = $toyear+1900 - $year; |
258
|
0
|
0
|
0
|
|
|
|
$age-- if $month > $tomonth || ($month == $tomonth && $day >= $today); |
|
|
|
0
|
|
|
|
|
259
|
0
|
|
|
|
|
|
$age; |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
|
263
|
0
|
|
|
0
|
1
|
|
sub titles() { shift->{UI_titles} } |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
1; |
266
|
|
|
|
|
|
|
|