UPS/Package.pm

filter: Statementstmt 93.1% 82 / 88 Branchbran 76.1% 32 / 42 Conditioncond 40.5% 15 / 37 MC/DCmcdc 16.6% 3 / 18 Subroutinesub 91.6% 11 / 12 Podpod 100% 3 / 3 totaltotal 73.0% 146 / 200 CC 37 SCAR 26.3
CC
37
Cov
77%
cache_id
30.0
is_oversized
18.6
as_hash
11.8
CRAP 13.9
« UPS/Address.pm ↑ Summary UPS/Response/QV/Exception.pm »
1 package Net::Async::Webservice::UPS::Package;
2 6 $Net::Async::Webservice::UPS::Package::VERSION = '1.1.4';
3 {
4 6 $Net::Async::Webservice::UPS::Package::DIST = 'Net-Async-Webservice-UPS';
5 }
6 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Type::Params qw(compile);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Types::Standard qw(Str Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Net::Async::Webservice::UPS::Types ':types';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Net::Async::Webservice::UPS::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # ABSTRACT: a package for UPS
15  
16  
17 has packaging_type => (
18 is => 'ro',
19 isa => PackagingType,
20 35 ▶ default => sub { 'PACKAGE' },
Subroutine __ANON__: called CC=1 SCAR=0.0
21 6 );
22  
23  
24 6 has linear_unit => (
25 is => 'ro',
26 isa => SizeMeasurementUnit,
27 required => 1,
28 );
29  
30  
31 6 has weight_unit => (
32 is => 'ro',
33 isa => WeightMeasurementUnit,
34 required => 1,
35 );
36  
37  
38 35 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=8 SCAR=22.4
39 35 my ($orig,$self,@etc) = @_;
40  
41 35 my $args = $self->$orig(@etc);
42 35 ▶ if (defined (my $ms = $args->{measurement_system})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ms = $args->{"measurement_system"})) 24 11 35
43 24 ▶ if ($ms eq 'english') {
Branch: 2 branches
BranchTrueFalseTotal
if ($ms eq 'english') { } 13 11 24
elsif ($ms eq 'metric') { } 11 0 11
44 13 ▶ $args->{linear_unit} ||= 'IN';
Condition50%1/2
$args->{"linear_unit"} ||= "IN"
l!l
013
MC/DC0%0/1
$args->{"linear_unit"} ||= "IN"
$args->{"linear_unit"}
Truth table50%1/2
A
A= $args->{"linear_unit"}
Aresult
11
00
45 13 ▶ $args->{weight_unit} ||= 'LBS';
Condition50%1/2
$args->{"weight_unit"} ||= "LBS"
l!l
013
MC/DC0%0/1
$args->{"weight_unit"} ||= "LBS"
$args->{"weight_unit"}
Truth table50%1/2
A
A= $args->{"weight_unit"}
Aresult
11
00
46 }
47 elsif ($ms eq 'metric') {
48 11 ▶ $args->{linear_unit} ||= 'CM';
Condition50%1/2
$args->{"linear_unit"} ||= "CM"
l!l
011
MC/DC0%0/1
$args->{"linear_unit"} ||= "CM"
$args->{"linear_unit"}
Truth table50%1/2
A
A= $args->{"linear_unit"}
Aresult
11
00
49 11 ▶ $args->{weight_unit} ||= 'KGS';
Condition50%1/2
$args->{"weight_unit"} ||= "KGS"
l!l
011
MC/DC0%0/1
$args->{"weight_unit"} ||= "KGS"
$args->{"weight_unit"}
Truth table50%1/2
A
A= $args->{"weight_unit"}
Aresult
11
00
50 }
51 else {
52 0 require Carp;
53 0 Carp::croak qq{Bad value "$ms" for measurement_system};
54 }
55 };
56 35 return $args;
57 6 };
58  
59  
60 6 has length => (
61 is => 'ro',
62 isa => Measure,
63 );
64  
65  
66 6 has width => (
67 is => 'ro',
68 isa => Measure,
69 );
70  
71  
72 6 has height => (
73 is => 'ro',
74 isa => Measure,
75 );
76  
77  
78 6 has weight => (
79 is => 'ro',
80 isa => Measure,
81 );
82  
83  
84 6 has id => (
85 is => 'rw',
86 isa => Str,
87 );
88  
89  
90 6 has description => (
91 is => 'rw',
92 isa => Str,
93 );
94  
95 6 my %code_for_packaging_type = (
96 LETTER => '01',
97 PACKAGE => '02',
98 TUBE => '03',
99 UPS_PAK => '04',
100 UPS_EXPRESS_BOX => '21',
101 UPS_25KG_BOX => '24',
102 UPS_10KG_BOX => '25'
103 );
104  
105  
106 11 ▶sub as_hash {
Subroutine as_hash: called CC=10 SCAR=24.7
Pod documented
107 11 state $argcheck = compile(Object);
108 11 my ($self) = $argcheck->(@_);
109  
110 my %data = (
111 PackagingType => {
112 11 Code => $code_for_packaging_type{$self->packaging_type},
113 },
114 );
115  
116 11 ▶ if ($self->description) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->description) 8 3 11
117 8 $data{Description} = $self->description;
118 }
119  
120 11 ▶ if ( $self->length || $self->width || $self->height ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->length or $self->width or $self->height) 11 0 11
Condition33%2/6
$self->length or $self->width or $self->height
l!l&&r!l&&!r
1100
$self->length or $self->width
l!l&&r!l&&!r
1100
MC/DC0%0/3
$self->length or $self->width or $self->height
$self->length $self->width $self->height
Truth table25%1/4
A or B or C
A= $self->lengthB= $self->widthC= $self->height
ABCresult
1XX1
01X1
0011
0000
121 $data{Dimensions} = {
122 11 UnitOfMeasurement => {
123 Code => $self->linear_unit,
124 }
125 };
126  
127 11 ▶ if ( $self->length ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->length) 11 0 11
128 11 $data{Dimensions}->{Length}= $self->length;
129 }
130 11 ▶ if ( $self->width ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->width) 11 0 11
131 11 $data{Dimensions}->{Width} = $self->width;
132 }
133 11 ▶ if ( $self->height ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->height) 11 0 11
134 11 $data{Dimensions}->{Height} = $self->height;
135 }
136 }
137  
138 11 ▶ if ( $self->weight ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->weight) 11 0 11
139 $data{PackageWeight} = {
140 11 UnitOfMeasurement => {
141 Code => $self->weight_unit,
142 },
143 Weight => $self->weight,
144 };
145 }
146  
147 11 ▶ if (my $oversized = $self->is_oversized ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $oversized = $self->is_oversized) 11 0 11
148 11 $data{OversizePackage} = $oversized;
149 }
150  
151 11 return \%data;
152 }
153  
154  
155 44 ▶sub is_oversized {
Subroutine is_oversized: called CC=17 SCAR=29.2
Pod documented
156 44 state $argcheck = compile(Object);
157 44 my ($self) = $argcheck->(@_);
158  
159 44 ▶ unless ( $self->width && $self->height && $self->length && $self->weight) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->width and $self->height and $self->length and $self->weight) 0 44 44
Condition33%3/9
$self->width and $self->height and $self->length and $self->weight
!ll&&!rl&&r
0044
$self->width and $self->height and $self->length
!ll&&!rl&&r
0044
$self->width and $self->height
!ll&&!rl&&r
0044
MC/DC0%0/4
$self->width and $self->height and $self->length and $self->weight
$self->width $self->height $self->length $self->weight
Truth table20%1/5
A and B and C and D
A= $self->widthB= $self->heightC= $self->lengthD= $self->weight
ABCDresult
0XXX0
10XX0
110X0
11100
11111
160 0 return 0;
161 }
162  
163 44 my @sides = sort { $a <=> $b } ($self->length, $self->width, $self->height);
164 44 my $len = pop(@sides); # Get longest side
165 44 my $girth = ((2 * $sides[0]) + (2 * $sides[1]));
166 44 my $size = $len + $girth;
167  
168 44 ▶ my ($max_len,$max_size,
Branch: 1 branch
BranchTrueFalseTotal
$self->linear_unit eq 'IN' ? : 28 16 44
169 $min_size,
170 $os1_size,
171 $os2_size,
172 $os3_size,) =
173 $self->linear_unit eq 'IN' ?
174 ( 108, 165,
175 84,
176 108,
177 130,
178 165, ) :
179 ( 270, 419,
180 210,
181 270,
182 330,
183 419, );
184  
185 44 ▶ my ($max_weight,
Branch: 1 branch
BranchTrueFalseTotal
$self->weight_unit eq 'LBS' ? : 27 17 44
186 $os1_weight,
187 $os2_weight,
188 $os3_weight) =
189 $self->weight_unit eq 'LBS' ?
190 ( 150,
191 30,
192 70,
193 90, ) :
194 ( 70,
195 10,
196 32,
197 40, );
198  
199 44 ▶ if ($len > $max_len or $self->weight > $max_weight or $size > $max_size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $max_len or $self->weight > $max_weight or $size > $max_size) 9 35 44
Condition100%6/6
$len > $max_len or $self->weight > $max_weight or $size > $max_size
l!l&&r!l&&!r
6335
$len > $max_len or $self->weight > $max_weight
l!l&&r!l&&!r
3338
MC/DC100%3/3
$len > $max_len or $self->weight > $max_weight or $size > $max_size
$len > $max_len $self->weight > $max_weight $size > $max_size
Truth table100%4/4
A or B or C
A= $len > $max_lenB= $self->weight > $max_weightC= $size > $max_size
ABCresult
1XX1
01X1
0011
0000
200 9 Net::Async::Webservice::UPS::Exception::BadPackage->throw({package=>$self});
201 }
202  
203 35 ▶ return 0 if ( $size <= $min_size ); # Below OS1
Branch: 1 branch
BranchTrueFalseTotal
if $size <= $min_size 0 35 35
204 35 ▶ if ($size <= $os1_size) { # OS1 pgk is billed for 30lbs
Branch: 1 branch
BranchTrueFalseTotal
if ($size <= $os1_size) 23 12 35
205 23 ▶ return (($self->weight < $os1_weight) ? 1 : 0); # Not OS1 if weight > 30lbs
Branch: 1 branch
BranchTrueFalseTotal
$self->weight < $os1_weight ? : 17 6 23
206 }
207 12 ▶ if ($size <= $os2_size) { # OS2 pgk is billed for 70lbs
Branch: 1 branch
BranchTrueFalseTotal
if ($size <= $os2_size) 6 6 12
208 6 ▶ return (($self->weight < $os2_weight) ? 2 : 0); # Not OS2 if weight > 70lbs
Branch: 1 branch
BranchTrueFalseTotal
$self->weight < $os2_weight ? : 3 3 6
209 }
210 6 ▶ if ($size <= $os3_size) { # OS3 pgk is billed for 90lbs
Branch: 1 branch
BranchTrueFalseTotal
if ($size <= $os3_size) 6 0 6
211 6 ▶ return (($self->weight < $os3_weight) ? 3 : 0); # Not OS3 if weight > 90lbs
Branch: 1 branch
BranchTrueFalseTotal
$self->weight < $os3_weight ? : 3 3 6
212 }
213 }
214  
215  
216 0 ▶sub cache_id {
Subroutine cache_id: not called CC=5 SCAR=34.0
Pod documented
217 0 state $argcheck = compile(Object);
218 0 my ($self) = $argcheck->(@_);
219  
220 0 ▶ return join ':',
Condition0%0/8
$self->length || 0
l!l
00
$self->width || 0
l!l
00
$self->height || 0
l!l
00
$self->weight || 0
l!l
00
MC/DC0%0/1
$self->length || 0
$self->length
MC/DC0%0/1
$self->width || 0
$self->width
MC/DC0%0/1
$self->height || 0
$self->height
MC/DC0%0/1
$self->weight || 0
$self->weight
Truth table0%0/2
A
A= $self->length
Aresult
11
00
Truth table0%0/2
A
A= $self->width
Aresult
11
00
Truth table0%0/2
A
A= $self->height
Aresult
11
00
Truth table0%0/2
A
A= $self->weight
Aresult
11
00
221 $self->packaging_type,$self->linear_unit,$self->weight_unit,
222 $self->length||0, $self->width||0, $self->height||0,
223 $self->weight||0,;
224 }
225  
226 6 1;
227  
228 __END__
« UPS/Address.pm ↑ Summary UPS/Response/QV/Exception.pm »