MWS/XML/Response/OrderReport/Item.pm

filter: Statementstmt 44.0% 37 / 84 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 26.0% 6 / 23 Podpod 100% 5 / 5 totaltotal 35.8% 48 / 134 CC 15 SCAR 25.9
CC
15
Cov
36%
_build_total_price
30.0
_get_price_component
30.0
_build_amazon_fee
20.0
CRAP 13.3
« MWS/XML/Feed.pm ↑ Summary MWS/Products.pm »
1 package Amazon::MWS::XML::Response::OrderReport::Item;
2  
3 6 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use MooX::Types::MooseLike::Base qw(Int Str HashRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 Amazon::MWS::XML::Response::OrderReport::Item
13  
14 =head1 DESCRIPTION
15  
16 Class which handles the xml structures reported by the C<GetReport>
17 with type C<OrderReport> in the C<Item> slot (the orderline's items).
18  
19 The class should act like L<Amazon::MWS::XML::OrderlineItem> when
20 applicable.
21  
22 =head1 ACCESSORS
23  
24 They correspond to the documented structure. They should not be called
25 directly, though, prefer the methods above.
26  
27 =over 4
28  
29 =item Title
30  
31 =item Quantity
32  
33 =item SKU
34  
35 =item ItemPrice
36  
37 =item ProductTaxCode
38  
39 =item AmazonOrderItemCode
40  
41 =item ItemFees
42  
43 =back
44  
45 =cut
46  
47 6 has Title => (is => 'ro', isa => Str);
48 6 has Quantity => (is => 'ro', isa => Int);
49 6 has SKU => (is => 'ro', isa => Str);
50 6 has ItemPrice => (is => 'ro', isa => HashRef);
51 6 has ProductTaxCode => (is => 'ro', isa => Str);
52 6 has AmazonOrderItemCode => (is => 'ro', isa => Str);
53 6 has ItemFees => (is => 'ro', isa => HashRef);
54  
55 =head2 merchant_order_item
56  
57 Our id (read-write).
58  
59 =head1 METHODS AND SHORTCUTS
60  
61 All the methods are read only.
62  
63 =over 4
64  
65 =item total_price
66  
67 The grand total for the item in the given quantity.
68  
69 =item subtotal
70  
71 If there are taxes in the amazon price component, including taxes, but
72 without shipping.
73  
74 =item shipping
75  
76 The shipping cost including taxes.
77  
78 =item price
79  
80 Individual price of a single item, including taxes (from the Amazon
81 point of view): subtotal / quantity.
82  
83 =item shipping_netto
84  
85 The shipping without the taxes (from the Amazon point of view).
86  
87 =item price_netto
88  
89 The price without taxes (from the Amazon point of view) for the
90 quantity.
91  
92 =item item_tax
93  
94 =item shipping_tax
95  
96 =item amazon_fee
97  
98 The price paid to amazon for the given item. It could be a negative
99 number.
100  
101 =item quantity
102  
103 =item currency
104  
105 =item name
106  
107 =item sku
108  
109 =item amazon_order_item
110  
111 =item as_ack_orderline_item_hashref
112  
113 =back
114  
115 =cut
116  
117 has merchant_order_item => (is => 'rw',
118 0 ▶ default => sub { '' });
Subroutine __ANON__: not called CC=1 SCAR=1.2
119  
120 6 has total_price => (is => 'lazy');
121 6 has subtotal => (is => 'lazy');
122 6 has price => (is => 'lazy');
123 6 has shipping => (is => 'lazy');
124 6 has shipping_netto => (is => 'lazy');
125 6 has price_netto => (is => 'lazy');
126 6 has item_tax => (is => 'lazy');
127 6 has shipping_tax => (is => 'lazy');
128 6 has amazon_fee => (is => 'lazy');
129  
130 0 ▶sub _build_amazon_fee {
Subroutine _build_amazon_fee: not called CC=4 SCAR=30.0
131 0 my $self = shift;
132 0 my $toll = 0;
133 0 ▶ if (my $fees = $self->ItemFees->{Fee}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fees = $self->ItemFees->{"Fee"}) 0 0 0
134 0 foreach my $fee (@$fees) {
135 0 ▶ $toll += $fee->{Amount}->{_} || 0;
Condition0%0/2
$fee->{'Amount'}{'_'} || 0
l!l
00
MC/DC0%0/1
$fee->{'Amount'}{'_'} || 0
$fee->{'Amount'}{'_'}
Truth table0%0/2
A
A= $fee->{'Amount'}{'_'}
Aresult
11
00
136 }
137 }
138 0 return sprintf('%.2f', $toll);
139 }
140  
141 0 ▶sub _build_shipping_netto {
Subroutine _build_shipping_netto: not called CC=1 SCAR=6.9
142 0 return shift->_get_price_component('Shipping');
143 }
144  
145 0 ▶sub _build_price_netto {
Subroutine _build_price_netto: not called CC=1 SCAR=6.9
146 0 return shift->_get_price_component('Principal');
147 }
148  
149 0 ▶sub _build_item_tax {
Subroutine _build_item_tax: not called CC=1 SCAR=6.9
150 0 return shift->_get_price_component('Tax');
151 }
152  
153 0 ▶sub _build_shipping_tax {
Subroutine _build_shipping_tax: not called CC=1 SCAR=6.9
154 0 return shift->_get_price_component('ShippingTax');
155 }
156  
157 0 ▶sub _build_price {
Subroutine _build_price: not called CC=1 SCAR=6.9
158 0 my $self = shift;
159 0 return sprintf('%.2f', $self->subtotal / $self->quantity);
160 }
161  
162 0 ▶sub _build_shipping {
Subroutine _build_shipping: not called CC=1 SCAR=6.9
163 0 my $self = shift;
164 0 return sprintf('%.2f', $self->shipping_netto + $self->shipping_tax);
165 }
166  
167 0 ▶sub _build_subtotal {
Subroutine _build_subtotal: not called CC=1 SCAR=6.9
168 0 my $self = shift;
169 0 return sprintf('%.2f', $self->price_netto + $self->item_tax);
170 }
171  
172  
173 0 ▶sub _build_total_price {
Subroutine _build_total_price: not called CC=5 SCAR=34.0
174 0 my $self = shift;
175 0 my $amount = 0;
176 0 ▶ if (my $components = $self->ItemPrice->{Component}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $components = $self->ItemPrice->{"Component"}) 0 0 0
177 0 foreach my $comp (@$components) {
178 0 ▶ $amount += $comp->{Amount}->{_} || 0;
Condition0%0/2
$comp->{'Amount'}{'_'} || 0
l!l
00
MC/DC0%0/1
$comp->{'Amount'}{'_'} || 0
$comp->{'Amount'}{'_'}
Truth table0%0/2
A
A= $comp->{'Amount'}{'_'}
Aresult
11
00
179 }
180 }
181 0 my $total_price = sprintf('%.2f', $amount);
182 0 my $check = $self->price_netto + $self->item_tax + $self->shipping_netto + $self->shipping_tax;
183 0 ▶ if ($total_price eq sprintf('%.2f', $check)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($total_price eq sprintf('%.2f', $check)) { } 0 0 0
184 0 return $total_price;
185 }
186 else {
187 0 die "There is a bug in the price routine!";
188 }
189 }
190  
191 6 has currency => (is => 'lazy');
192  
193 0 ▶sub _build_currency {
Subroutine _build_currency: not called CC=4 SCAR=30.0
194 0 my $self = shift;
195 0 my $currency;
196 0 ▶ if (my $components = $self->ItemPrice->{Component}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $components = $self->ItemPrice->{"Component"}) 0 0 0
197 0 foreach my $comp (@$components) {
198 0 ▶ last if $currency = $comp->{Amount}->{currency};
Branch: 1 branch
BranchTrueFalseTotal
if $currency = $comp->{"Amount"}{"currency"} 0 0 0
199 }
200 }
201 0 return $currency;
202 }
203  
204 0 ▶sub _get_price_component {
Subroutine _get_price_component: not called CC=5 SCAR=34.0
205 0 my ($self, $type) = @_;
206 0 ▶ die unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 0 0
207 0 my $amount = 0;
208 0 ▶ if (my $components = $self->ItemPrice->{Component}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $components = $self->ItemPrice->{"Component"}) 0 0 0
209 0 foreach my $comp (@$components) {
210 0 ▶ if ($type eq $comp->{Type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq $comp->{"Type"}) 0 0 0
211 0 $amount += $comp->{Amount}->{_};
212 }
213 }
214 }
215 0 return sprintf('%.2f', $amount);
216 }
217  
218  
219 0 ▶sub sku {
Subroutine sku: not called CC=1 SCAR=6.9
Pod documented
220 0 return shift->SKU;
221 }
222  
223 0 ▶sub quantity {
Subroutine quantity: not called CC=1 SCAR=6.9
Pod documented
224 0 return shift->Quantity;
225 }
226  
227 0 ▶sub name {
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
228 0 return shift->Title;
229 }
230  
231 0 ▶sub amazon_order_item {
Subroutine amazon_order_item: not called CC=1 SCAR=6.9
Pod documented
232 0 return shift->AmazonOrderItemCode;
233 }
234  
235 0 ▶sub as_ack_orderline_item_hashref {
Subroutine as_ack_orderline_item_hashref: not called CC=1 SCAR=6.9
Pod documented
236 0 my $self = shift;
237 return {
238 0 AmazonOrderItemCode => $self->amazon_order_item,
239 MerchantOrderItemID => $self->merchant_order_item,
240 };
241  
242 }
243  
244  
245 6 1;
« MWS/XML/Feed.pm ↑ Summary MWS/Products.pm »