Shipment/Base.pm

filter: Statementstmt 60.8% 76 / 125 Branchbran 5.0% 1 / 20 Conditioncond 18.1% 2 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 56.6% 17 / 30 Podpod 100% 7 / 7 totaltotal 51.5% 103 / 200 CC 17 SCAR 23.6
CC
17
Cov
51%
coerce_datetime
45.0
__ANON__
6.0
__ANON__
6.0
CRAP 10.6
« Shipment/Purolator/WSDL/Interfaces/ServiceAvailabilityService/ServiceAvailabilityServiceEndpoint.pm ↑ Summary Shipment/Purolator/WSDL/Interfaces/ShippingService/ShippingServiceEndpoint.pm »
1 package Shipment::Base;
2 12 $Shipment::Base::VERSION = '3.11';
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 12 ▶use Data::Currency;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use Shipment::Service;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 12 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 12 ▶use MooX::Aliases;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 12 ▶use MooX::HandlesVia;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 12 ▶use MooX::Types::MooseLike qw(exception_message);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 12 ▶use MooX::Types::MooseLike::Base qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 12 ▶use MooX::Types::MooseLike::DateTime qw( DateAndTime );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 12 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 12 has 'from_address' => (
22 is => 'rw',
23 isa => InstanceOf ['Shipment::Address'],
24 );
25  
26 12 has 'to_address' => (
27 is => 'rw',
28 isa => InstanceOf ['Shipment::Address'],
29 );
30  
31  
32 12 has 'account' => (
33 is => 'rw',
34 isa => Str,
35 );
36  
37  
38 12 has 'bill_account' => (
39 is => 'rw',
40 isa => Str,
41 lazy => 1,
42 builder => 1,
43 );
44  
45 0 ▶sub _build_bill_account {
Subroutine _build_bill_account: not called CC=1 SCAR=6.9
46 0 return shift->account;
47 }
48  
49  
50 12 has 'bill_address' => (
51 is => 'rw',
52 isa => InstanceOf ['Shipment::Address'],
53 );
54  
55  
56 12 has 'bill_type' => (
57 is => 'rw',
58 isa => Enum [qw( sender recipient third_party )],
59 default => 'sender',
60 );
61  
62  
63 12 has 'pickup_type' => (
64 is => 'rw',
65 isa => Enum [qw( pickup dropoff )],
66 default => 'pickup'
67 );
68  
69  
70 12 has 'printer_type' => (
71 is => 'rw',
72 isa => Str,
73 default => 'pdf',
74 );
75  
76  
77 12 has 'signature_type' => (
78 is => 'rw',
79 isa => Enum [qw( default required not_required adult )],
80 default => 'default',
81 );
82  
83  
84 12 has 'package_type' => (
85 is => 'rw',
86 isa => Enum [qw( custom envelope tube box pack )],
87 default => 'custom',
88 );
89  
90  
91 has 'packages' => (
92 handles_via => 'Array',
93 is => 'rw',
94 isa => ArrayRef [InstanceOf ['Shipment::Package']],
95 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
96 12 handles => {
97 all_packages => 'elements',
98 get_package => 'get',
99 add_package => 'push',
100 count_packages => 'count',
101 },
102 );
103  
104  
105 12 has 'weight_unit' => (
106 is => 'rw',
107 isa => Enum [qw( lb kg oz )],
108 default => 'lb',
109 );
110  
111 12 has 'dim_unit' => (
112 is => 'rw',
113 isa => Enum [qw( in cm )],
114 default => 'in',
115 );
116  
117  
118 12 has 'currency' => (
119 is => 'rw',
120 isa => Str,
121 default => 'USD',
122 );
123  
124  
125 has 'insured_value' => (
126 is => 'rw',
127 isa => InstanceOf ['Data::Currency'],
128 lazy => 1,
129 0 ▶ default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
130 0 my $self = shift;
131 0 my $insured_value = 0;
132 0 foreach (@{$self->packages}) {
133 0 $insured_value += $_->insured_value->value;
134 }
135 0 Data::Currency->new($insured_value);
136 },
137 12 );
138  
139  
140 has 'goods_value' => (
141 is => 'rw',
142 isa => InstanceOf ['Data::Currency'],
143 lazy => 1,
144 0 ▶ default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
145 0 my $self = shift;
146 0 my $goods_value = 0;
147 0 foreach (@{$self->packages}) {
148 0 $goods_value += $_->goods_value->value;
149 }
150 0 Data::Currency->new($goods_value);
151 },
152 12 );
153  
154  
155 has 'pickup_date' => (
156 is => 'rw',
157 isa => DateAndTime,
158 coerce => \&coerce_datetime,
159 2 ▶ default => sub { DateTime->now },
Subroutine __ANON__: called CC=1 SCAR=0.0
160 12 );
161  
162  
163 12 has 'services' => (
164 handles_via => 'Hash',
165 is => 'lazy',
166 isa => HashRef [InstanceOf ['Shipment::Service']],
167 handles => {all_services => 'values',},
168 );
169  
170  
171 12 has 'service' => (
172 is => 'rw',
173 isa => InstanceOf ['Shipment::Service'],
174 );
175  
176  
177 12 has 'tracking_id' => (
178 is => 'rw',
179 isa => Str,
180 );
181  
182  
183 has 'activities' => (
184 handles_via => 'Array',
185 is => 'rw',
186 isa => ArrayRef [InstanceOf ['Shipment::Activity']],
187 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
188 12 handles => {
189 all_activities => 'elements',
190 get_activity => 'get',
191 add_activity => 'push',
192 count_activities => 'count',
193 },
194 );
195  
196  
197 0 ▶sub status {
Subroutine status: not called CC=1 SCAR=6.9
Pod documented
198 0 shift->get_activity(0);
199 }
200  
201 12 has 'ship_date' => (
202 is => 'rw',
203 isa => DateAndTime,
204 coerce => \&coerce_datetime,
205 );
206  
207  
208 12 has 'documents' => (
209 is => 'rw',
210 isa => InstanceOf ['Shipment::Label'],
211 );
212  
213  
214 12 has 'manifest' => (
215 is => 'rw',
216 isa => InstanceOf ['Shipment::Label'],
217 );
218  
219  
220 has 'debug' => (
221 is => 'ro',
222 isa => Num,
223 2 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
224 2 ▶ return $ENV{SHIPMENT_DEBUG} || 0;
Condition50%1/2
$ENV{'SHIPMENT_DEBUG'} || 0
l!l
02
MC/DC0%0/1
$ENV{'SHIPMENT_DEBUG'} || 0
$ENV{'SHIPMENT_DEBUG'}
Truth table50%1/2
A
A= $ENV{'SHIPMENT_DEBUG'}
Aresult
11
00
225 },
226 12 );
227  
228  
229 12 has 'error' => (
230 is => 'rw',
231 isa => Str,
232 );
233  
234  
235 12 has 'notice' => (
236 handles_via => 'String',
237 is => 'rw',
238 isa => Str,
239 default => q{},
240 handles => {add_notice => 'append',},
241 );
242  
243  
244 has 'references' => (
245 handles_via => 'Array',
246 is => 'rw',
247 isa => ArrayRef [],
248 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
249 12 handles => {
250 all_references => 'elements',
251 get_reference => 'get',
252 add_reference => 'push',
253 count_references => 'count',
254 },
255 );
256  
257  
258 12 has 'special_instructions' => (
259 is => 'rw',
260 isa => Str,
261 );
262  
263  
264 12 has 'carbon_offset' => (
265 is => 'rw',
266 isa => Bool,
267 default => 0,
268 );
269  
270  
271 0 ▶sub _build_services {
Subroutine _build_services: not called CC=1 SCAR=6.9
272 0 my $self = shift;
273  
274 0 warn "routine '_build_services' has not been implemented";
275 0 $self->error("routine '_build_services' has not been implemented");
276 0 { ground => Shipment::Service->new(
277 id => 'ground',
278 name => 'Example Ground Service',
279 etd => 4, ## Estimated Transit Days
280 cost => Data::Currency->new(1),
281 ),
282 express => Shipment::Service->new(
283 id => 'express',
284 name => 'Example Express Service',
285 etd => 2, ## Estimated Transit Days
286 cost => Data::Currency->new(10),
287 ),
288 priority => Shipment::Service->new(
289 id => 'priority',
290 name => 'Example Priority Service',
291 etd => 1, ## Estimated Transit Days
292 cost => Data::Currency->new(100),
293 ),
294 };
295 }
296  
297  
298 0 ▶sub rate {
Subroutine rate: not called CC=2 SCAR=17.9
Pod documented
299 0 my ($self, $service_id) = @_;
300  
301 0 ▶ warn "routine 'rate' is not implemented for $self" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
302 0 $self->error("routine 'rate' is not implemented for $self");
303  
304 0 return;
305 }
306  
307  
308 0 ▶sub ship {
Subroutine ship: not called CC=2 SCAR=17.9
Pod documented
309 0 my ($self, $service_id) = @_;
310  
311 0 ▶ warn "routine 'ship' is not implemented for $self" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
312 0 $self->error("routine 'ship' is not implemented for $self");
313  
314 0 return;
315 }
316  
317  
318 0 ▶sub return {
Subroutine return: not called CC=2 SCAR=17.9
Pod documented
319 0 my ($self, $service_id) = @_;
320  
321 0 ▶ warn "routine 'return' is not implemented for $self" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
322 0 $self->error("routine 'return' is not implemented for $self");
323  
324 0 return;
325 }
326  
327  
328 0 ▶sub cancel {
Subroutine cancel: not called CC=2 SCAR=17.9
Pod documented
329 0 my ($self, $service_id) = @_;
330  
331 0 ▶ warn "routine 'cancel' is not implemented for $self" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
332 0 $self->error("routine 'cancel' is not implemented for $self");
333  
334 0 return;
335 }
336  
337  
338 0 ▶sub end_of_day {
Subroutine end_of_day: not called CC=2 SCAR=17.9
Pod documented
339 0 my ($self, $service_id) = @_;
340  
341 0 ▶ warn "routine 'end_of_day' is not implemented for $self" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
342 0 $self->error("routine 'end_of_day' is not implemented for $self");
343  
344 0 return;
345 }
346  
347  
348 0 ▶sub track {
Subroutine track: not called CC=2 SCAR=17.9
Pod documented
349 0 my $self = shift;
350  
351 0 ▶ warn "routine 'track' is not implemented for $self" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
352 0 $self->error("routine 'track' is not implemented for $self");
353  
354 0 return;
355 }
356  
357  
358 2 ▶sub coerce_datetime {
Subroutine coerce_datetime: called CC=8 SCAR=38.1
359 2 ▶ if (blessed($_[0]) and (blessed($_[0]) eq 'DateTime')) {
Branch: 4 branches
BranchTrueFalseTotal
if (builtin::blessed($_[0]) and builtin::blessed($_[0]) eq 'DateTime') { } 2 0 2
elsif (ref $_[0] eq 'HASH') { } 0 0 0
elsif (ref $_[0] eq '' and $_[0] =~ /^\d+/) { } 0 0 0
elsif (ref $_[0] eq '' and $_[0] eq 'now') { } 0 0 0
Condition33%1/3
builtin::blessed($_[0]) and builtin::blessed($_[0]) eq "DateTime"
!ll&&!rl&&r
002
MC/DC0%0/2
builtin::blessed($_[0]) and builtin::blessed($_[0]) eq "DateTime"
builtin::blessed($_[0]) builtin::blessed($_[0]) eq "DateTime"
Truth table33%1/3
A and B
A= builtin::blessed($_[0])B= builtin::blessed($_[0]) eq "DateTime"
ABresult
0X0
100
111
360 2 return $_[0];
361 }
362 elsif (ref($_[0]) eq 'HASH') {
363 0 return DateTime->new(%{$_[0]});
364 }
365 ▶ elsif (ref($_[0]) eq '' && $_[0] =~ /^\d+/) {
Condition0%0/3
ref $_[0] eq "" and $_[0] =~ /^\d+/
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[0] eq "" and $_[0] =~ /^\d+/
ref $_[0] eq "" $_[0] =~ /^\d+/
Truth table0%0/3
A and B
A= ref $_[0] eq ""B= $_[0] =~ /^\d+/
ABresult
0X0
100
111
366 0 return DateTime->from_epoch(epoch => $_[0]);
367 }
368 ▶ elsif (ref($_[0]) eq '' && $_[0] eq 'now') {
Condition0%0/3
ref $_[0] eq "" and $_[0] eq "now"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[0] eq "" and $_[0] eq "now"
ref $_[0] eq "" $_[0] eq "now"
Truth table0%0/3
A and B
A= ref $_[0] eq ""B= $_[0] eq "now"
ABresult
0X0
100
111
369 0 return DateTime->now;
370 }
371 else {
372 0 return return exception_message($_[0], 'a DateTime object');
373 }
374 }
375  
376  
377 12 1;
378  
379 __END__
« Shipment/Purolator/WSDL/Interfaces/ServiceAvailabilityService/ServiceAvailabilityServiceEndpoint.pm ↑ Summary Shipment/Purolator/WSDL/Interfaces/ShippingService/ShippingServiceEndpoint.pm »