Vehicle/Status.pm

filter: Statementstmt 22.2% 18 / 81 Branchbran 0.0% 0 / 40 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 37.5% 6 / 16 Podpod 0.0% 0 / 1 totaltotal 17.3% 24 / 138 CC 21 SCAR 26.5
CC
21
Cov
15%
BUILD
42.0
dateOfLastV5CIssued
12.0
markedForExport
12.0
CRAP 14.2
↑ Summary Vehicle.pm »
1 package UK::Vehicle::Status;
2  
3 3 ▶use 5.030000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use subs qw(dateOfLastV5CIssued manufacturer markedForExport monthOfFirstRegistration motExpiryDate vrm taxDueDate yearOfManufacture wheelPlan);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 use Class::Tiny qw(result message co2Emissions colour dateOfLastV5CIssued engineCapacity euroStatus fuelType make manufacturer markedForExport monthOfFirstRegistration
8 3 ▶ motExpiryDate motStatus registrationNumber vrm revenueWeight taxDueDate taxStatus typeApproval wheelplan wheelPlan yearOfManufacture);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 SEE ALSO
13  
14 See L<UK::Vehicle> for usage information.
15  
16 =head1 METHODS
17  
18 =over 3
19  
20 =item result()
21  
22 Whether the query against the VES API for information on the vehicle
23 was successful. If it wasn't, more information is available using the
24 method B<message>().
25  
26 Returns 1 if successful, 0 otherwise. Successful means a record for the
27 vehicle was found and returned.
28  
29 =item message()
30  
31 More information on the success of the query that returned this result.
32 For information on possible responses see L<here|https://developer-portal.driver-vehicle-licensing.api.gov.uk/apis/vehicle-enquiry-service/v1.1.0-vehicle-enquiry-service.html#getvehicledetailsbyregistrationnumber-responses>
33  
34 =item co2Emissions()
35  
36 The registered CO2 emissions in grammes per km.
37  
38 Returns an integer.
39  
40 =item colour()
41  
42 The registered colour of the vehicle.
43  
44 Returns a string.
45  
46 =cut
47  
48 sub BUILD
49 {
50 0 ▶ my ($self, $args) = @_;
Subroutine BUILD: not called CC=6 SCAR=37.4
Pod undocumented
51  
52 0 ▶ $self->dateOfLastV5CIssued($args->{'dateOfLastV5CIssued'}) if($args->{'dateOfLastV5CIssued'});
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"dateOfLastV5CIssued"} 0 0 0
53 0 ▶ $self->monthOfFirstRegistration($args->{'monthOfFirstRegistration'}) if($args->{'monthOfFirstRegistration'});
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"monthOfFirstRegistration"} 0 0 0
54 0 ▶ $self->taxDueDate($args->{'taxDueDate'}) if($args->{'taxDueDate'});
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"taxDueDate"} 0 0 0
55 0 ▶ $self->yearOfManufacture($args->{'yearOfManufacture'}) if($args->{'yearOfManufacture'});
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"yearOfManufacture"} 0 0 0
56 0 ▶ $self->motExpiryDate($args->{'motExpiryDate'}) if($args->{'motExpiryDate'});
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"motExpiryDate"} 0 0 0
57 }
58  
59  
60 =pod
61  
62 =item dateOfLastV5CIssued()
63  
64 The date the most recent V5 was issued, to the day. This can be helpful in
65 determining when it was most revently registered to a new keeper, and
66 whether the V5 you have in front of you is the current one.
67  
68 Returns a L<DateTime> object. The time portion of this object will be
69 set to to 00:00:00, and the timezone "Europe/London."
70  
71 =cut
72  
73 sub dateOfLastV5CIssued
74 {
75 0 ▶ my $self = shift;
Subroutine dateOfLastV5CIssued: not called CC=3 SCAR=24.8
76 0 my $newval = shift;
77
78 0 ▶ if($newval)
Branch: 1 branch
BranchTrueFalseTotal
if ($newval) 0 0 0
79 {
80 0 ▶ if(ref($newval) eq "DateTime")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $newval eq 'DateTime') { } 0 0 0
81 {
82 0 $self->{'dateOfLastV5CIssued'} = $newval;
83 }
84 else
85 { # Assume YYYY-MM-DD as per data returned by the VES API
86 0 $self->{'dateOfLastV5CIssued'} = DateTime->new(year => substr($newval, 0, 4), month => substr($newval, 5, 2), day => substr($newval, 8, 2), time_zone => 'Europe/London');
87 }
88 }
89 0 return $self->{'dateOfLastV5CIssued'};
90 }
91  
92 =pod
93  
94 =item engineCapacity()
95  
96 The engine capacity of any combustion engine fitted in cc. Should be
97 undef for electric vehicles.
98  
99 Returns an integer.
100  
101 =item euroStatus()
102  
103 The relevant european emissions standard with which the vehicle complies.
104  
105 Returns a string.
106  
107 =item fuelType()
108  
109 The type of fuel the vehicle uses. he API documentation doesn't
110 list this as an enumerated value, so presumably they don't know what's
111 coming over the next ten years and are leaving flexible. Plan for
112 anything! If you've seen other values let me know and I'll add it to
113 the list. Some values currently in use are:
114  
115 - "PETROL"
116 - "DIESEL"
117 - "HYBRID ELECTRIC"
118 - "ELECTRICITY"
119
120 Returns a string containing god knows what.
121  
122 =item make()
123  
124 =item manufacturer()
125  
126 The registered manufacturer name of the vehicle.
127  
128 Returns a string.
129  
130 =cut
131  
132 # Alias for make
133 sub manufacturer
134 {
135 0 ▶ my $self = shift;
Subroutine manufacturer: not called CC=2 SCAR=17.9
136 0 my $newval = shift;
137
138 0 ▶ if($newval)
Branch: 1 branch
BranchTrueFalseTotal
if ($newval) 0 0 0
139 {
140 0 $self->make($newval);
141 }
142
143 0 return $self->make;
144 }
145  
146 =pod
147  
148 =item markedForExport()
149  
150 Whether or not this vehicle has been marked for export - this means
151 someone has notified the DVLA of their intention to export it. The
152 vehicle is no longer registered in the UK and cannot be taxed, nor can
153 a V5 be issued for it. It can be MOT tested.
154  
155 No information is available as to whether the vehicle has actually been
156 exported.
157  
158 Returns 1 if marked for export, 0 otherwise.
159  
160 =cut
161  
162 sub markedForExport
163 {
164 0 ▶ my $self = shift;
Subroutine markedForExport: not called CC=3 SCAR=24.8
165 0 my $newval = shift;
166
167 0 ▶ if($newval)
Branch: 1 branch
BranchTrueFalseTotal
if ($newval) 0 0 0
168 {
169 0 $self->{'markedForExport'} = $newval;
170 }
171
172 0 ▶ if($self->{'markedForExport'}) { return 1 }; # Looks pointless but converts JSON::PP::Boolean into 1 or 0
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"markedForExport"}) 0 0 0
173 0 return 0;
174 }
175  
176 =pod
177  
178 =item monthOfFirstRegistration()
179  
180 The month in which the vehicle was first registered with the DVLA. This
181 is not likely to be the month in which it was manufactured.
182  
183 Returns a L<DateTime> object. The day portion of this object will be set
184 to the first day of the month, the time portion of this object will be
185 set to to 00:00:00, and the timezone "Europe/London."
186  
187 =cut
188  
189 sub monthOfFirstRegistration
190 {
191 0 ▶ my $self = shift;
Subroutine monthOfFirstRegistration: not called CC=3 SCAR=24.8
192 0 my $newval = shift;
193
194 0 ▶ if($newval)
Branch: 1 branch
BranchTrueFalseTotal
if ($newval) 0 0 0
195 {
196 0 ▶ if(ref($newval) eq "DateTime")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $newval eq 'DateTime') { } 0 0 0
197 {
198 0 $self->{'monthOfFirstRegistration'} = $newval;
199 }
200 else
201 { # Assume YYYY-MM-DD as per data returned by the VES API
202 0 $self->{'monthOfFirstRegistration'} = DateTime->new(year => substr($newval, 0, 4), month => substr($newval, 5, 2), time_zone => 'Europe/London');
203 }
204 }
205 0 return $self->{'monthOfFirstRegistration'};
206 }
207  
208 =pod
209  
210 =item motExpiryDate()
211  
212 The date the current MoT expires, to the day.
213  
214 Returns a L<DateTime> object. The time portion of this object will be
215 set to to 00:00:00, and the timezone "Europe/London." Returns undef if
216 no MoT has been done.
217  
218 =cut
219  
220 sub motExpiryDate
221 {
222 0 ▶ my $self = shift;
Subroutine motExpiryDate: not called CC=3 SCAR=24.8
223 0 my $newval = shift;
224
225 0 ▶ if($newval)
Branch: 1 branch
BranchTrueFalseTotal
if ($newval) 0 0 0
226 {
227 0 ▶ if(ref($newval) eq "DateTime")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $newval eq 'DateTime') { } 0 0 0
228 {
229 0 $self->{'motExpiryDate'} = $newval;
230 }
231 else
232 { # Assume YYYY-MM-DD as per data returned by the VES API
233 0 $self->{'motExpiryDate'} = DateTime->new(year => substr($newval, 0, 4), month => substr($newval, 5, 2), day => substr($newval, 8, 2), time_zone => 'Europe/London');
234 }
235 }
236 0 return $self->{'motExpiryDate'};
237 }
238  
239 =pod
240  
241 =item motStatus()
242  
243 A string representing the vehicle's mot test status.
244  
245 Returns a string with one of these values:
246 - "No details held by DVLA"
247 - "No results returned" (don't know the difference)
248 - "Not valid" (last MoT pass has expired)
249 - "Valid" (last MoT pass has not expired)
250  
251 =item registrationNumber
252  
253 =item vrm
254  
255 The VRM of the vehicle for which the status information was returned.
256 This ought to match the VRM you asked for, with any spaces removed.
257  
258 Returns a string.
259  
260 =cut
261  
262 # Alias for registrationNumber
263 sub vrm
264 {
265 0 ▶ my $self = shift;
Subroutine vrm: not called CC=2 SCAR=17.9
266 0 my $newval = shift;
267
268 0 ▶ if($newval)
Branch: 1 branch
BranchTrueFalseTotal
if ($newval) 0 0 0
269 {
270 0 $self->registrationNumber($newval);
271 }
272
273 0 return $self->registrationNumber;
274 }
275  
276 =pod
277  
278 =item revenueWeight()
279  
280 The registered "plated gross weight" for the vehicle in kg. See L<The Vehicle
281 Excise and Registration Act 1994|https://www.legislation.gov.uk/ukpga/1994/22/section/60A#:~:text=%5BF160A%20Meaning%20of%20%E2%80%9Crevenue%20weight%E2%80%9D.&text=(b)in%20the%20case%20of,travelling%20on%20a%20road%20laden.>
282 for more.
283  
284 Returns an integer.
285  
286 =item taxDueDate()
287  
288 The date the road tax is next due to be paid; this does not take into
289 account the payment method. Even if the keeper signed up to pay monthly
290 by direct debit it will show a date up to 12 months in the future when
291 compared to now().
292
293 Returns a L<DateTime> object. The time portion of this object will be
294 set to to 00:00:00, and the timezone "Europe/London."
295  
296 =cut
297  
298 sub taxDueDate
299 {
300 0 ▶ my $self = shift;
Subroutine taxDueDate: not called CC=3 SCAR=24.8
301 0 my $newval = shift;
302
303 0 ▶ if($newval)
Branch: 1 branch
BranchTrueFalseTotal
if ($newval) 0 0 0
304 {
305 0 ▶ if(ref($newval) eq "DateTime")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $newval eq 'DateTime') { } 0 0 0
306 {
307 0 $self->{'taxDueDate'} = $newval;
308 }
309 else
310 { # Assume YYYY-MM-DD as per data returned by the VES API
311 0 $self->{'taxDueDate'} = DateTime->new(year => substr($newval, 0, 4), month => substr($newval, 5, 2), day => substr($newval, 8, 2), time_zone => 'Europe/London');
312 }
313 }
314 0 return $self->{'taxDueDate'};
315 }
316  
317 =item taxStatus()
318  
319 A string representing the vehicle's tax status.
320  
321 Returns a string with one of these value:
322 - "Not Taxed for on Road Use" (farm vehicle etc.?)
323 - "SORN"
324 - "Taxed" (last MoT pass has expired)
325 - "Untaxed"
326  
327 =item typeApproval()
328  
329 The registered type approval category for the vehicle. You can infer
330 some things about the type of vehicle from this; see the
331 L<Vehicle Certification Agency's website|https://www.vehicle-certification-agency.gov.uk/vehicle-type-approval/classification-of-power-driven-vehicles-and-trailers/>
332 for a list of the categories.
333  
334 Returns a 2-character string.
335  
336 =item wheelplan()
337 =item wheelPlan()
338  
339 A description of the number of axles and sometimes the nature of the
340 body of the vehicle.
341  
342 Returns a string containing god knows what.
343  
344 =cut
345  
346 # Alias for wheelplan
347 sub wheelPlan
348 {
349 0 ▶ my $self = shift;
Subroutine wheelPlan: not called CC=2 SCAR=17.9
350 0 my $newval = shift;
351
352 0 ▶ if($newval)
Branch: 1 branch
BranchTrueFalseTotal
if ($newval) 0 0 0
353 {
354 0 $self->wheelplan($newval);
355 }
356
357 0 return $self->wheelplan;
358 }
359  
360 =pod
361  
362 =item yearOfManufacture()
363  
364 The month in which the vehicle was manufactured.
365  
366 Returns a L<DateTime> object. The month portion of this object will be
367 set to the first month of the year, the day portion of this object will
368 be set to the first day of the month, the time portion of this object
369 will be set to to 00:00:00, and the timezone "Europe/London."
370  
371 =cut
372  
373 sub yearOfManufacture
374 {
375 0 ▶ my $self = shift;
Subroutine yearOfManufacture: not called CC=3 SCAR=24.8
376 0 my $newval = shift;
377
378 0 ▶ if($newval)
Branch: 1 branch
BranchTrueFalseTotal
if ($newval) 0 0 0
379 {
380 0 ▶ if(ref($newval) eq "DateTime")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $newval eq 'DateTime') { } 0 0 0
381 {
382 0 $self->{'yearOfManufacture'} = $newval;
383 }
384 else
385 { # Assume year as a number as per data returned by the VES API
386 0 $self->{'yearOfManufacture'} = DateTime->new(year => $newval, time_zone => 'Europe/London');
387 }
388 }
389 0 return $self->{'yearOfManufacture'};
390 }
391  
392 3 1;
393 __END__
394  
395  
396 #~ =item is_mot_current()
397  
398 #~ $status->is_mot_current();
399 #~ # returns 1 if there is a current, valid MOT. 0 otherwise.
400
401 #~ This method looks at the property motExpiryDate, and then checks
402 #~ whether it is currently "valid". "Valid" means the following is true:
403 #~ =over 6
404 #~ =item * The last MoT test result was a pass
405 #~ =item * The current time in the timezone Europe/London is not
406 #~ later than 23:59:59.000 on the expiry date.
407 #~ =back
408 #~ B<Yes>, as soon as vehicle fails an MoT, it no longer has a current
409 #~ valid MoT even if it not yet one year after the last pass, and you
410 #~ cannot legally drive it except under the limited circumstances provided
411 #~ for in the relevant law. B<Yes>, your MoT expires right at the very end
412 #~ of the expiry date so you can drive it right up to midnight on that day.
413  
414 #~ =item is_tax_current()
415  
416 #~ $status->is_tax_current();
417 #~ # returns 1 if the vehicle is taxed and can be on the road. 0
418 #~ otherwise
419
420 #~ This method looks at the property taxStatus, and then checks if it is
421 #~ "Taxed". Any status other than this, whether SORNd or untaxed, will
422 #~ return 0.
423  
424 #~ This method will croak if you have not yet called get().
425  
426 #~ =item is_sorn_declared()
427  
428 #~ $status->is_sorn_declared();
429 #~ # returns 1 if a SORN has been made for the vehicle. 0 otherwise.
430  
431 #~ This method looks at the property taxStatus, and then checks if it is
432 #~ "SORN". Any status other than this, whether taxed or untaxed, will
433 #~ return 0.
434  
435 #~ This method will croak if you have not yet called get().
436
437 =back
438  
439 =head1 BUGS AND REQUESTS
440  
441 Please report to L<the GitHub repository|https://https://github.com/realflash/perl-mot-history>
442  
443 =head1 AUTHOR
444  
445 Ian Gibbs, E<lt>igibbs@cpan.orgE<gt>
446  
447 =head1 COPYRIGHT AND LICENSE
448  
449 Copyright (C) 2022 by Ian Gibbs
450  
451 This library is free software; you can redistribute it and/or modify
452 it under the terms of the GNU GPL version 3.
453  
454 =cut
↑ Summary Vehicle.pm »