line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::RandomPerson; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1021
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
49
|
|
4
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
55
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
915
|
use Data::Random qw(rand_date); |
|
2
|
|
|
|
|
17428
|
|
|
2
|
|
|
|
|
121
|
|
7
|
2
|
|
|
2
|
|
747
|
use Data::RandomPerson::Choice; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
47
|
|
8
|
2
|
|
|
2
|
|
704
|
use Module::Find; |
|
2
|
|
|
|
|
1609
|
|
|
2
|
|
|
|
|
1424
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.60'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
5
|
|
|
5
|
1
|
1521
|
my ( $class, %args ) = @_; |
14
|
|
|
|
|
|
|
|
15
|
5
|
|
|
|
|
9
|
my $self = bless {}, $class; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
## |
18
|
|
|
|
|
|
|
## Set up the defaults for the various name classes |
19
|
|
|
|
|
|
|
## and see if they are being overwritten |
20
|
|
|
|
|
|
|
## |
21
|
|
|
|
|
|
|
|
22
|
5
|
|
|
|
|
7
|
my $base_class = 'Data::RandomPerson::Names'; |
23
|
|
|
|
|
|
|
|
24
|
5
|
|
|
|
|
8
|
my $male_class = $base_class . '::Male'; |
25
|
5
|
|
|
|
|
6
|
my $female_class = $base_class . '::Female'; |
26
|
5
|
|
|
|
|
6
|
my $last_class = $base_class . '::Last'; |
27
|
|
|
|
|
|
|
|
28
|
5
|
|
|
|
|
16
|
foreach my $key ( sort keys %args ) { |
29
|
7
|
100
|
|
|
|
24
|
if ( lc $key eq 'male' ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
30
|
2
|
|
|
|
|
2
|
$male_class = $args{$key}; |
31
|
2
|
|
|
|
|
4
|
delete( $args{$key} ); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
elsif ( lc $key eq 'female' ) { |
34
|
2
|
|
|
|
|
2
|
$female_class = $args{$key}; |
35
|
2
|
|
|
|
|
4
|
delete( $args{$key} ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
elsif ( lc $key eq 'last' ) { |
38
|
2
|
|
|
|
|
3
|
$last_class = $args{$key}; |
39
|
2
|
|
|
|
|
3
|
delete( $args{$key} ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
elsif ($key eq 'type') { |
42
|
0
|
|
|
|
|
0
|
$male_class = $base_class . '::' . $args{$key} . 'Male'; |
43
|
0
|
|
|
|
|
0
|
$female_class = $base_class . '::' . $args{$key} . 'Female'; |
44
|
0
|
|
|
|
|
0
|
$last_class = $base_class . '::' . $args{$key} . 'Last'; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else { |
47
|
1
|
|
|
|
|
12
|
die "Unknown argument '$key' passed to new"; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
## |
52
|
|
|
|
|
|
|
## Now load the classes |
53
|
|
|
|
|
|
|
## |
54
|
|
|
|
|
|
|
|
55
|
4
|
|
|
1
|
|
195
|
eval "use $male_class;"; |
|
1
|
|
|
1
|
|
332
|
|
|
0
|
|
|
1
|
|
0
|
|
|
0
|
|
|
1
|
|
0
|
|
|
1
|
|
|
|
|
369
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
11
|
|
56
|
4
|
100
|
|
|
|
20
|
die "Unable to load '$male_class': $@" if $@; |
57
|
|
|
|
|
|
|
|
58
|
3
|
|
|
1
|
|
131
|
eval "use $female_class;"; |
|
1
|
|
|
1
|
|
169
|
|
|
0
|
|
|
1
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
347
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
59
|
3
|
100
|
|
|
|
16
|
die "Unable to load '$female_class': $@" if $@; |
60
|
|
|
|
|
|
|
|
61
|
2
|
|
|
1
|
|
74
|
eval "use $last_class;"; |
|
1
|
|
|
1
|
|
131
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
330
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
62
|
2
|
100
|
|
|
|
13
|
die "Unable to load '$last_class': $@" if $@; |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
7
|
$self->{mn} = $male_class->new(); |
65
|
1
|
|
|
|
|
12
|
$self->{fn} = $female_class->new(); |
66
|
1
|
|
|
|
|
16
|
$self->{ln} = $last_class->new(); |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
12
|
return $self; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
################################################################################ |
72
|
|
|
|
|
|
|
# Subclass these if you want to change the gender, age and title calculated |
73
|
|
|
|
|
|
|
################################################################################ |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _pick_gender { |
76
|
20
|
|
|
20
|
|
41
|
my ($self) = @_; |
77
|
|
|
|
|
|
|
|
78
|
20
|
100
|
|
|
|
578
|
return ( rand() < 0.5 ) ? 'm' : 'f'; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _pick_age { |
82
|
20
|
|
|
20
|
|
40
|
my ($self) = @_; |
83
|
|
|
|
|
|
|
|
84
|
20
|
|
|
|
|
77
|
return int( rand() * 100 ) + 1; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _pick_title { |
88
|
20
|
|
|
20
|
|
58
|
my ($self) = @_; |
89
|
|
|
|
|
|
|
|
90
|
20
|
|
|
|
|
153
|
my $choice = Data::RandomPerson::Choice->new(); |
91
|
|
|
|
|
|
|
|
92
|
20
|
100
|
|
|
|
196
|
if ( $self->{gender} eq 'm' ) { |
93
|
10
|
|
|
|
|
56
|
$choice->add( 'mr', 30 ); |
94
|
10
|
100
|
|
|
|
54
|
$choice->add('dr') if $self->{age} > 26; |
95
|
10
|
100
|
|
|
|
52
|
$choice->add('prof') if $self->{age} > 34; |
96
|
10
|
100
|
|
|
|
41
|
$choice->add('rev') if $self->{age} > 34; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
else { |
99
|
10
|
|
|
|
|
58
|
$choice->add('miss'); |
100
|
10
|
100
|
|
|
|
60
|
$choice->add('ms') if $self->{age} > 16; |
101
|
10
|
100
|
|
|
|
48
|
$choice->add( 'mrs', 20 ) if $self->{age} > 16; |
102
|
10
|
100
|
|
|
|
40
|
$choice->add('dr') if $self->{age} > 26; |
103
|
10
|
100
|
|
|
|
61
|
$choice->add('prof') if $self->{age} > 34; |
104
|
10
|
100
|
|
|
|
37
|
$choice->add('rev') if $self->{age} > 34; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
20
|
|
|
|
|
74
|
return ucfirst $choice->pick(); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
################################################################################ |
111
|
|
|
|
|
|
|
# These methods do not, typically, need to be overridden |
112
|
|
|
|
|
|
|
################################################################################ |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _pick_lastname { |
115
|
20
|
|
|
20
|
|
35
|
my ($self) = @_; |
116
|
|
|
|
|
|
|
|
117
|
20
|
|
|
|
|
144
|
return $self->{ln}->get(); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _pick_firstname { |
121
|
20
|
|
|
20
|
|
94
|
my ($self) = @_; |
122
|
|
|
|
|
|
|
|
123
|
20
|
100
|
|
|
|
312
|
return ( $self->{gender} eq 'm' ) ? $self->{mn}->get() : $self->{fn}->get(); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub _pick_dob { |
127
|
20
|
|
|
20
|
|
39
|
my ($self) = @_; |
128
|
|
|
|
|
|
|
|
129
|
20
|
|
|
|
|
414
|
my $year = ( localtime() )[5] + 1900 - $self->{age}; |
130
|
20
|
|
|
|
|
164
|
my $dob = rand_date(min => "$year-01-01", max => "$year-12-31"); |
131
|
|
|
|
|
|
|
|
132
|
20
|
|
|
|
|
5375
|
return $dob; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub create { |
136
|
20
|
|
|
20
|
1
|
114072
|
my ($self) = @_; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
## These settings have no prerequisites |
139
|
|
|
|
|
|
|
|
140
|
20
|
|
|
|
|
85
|
$self->{gender} = $self->_pick_gender(); |
141
|
20
|
|
|
|
|
71
|
$self->{age} = $self->_pick_age(); |
142
|
20
|
|
|
|
|
71
|
$self->{dob} = $self->_pick_dob(); |
143
|
20
|
|
|
|
|
69
|
$self->{lastname} = $self->_pick_lastname(); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
## This setting requires gender |
146
|
|
|
|
|
|
|
|
147
|
20
|
|
|
|
|
4361017
|
$self->{firstname} = $self->_pick_firstname(); |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
## This setting requires gender and age |
150
|
|
|
|
|
|
|
|
151
|
20
|
|
|
|
|
141672
|
$self->{title} = $self->_pick_title(); |
152
|
|
|
|
|
|
|
|
153
|
20
|
|
|
|
|
1299
|
return { dob => $self->{dob}, gender => $self->{gender}, age => $self->{age}, firstname => $self->{firstname}, lastname => $self->{lastname}, title => $self->{title} }; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub available_types { |
157
|
1
|
|
|
1
|
1
|
315
|
my @backends = sort { $a cmp $b } findsubmod Data::RandomPerson::Names; |
|
134
|
|
|
|
|
9936
|
|
158
|
1
|
|
|
|
|
3
|
my %backends = map {$_ => 1} @backends; |
|
34
|
|
|
|
|
41
|
|
159
|
1
|
|
|
|
|
2
|
my @available; |
160
|
1
|
|
|
|
|
2
|
for my $backend (grep {/Last$/} @backends) { |
|
34
|
|
|
|
|
30
|
|
161
|
6
|
100
|
|
|
|
18
|
if ($backend =~ /::(\w+)Last$/) { |
162
|
5
|
50
|
|
|
|
13
|
next if !$backends{'Data::RandomPerson::Names::' . $1 . 'Female'}; |
163
|
5
|
50
|
|
|
|
10
|
next if !$backends{'Data::RandomPerson::Names::' . $1 . 'Male'}; |
164
|
5
|
|
|
|
|
8
|
push @available, $1; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
} |
167
|
1
|
|
|
|
|
7
|
return @available; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
__END__ |