Schema/Result/Address.pm

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