line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Myco::Core::Person; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
############################################################################### |
4
|
|
|
|
|
|
|
# $Id: Person.pm,v 1.1.1.1 2006/02/28 22:15:51 sommerb Exp $ |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# See license and copyright near the end of this file. |
7
|
|
|
|
|
|
|
############################################################################### |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Myco::Core::Person - Myco Person objects. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=item Release |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
1.0 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = 1.0; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Myco; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Constructors. See Myco::Entity for more. |
26
|
|
|
|
|
|
|
my $p = Myco::Core::Person->new; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Name. |
29
|
|
|
|
|
|
|
my $last = $p->get_last; |
30
|
|
|
|
|
|
|
$p = $p->set_last($last); |
31
|
|
|
|
|
|
|
my $first = $p->get_first; |
32
|
|
|
|
|
|
|
$p = $p->set_first($first); |
33
|
|
|
|
|
|
|
my $middle = $p->get_middle; |
34
|
|
|
|
|
|
|
$p = $p->set_middle($middle); |
35
|
|
|
|
|
|
|
my $prefix = $p->get_prefix; |
36
|
|
|
|
|
|
|
$p = $p->set_prefix($prefix); |
37
|
|
|
|
|
|
|
my $suffix = $p->get_suffix; |
38
|
|
|
|
|
|
|
$p = $p->set_suffix($suffix); |
39
|
|
|
|
|
|
|
my $nick = $p->get_nick; |
40
|
|
|
|
|
|
|
$p = $p->set_nick($nick); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Vital Stats. |
43
|
|
|
|
|
|
|
my $gender = $p->get_gender; |
44
|
|
|
|
|
|
|
$p = $p->set_gender($gender); |
45
|
|
|
|
|
|
|
my $birthdate = $p->get_birthdate; |
46
|
|
|
|
|
|
|
$p = $p->set_birthdate($birthdate); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Added instance methods. |
49
|
|
|
|
|
|
|
my $format = "%p% f% M% l%, s"; |
50
|
|
|
|
|
|
|
my $name = $p->strfname($format); |
51
|
|
|
|
|
|
|
my $uidf = $p->get_unique_id_fmt; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Persistence methods. |
54
|
|
|
|
|
|
|
$p->save; |
55
|
|
|
|
|
|
|
$p->destroy; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 DESCRIPTION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
This class represents what may well be the central object of any Myco-based |
60
|
|
|
|
|
|
|
application: the Person. Myco::Core::Person provides the absolute bare bones |
61
|
|
|
|
|
|
|
skeleton of what most applications will need in a person object. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
############################################################################## |
66
|
|
|
|
|
|
|
# Dependencies |
67
|
|
|
|
|
|
|
############################################################################## |
68
|
|
|
|
|
|
|
# Module Dependencies and Compiler Pragma |
69
|
1
|
|
|
1
|
|
6773
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
51
|
|
70
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
71
|
1
|
|
|
1
|
|
3520
|
use Myco::Exceptions; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
############################################################################## |
74
|
|
|
|
|
|
|
# Programmatic Dependencies |
75
|
|
|
|
|
|
|
use Lingua::Strfname (); |
76
|
|
|
|
|
|
|
use Myco::Util::Strings; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
############################################################################## |
79
|
|
|
|
|
|
|
# Inheritance & Introspection |
80
|
|
|
|
|
|
|
############################################################################## |
81
|
|
|
|
|
|
|
use lib '/usr/home/sommerb/dev/myco/lib'; |
82
|
|
|
|
|
|
|
use base qw(Myco::Entity); |
83
|
|
|
|
|
|
|
my $md = Myco::Entity::Meta->new |
84
|
|
|
|
|
|
|
( name => __PACKAGE__, |
85
|
|
|
|
|
|
|
tangram => { table => 'myco_core_person' }, |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
############################################################################## |
89
|
|
|
|
|
|
|
# Function and Closure Prototypes |
90
|
|
|
|
|
|
|
############################################################################## |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# Use this code reference to validate the Unique ID. |
93
|
|
|
|
|
|
|
my $chk_uid = sub { |
94
|
|
|
|
|
|
|
Myco::Exception::DataValidation->throw |
95
|
|
|
|
|
|
|
(error => "id must be of form ####-####-# (dashes optional)") |
96
|
|
|
|
|
|
|
unless defined ${$_[0]} and ${$_[0]} =~ /^\d{9}$/; |
97
|
|
|
|
|
|
|
}; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
############################################################################## |
100
|
|
|
|
|
|
|
# Queries - this is delayed to avoid compile loops |
101
|
|
|
|
|
|
|
############################################################################## |
102
|
|
|
|
|
|
|
my $queries = sub { |
103
|
|
|
|
|
|
|
my $md = shift; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$md->add_query( name => 'default', |
106
|
|
|
|
|
|
|
remotes => { '$p_' => 'Myco::Core::Person', }, |
107
|
|
|
|
|
|
|
result_remote => '$p_', |
108
|
|
|
|
|
|
|
params => { last => [ qw($p_ last) ], }, |
109
|
|
|
|
|
|
|
filter => { |
110
|
|
|
|
|
|
|
parts => [ { remote => '$p_', |
111
|
|
|
|
|
|
|
attr => 'last', |
112
|
|
|
|
|
|
|
oper => 'eq', |
113
|
|
|
|
|
|
|
param => 'last' }, |
114
|
|
|
|
|
|
|
] }, |
115
|
|
|
|
|
|
|
); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
}; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
############################################################################## |
120
|
|
|
|
|
|
|
# Constructor, etc. |
121
|
|
|
|
|
|
|
############################################################################## |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 COMMON ENTITY INTERFACE |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Constructor, accessors, and other methods -- as inherited from Myco::Entity. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
############################################################################## |
130
|
|
|
|
|
|
|
# Attributes & Attribute Accessors / Schema Definition |
131
|
|
|
|
|
|
|
############################################################################## |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Attributes may be initially set during object construction (with C) but |
136
|
|
|
|
|
|
|
otherwise should be accessed solely through accessor methods. Typical usage: |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=over 3 |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Set attribute value |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
$p->set_attribute($value); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Check functions (see L) perform data |
147
|
|
|
|
|
|
|
validation. If there is any concern that the set method might be called with |
148
|
|
|
|
|
|
|
invalid data then the call should be wrapped in an C block to catch |
149
|
|
|
|
|
|
|
exceptions that would result. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item * |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Get attribute value |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
$value = $p->get_attribute; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=back |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
A listing of available attributes follows: |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=cut |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 last |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
type: string(64) required: not empty |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
The personE<39>s last name. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
$md->add_attribute( name => 'last', |
172
|
|
|
|
|
|
|
type => 'string', |
173
|
|
|
|
|
|
|
type_options => { string_length => 64 }, |
174
|
|
|
|
|
|
|
synopsis => 'Last Name', |
175
|
|
|
|
|
|
|
tangram_options => { required => 1 }, |
176
|
|
|
|
|
|
|
); |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 first |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
type: string(64) |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
The personE<39>s first name. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
$md->add_attribute(name => 'first', |
188
|
|
|
|
|
|
|
type => 'string', |
189
|
|
|
|
|
|
|
type_options => { string_length => 64 }, |
190
|
|
|
|
|
|
|
synopsis => 'First Name', |
191
|
|
|
|
|
|
|
); |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 middle |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
type: string(64) |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
The personE<39>s middle name. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=cut |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
$md->add_attribute(name => 'middle', |
203
|
|
|
|
|
|
|
type => 'string', |
204
|
|
|
|
|
|
|
type_options => { string_length => 64 }, |
205
|
|
|
|
|
|
|
synopsis => 'Middle Name', |
206
|
|
|
|
|
|
|
); |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head2 prefix |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
type: string(32) |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
The prefix to the personE<39>s name. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=cut |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
$md->add_attribute(name => 'prefix', |
217
|
|
|
|
|
|
|
type => 'string', |
218
|
|
|
|
|
|
|
type_options => { string_length => 32 }, |
219
|
|
|
|
|
|
|
synopsis => 'Prefix', |
220
|
|
|
|
|
|
|
values => [ qw( __select__ Ms. Miss Mrs. Mr. __other__ )], |
221
|
|
|
|
|
|
|
); |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head2 suffix |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
type: string(32) |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
The suffix to the personE<39>s name. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=cut |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
$md->add_attribute(name => 'suffix', |
232
|
|
|
|
|
|
|
type => 'string', |
233
|
|
|
|
|
|
|
type_options => { string_length => 32 }, |
234
|
|
|
|
|
|
|
synopsis => 'Suffix', |
235
|
|
|
|
|
|
|
values => [ qw( __select__ Jr. Sr. M.D. PhD. __other__ )], |
236
|
|
|
|
|
|
|
); |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head2 nick |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
type: string(64) |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
The personE<39>s nick name. |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=cut |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
$md->add_attribute(name => 'nick', |
247
|
|
|
|
|
|
|
type => 'string', |
248
|
|
|
|
|
|
|
type_options => { string_length => 64 }, |
249
|
|
|
|
|
|
|
synopsis => 'Nick Name', |
250
|
|
|
|
|
|
|
); |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head2 birthdate |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
type: rawdate |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
The personE<39>s birthday. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=cut |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
$md->add_attribute( name => 'birthdate', |
261
|
|
|
|
|
|
|
syntax_msg => 'YYYY-MM-DD (dashes optional)', |
262
|
|
|
|
|
|
|
type => 'rawdate', |
263
|
|
|
|
|
|
|
ui => { label => 'Birth Date' }, |
264
|
|
|
|
|
|
|
); |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
############################################################################## |
268
|
|
|
|
|
|
|
# Methods |
269
|
|
|
|
|
|
|
############################################################################## |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=head1 ADDED CLASS / INSTANCE METHODS |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=head2 strfname |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
my $format = "%p% f% M% l%, s"; |
276
|
|
|
|
|
|
|
my $name = $person->strfname($format); |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
This method allows the parts of the personE<39>s name to be formatted according |
279
|
|
|
|
|
|
|
to the strfname formatting template syntax. See |
280
|
|
|
|
|
|
|
L for the details of the formatting |
281
|
|
|
|
|
|
|
syntax. Note that the only difference here is that the "first extra name" is |
282
|
|
|
|
|
|
|
always the personE<39>s nick name. Thus, the formatting characters are as |
283
|
|
|
|
|
|
|
follows: |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
%l Last Name |
286
|
|
|
|
|
|
|
%f First Name |
287
|
|
|
|
|
|
|
%m Middle Name |
288
|
|
|
|
|
|
|
%p Prefix |
289
|
|
|
|
|
|
|
%s Suffix |
290
|
|
|
|
|
|
|
%a Nick Name |
291
|
|
|
|
|
|
|
%L Last Name Initial with period |
292
|
|
|
|
|
|
|
%F First Name Initial with period |
293
|
|
|
|
|
|
|
%M Middle Name Initial with period |
294
|
|
|
|
|
|
|
%A Nick Name Initial with period |
295
|
|
|
|
|
|
|
%T Last Name Initial |
296
|
|
|
|
|
|
|
%S First Name Initial |
297
|
|
|
|
|
|
|
%I Middle Name Initial |
298
|
|
|
|
|
|
|
%1 Nick Name Initial |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=cut |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
sub strfname { |
303
|
|
|
|
|
|
|
Lingua::Strfname::strfname($_[1], |
304
|
|
|
|
|
|
|
@{$_[0]}{qw(last first middle prefix suffix nick)}) |
305
|
|
|
|
|
|
|
} |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
############################################################################## |
308
|
|
|
|
|
|
|
# Object Schema Activation and Metadata Finalization |
309
|
|
|
|
|
|
|
############################################################################## |
310
|
|
|
|
|
|
|
$md->activate_class( queries => $queries ); |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
1; |
313
|
|
|
|
|
|
|
__END__ |