line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
1203
|
use utf8; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
14
|
|
2
|
|
|
|
|
|
|
package Interchange6::Schema::Result::Address; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
Interchange6::Schema::Result::Address |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=cut |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
|
|
20
|
use Interchange6::Schema::Candy -components => |
11
|
2
|
|
|
2
|
|
131
|
[qw(InflateColumn::DateTime TimeStamp)]; |
|
2
|
|
|
|
|
6
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
6854
|
use Class::Method::Modifiers; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
188
|
|
14
|
2
|
|
|
2
|
|
21
|
use Try::Tiny; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
1338
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
The Address class is used to store any kind of address such as billing, |
19
|
|
|
|
|
|
|
delivery, etc along with company and individual names if needed. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 ACCESSORS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 addresses_id |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Primary key. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
primary_column addresses_id => { |
30
|
|
|
|
|
|
|
data_type => "integer", |
31
|
|
|
|
|
|
|
is_auto_increment => 1, |
32
|
|
|
|
|
|
|
sequence => "addresses_addresses_id_seq", |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 users_id |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Foreign key constraint on L<Interchange6::Schema::Result::User/users_id> |
38
|
|
|
|
|
|
|
via L</user> relationship. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
column users_id => { |
43
|
|
|
|
|
|
|
data_type => "integer", |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 type |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Address L</type> for such things as "billing" or "shipping". Defaults to |
49
|
|
|
|
|
|
|
empty string. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
column type => { |
54
|
|
|
|
|
|
|
data_type => "varchar", |
55
|
|
|
|
|
|
|
default_value => "", |
56
|
|
|
|
|
|
|
size => 16, |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 archived |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Boolean indicating that address has been archived and so should no longer |
62
|
|
|
|
|
|
|
appear in normal address listings. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
column archived => { |
67
|
|
|
|
|
|
|
data_type => "boolean", |
68
|
|
|
|
|
|
|
default_value => 0, |
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 first_name |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
First name of person associated with address. Defaults to empty string. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
column first_name => { |
78
|
|
|
|
|
|
|
data_type => "varchar", |
79
|
|
|
|
|
|
|
default_value => "", |
80
|
|
|
|
|
|
|
size => 255, |
81
|
|
|
|
|
|
|
}; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 last_name |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Last name of person associated with address. Defaults to empty string. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
column last_name => { |
90
|
|
|
|
|
|
|
data_type => "varchar", |
91
|
|
|
|
|
|
|
default_value => "", |
92
|
|
|
|
|
|
|
size => 255, |
93
|
|
|
|
|
|
|
}; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 company |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Company name associated with address. Defaults to empty string. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
column company => { |
102
|
|
|
|
|
|
|
data_type => "varchar", |
103
|
|
|
|
|
|
|
default_value => "", |
104
|
|
|
|
|
|
|
size => 255, |
105
|
|
|
|
|
|
|
}; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 address |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
First line of address. Defaults to empty string. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
column address => { |
114
|
|
|
|
|
|
|
data_type => "varchar", |
115
|
|
|
|
|
|
|
default_value => "", |
116
|
|
|
|
|
|
|
size => 255, |
117
|
|
|
|
|
|
|
}; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 address_2 |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Second line of address. Defaults to empty string. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
column address_2 => { |
126
|
|
|
|
|
|
|
data_type => "varchar", |
127
|
|
|
|
|
|
|
default_value => "", |
128
|
|
|
|
|
|
|
size => 255, |
129
|
|
|
|
|
|
|
}; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 postal_code |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Postal/zip code. Defaults to empty string. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
column postal_code => { |
138
|
|
|
|
|
|
|
data_type => "varchar", |
139
|
|
|
|
|
|
|
default_value => "", |
140
|
|
|
|
|
|
|
size => 255, |
141
|
|
|
|
|
|
|
}; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 city |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
City/town name. Defaults to empty string. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
column city => { |
150
|
|
|
|
|
|
|
data_type => "varchar", |
151
|
|
|
|
|
|
|
default_value => "", |
152
|
|
|
|
|
|
|
size => 255, |
153
|
|
|
|
|
|
|
}; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 phone |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Telephone number. Defaults to empty string. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
column phone => { |
162
|
|
|
|
|
|
|
data_type => "varchar", |
163
|
|
|
|
|
|
|
default_value => "", |
164
|
|
|
|
|
|
|
size => 32, |
165
|
|
|
|
|
|
|
}; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 states_id |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Foreign key constraint on L<Interchange6::Schema::Result::State/states_id> |
170
|
|
|
|
|
|
|
via L</state> relationship. NULL values are allowed. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=cut |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
column states_id => { |
175
|
|
|
|
|
|
|
data_type => "integer", |
176
|
|
|
|
|
|
|
is_nullable => 1, |
177
|
|
|
|
|
|
|
}; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 country_iso_code |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Two character country ISO code. Foreign key constraint on |
182
|
|
|
|
|
|
|
L<Interchange6::Schema::Result::Country/country_iso_code> via L</country> |
183
|
|
|
|
|
|
|
relationship. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
column country_iso_code => { |
188
|
|
|
|
|
|
|
data_type => "char", |
189
|
|
|
|
|
|
|
size => 2, |
190
|
|
|
|
|
|
|
}; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head2 priority |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Signed integer priority. We normally order descending. A simple use might |
195
|
|
|
|
|
|
|
be to set default address to 1 and others to 0. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Defaults to 0. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
column priority => { data_type => "integer", default_value => 0 }; |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head2 created |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Date and time when this record was created returned as L<DateTime> object. |
206
|
|
|
|
|
|
|
Value is auto-set on insert. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
column created => { |
211
|
|
|
|
|
|
|
data_type => "datetime", |
212
|
|
|
|
|
|
|
set_on_create => 1, |
213
|
|
|
|
|
|
|
}; |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head2 last_modified |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Date and time when this record was last modified returned as L<DateTime> object. |
218
|
|
|
|
|
|
|
Value is auto-set on insert and update. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=cut |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
column last_modified => { |
223
|
|
|
|
|
|
|
data_type => "datetime", |
224
|
|
|
|
|
|
|
set_on_create => 1, |
225
|
|
|
|
|
|
|
set_on_update => 1, |
226
|
|
|
|
|
|
|
}; |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 RELATIONS |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head2 orderlines_shipping |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Type: has_many |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Related object: L<Interchange6::Schema::Result::OrderlinesShipping> |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=cut |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
has_many |
239
|
|
|
|
|
|
|
orderlines_shipping => "Interchange6::Schema::Result::OrderlinesShipping", |
240
|
|
|
|
|
|
|
{ "foreign.addresses_id" => "self.addresses_id" }, |
241
|
|
|
|
|
|
|
{ cascade_copy => 0, cascade_delete => 0 }; |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head2 orders |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Type: has_many |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Related object: L<Interchange6::Schema::Result::Order> |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=cut |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
has_many |
252
|
|
|
|
|
|
|
orders => "Interchange6::Schema::Result::Order", |
253
|
|
|
|
|
|
|
{ "foreign.billing_addresses_id" => "self.addresses_id" }, |
254
|
|
|
|
|
|
|
{ cascade_copy => 0, cascade_delete => 0 }; |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head2 user |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Type: belongs_to |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
Related object: L<Interchange6::Schema::Result::User> |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=cut |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
belongs_to |
265
|
|
|
|
|
|
|
user => "Interchange6::Schema::Result::User", |
266
|
|
|
|
|
|
|
{ users_id => "users_id" }, |
267
|
|
|
|
|
|
|
{ is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }; |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=head2 state |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
Type: belongs_to |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
Related object: L<Interchange6::Schema::Result::State> |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=cut |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
belongs_to |
278
|
|
|
|
|
|
|
state => "Interchange6::Schema::Result::State", |
279
|
|
|
|
|
|
|
{ states_id => "states_id" }, |
280
|
|
|
|
|
|
|
{ join_type => 'left', is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }; |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=head2 country |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
Type: belongs_to |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
Related object: L<Interchange6::Schema::Result::Country> |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=cut |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
belongs_to |
291
|
|
|
|
|
|
|
country => "Interchange6::Schema::Result::Country", |
292
|
|
|
|
|
|
|
"country_iso_code", |
293
|
|
|
|
|
|
|
{ is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }; |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=head2 orderlines |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
Type: many_to_many |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
Composing rels: L</orderlines_shipping> -> orderline |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=cut |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
many_to_many orderlines => "orderlines_shipping", "orderline"; |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=head1 METHODS |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=head2 delete |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
If an address cannot be deleted due to foreign key constraints (perhaps |
310
|
|
|
|
|
|
|
it has L</orders> or L</orderlines_shipping>) then instead of deleting the |
311
|
|
|
|
|
|
|
row set L</archived> to true. |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=cut |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
# we can't use next::method since we do the delete inside try{} and that messes |
316
|
|
|
|
|
|
|
# up callers so instead we use Class::Method::Modifiers::around |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
around delete => sub { |
319
|
|
|
|
|
|
|
my ( $orig, $self ) = @_; |
320
|
|
|
|
|
|
|
try { |
321
|
|
|
|
|
|
|
$self->$orig(@_); |
322
|
|
|
|
|
|
|
} |
323
|
|
|
|
|
|
|
catch { |
324
|
|
|
|
|
|
|
my $original_error = $_; |
325
|
|
|
|
|
|
|
try { |
326
|
|
|
|
|
|
|
$self->update({archived => 1}); |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
catch { |
329
|
|
|
|
|
|
|
$self->result_source->schema->throw_exception($original_error); |
330
|
|
|
|
|
|
|
}; |
331
|
|
|
|
|
|
|
}; |
332
|
|
|
|
|
|
|
}; |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
1; |