line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::RandomPerson; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
687
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
533
|
use Data::Random qw(rand_date); |
|
1
|
|
|
|
|
2922
|
|
|
1
|
|
|
|
|
81
|
|
7
|
1
|
|
|
1
|
|
430
|
use Data::RandomPerson::Choice; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
563
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.51'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
5
|
|
|
5
|
1
|
2091
|
my ( $class, %args ) = @_; |
13
|
|
|
|
|
|
|
|
14
|
5
|
|
|
|
|
16
|
my $self = bless {}, $class; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
## |
17
|
|
|
|
|
|
|
## Set up the defaults for the various name classes |
18
|
|
|
|
|
|
|
## and see if they are being overwritten |
19
|
|
|
|
|
|
|
## |
20
|
|
|
|
|
|
|
|
21
|
5
|
|
|
|
|
8
|
my $male_class = 'Data::RandomPerson::Names::Male'; |
22
|
5
|
|
|
|
|
7
|
my $female_class = 'Data::RandomPerson::Names::Female'; |
23
|
5
|
|
|
|
|
7
|
my $last_class = 'Data::RandomPerson::Names::Last'; |
24
|
|
|
|
|
|
|
|
25
|
5
|
|
|
|
|
16
|
foreach my $key ( keys %args ) { |
26
|
7
|
100
|
|
|
|
29
|
if ( lc $key eq 'male' ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
27
|
2
|
|
|
|
|
3
|
$male_class = $args{$key}; |
28
|
2
|
|
|
|
|
5
|
delete( $args{$key} ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
elsif ( lc $key eq 'female' ) { |
31
|
2
|
|
|
|
|
7
|
$female_class = $args{$key}; |
32
|
2
|
|
|
|
|
6
|
delete( $args{$key} ); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
elsif ( lc $key eq 'last' ) { |
35
|
2
|
|
|
|
|
5
|
$last_class = $args{$key}; |
36
|
2
|
|
|
|
|
7
|
delete( $args{$key} ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else { |
39
|
1
|
|
|
|
|
21
|
die "Unknown argument '$key' passed to new"; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
## |
44
|
|
|
|
|
|
|
## Now load the classes |
45
|
|
|
|
|
|
|
## |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
1
|
|
248
|
eval "use $male_class;"; |
|
0
|
|
|
1
|
|
0
|
|
|
0
|
|
|
1
|
|
0
|
|
|
1
|
|
|
1
|
|
416
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
30
|
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
301
|
|
48
|
4
|
100
|
|
|
|
21
|
die "Unable to load '$male_class': $@" if $@; |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
1
|
|
228
|
eval "use $female_class;"; |
|
0
|
|
|
1
|
|
0
|
|
|
0
|
|
|
1
|
|
0
|
|
|
1
|
|
|
|
|
670
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
191
|
|
51
|
3
|
100
|
|
|
|
19
|
die "Unable to load '$female_class': $@" if $@; |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
1
|
|
252
|
eval "use $last_class;"; |
|
0
|
|
|
1
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
368
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
19
|
|
|
2
|
|
|
|
|
118
|
|
54
|
2
|
100
|
|
|
|
23
|
die "Unable to load '$last_class': $@" if $@; |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
13
|
$self->{mn} = $male_class->new(); |
57
|
1
|
|
|
|
|
13
|
$self->{fn} = $female_class->new(); |
58
|
1
|
|
|
|
|
13
|
$self->{ln} = $last_class->new(); |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
12
|
return $self; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
################################################################################ |
64
|
|
|
|
|
|
|
# Subclass these if you want to change the gender, age and title calculated |
65
|
|
|
|
|
|
|
################################################################################ |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _pick_gender { |
68
|
20
|
|
|
20
|
|
18
|
my ($self) = @_; |
69
|
|
|
|
|
|
|
|
70
|
20
|
100
|
|
|
|
179
|
return ( rand() < 0.5 ) ? 'm' : 'f'; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _pick_age { |
74
|
20
|
|
|
20
|
|
24
|
my ($self) = @_; |
75
|
|
|
|
|
|
|
|
76
|
20
|
|
|
|
|
52
|
return int( rand() * 100 ) + 1; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _pick_title { |
80
|
20
|
|
|
20
|
|
23
|
my ($self) = @_; |
81
|
|
|
|
|
|
|
|
82
|
20
|
|
|
|
|
63
|
my $choice = Data::RandomPerson::Choice->new(); |
83
|
|
|
|
|
|
|
|
84
|
20
|
100
|
|
|
|
54
|
if ( $self->{gender} eq 'm' ) { |
85
|
14
|
|
|
|
|
32
|
$choice->add( 'mr', 30 ); |
86
|
14
|
100
|
|
|
|
46
|
$choice->add('dr') if $self->{age} > 26; |
87
|
14
|
100
|
|
|
|
42
|
$choice->add('prof') if $self->{age} > 34; |
88
|
14
|
100
|
|
|
|
48
|
$choice->add('rev') if $self->{age} > 34; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else { |
91
|
6
|
|
|
|
|
20
|
$choice->add('miss'); |
92
|
6
|
50
|
|
|
|
26
|
$choice->add('ms') if $self->{age} > 16; |
93
|
6
|
50
|
|
|
|
29
|
$choice->add( 'mrs', 20 ) if $self->{age} > 16; |
94
|
6
|
100
|
|
|
|
32
|
$choice->add('dr') if $self->{age} > 26; |
95
|
6
|
100
|
|
|
|
23
|
$choice->add('prof') if $self->{age} > 34; |
96
|
6
|
100
|
|
|
|
19
|
$choice->add('rev') if $self->{age} > 34; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
20
|
|
|
|
|
39
|
return ucfirst $choice->pick(); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
################################################################################ |
103
|
|
|
|
|
|
|
# These methods do not, typically, need to be overridden |
104
|
|
|
|
|
|
|
################################################################################ |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _pick_lastname { |
107
|
20
|
|
|
20
|
|
24
|
my ($self) = @_; |
108
|
|
|
|
|
|
|
|
109
|
20
|
|
|
|
|
98
|
return $self->{ln}->get(); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub _pick_firstname { |
113
|
20
|
|
|
20
|
|
25
|
my ($self) = @_; |
114
|
|
|
|
|
|
|
|
115
|
20
|
100
|
|
|
|
96
|
return ( $self->{gender} eq 'm' ) ? $self->{mn}->get() : $self->{fn}->get(); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub _pick_dob { |
119
|
20
|
|
|
20
|
|
24
|
my ($self) = @_; |
120
|
|
|
|
|
|
|
|
121
|
20
|
|
|
|
|
383
|
my $year = ( localtime() )[5] + 1900 - $self->{age}; |
122
|
20
|
|
|
|
|
116
|
my $dob = rand_date(min => "$year-01-01", max => "$year-12-31"); |
123
|
|
|
|
|
|
|
|
124
|
20
|
|
|
|
|
31356
|
return $dob; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub create { |
128
|
20
|
|
|
20
|
1
|
79572
|
my ($self) = @_; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
## These settings have no prerequisites |
131
|
|
|
|
|
|
|
|
132
|
20
|
|
|
|
|
68
|
$self->{gender} = $self->_pick_gender(); |
133
|
20
|
|
|
|
|
53
|
$self->{age} = $self->_pick_age(); |
134
|
20
|
|
|
|
|
47
|
$self->{dob} = $self->_pick_dob(); |
135
|
20
|
|
|
|
|
51
|
$self->{lastname} = $self->_pick_lastname(); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
## This setting requires gender |
138
|
|
|
|
|
|
|
|
139
|
20
|
|
|
|
|
47
|
$self->{firstname} = $self->_pick_firstname(); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
## This setting requires gender and age |
142
|
|
|
|
|
|
|
|
143
|
20
|
|
|
|
|
42
|
$self->{title} = $self->_pick_title(); |
144
|
|
|
|
|
|
|
|
145
|
20
|
|
|
|
|
103
|
return { dob => $self->{dob}, gender => $self->{gender}, age => $self->{age}, firstname => $self->{firstname}, lastname => $self->{lastname}, title => $self->{title} }; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
__END__ |