| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Amazon::MWS::XML::OrderlineItem; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 7 |  |  | 7 |  | 29 | use strict; | 
|  | 7 |  |  |  |  | 10 |  | 
|  | 7 |  |  |  |  | 218 |  | 
| 4 | 7 |  |  | 7 |  | 29 | use warnings; | 
|  | 7 |  |  |  |  | 8 |  | 
|  | 7 |  |  |  |  | 178 |  | 
| 5 | 7 |  |  | 7 |  | 27 | use Moo; | 
|  | 7 |  |  |  |  | 8 |  | 
|  | 7 |  |  |  |  | 119 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | =head1 ACCESSORS (they map the XML data) | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | =over 4 | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | =item PromotionDiscount | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | =item Title | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | =item OrderItemId | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | =item ASIN | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | =item GiftWrapPrice | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | =item GiftWrapTax | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | =item SellerSKU | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | =item ShippingPrice | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | =item ShippingTax | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | =item ShippingDiscount | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | =item ItemTax | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | =item ConditionId | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | =item ItemPrice | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | =item ConditionSubtypeId | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | =item QuantityShipped | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =item QuantityOrdered | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | =back | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | =cut | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | has PromotionDiscount => (is => 'ro', | 
| 49 |  |  |  |  |  |  | isa => sub { die unless ref($_[0]) eq 'HASH'}); | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | has Title => (is => 'ro'); | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | has OrderItemId => (is => 'ro'); | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | has ASIN => (is => 'ro'); | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | has GiftWrapPrice => (is => 'ro', | 
| 58 |  |  |  |  |  |  | isa => sub { die unless ref($_[0]) eq 'HASH'}); | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | has GiftWrapTax => (is => 'ro', | 
| 61 |  |  |  |  |  |  | isa => sub { die unless ref($_[0]) eq 'HASH'}); | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | has SellerSKU => (is => 'ro'); | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | has ShippingPrice => (is => 'ro', | 
| 66 |  |  |  |  |  |  | isa => sub { die unless ref($_[0]) eq 'HASH'}); | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | has ShippingTax => (is => 'ro', | 
| 69 |  |  |  |  |  |  | isa => sub { die unless ref($_[0]) eq 'HASH'}); | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | has ShippingDiscount => (is => 'ro', | 
| 72 |  |  |  |  |  |  | isa => sub { die unless ref($_[0]) eq 'HASH'}); | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | has ItemTax => (is => 'ro', | 
| 75 |  |  |  |  |  |  | isa => sub { die unless ref($_[0]) eq 'HASH'}); | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | has ConditionId => (is => 'ro'); | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | has ItemPrice => (is => 'ro', | 
| 80 |  |  |  |  |  |  | isa => sub { die unless ref($_[0]) eq 'HASH'}); | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | has ConditionSubtypeId => (is => 'ro'); | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | has QuantityShipped => (is => 'ro'); | 
| 85 |  |  |  |  |  |  | has QuantityOrdered => (is => 'ro'); | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | =head2 amazon_order_item | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | The amazon id for the given item (read-only) | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | =head2 remote_shop_order_item | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | Alias for C<amazon_order_item> | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =head2 merchant_order_item | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | Our id (read-write). | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | =head2 currency | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | The currency code. | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | =cut | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | has merchant_order_item => (is => 'rw'); | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | sub amazon_order_item { | 
| 108 | 2 |  |  | 2 | 1 | 11 | return shift->OrderItemId; | 
| 109 |  |  |  |  |  |  | } | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | sub remote_shop_order_item { | 
| 112 | 1 |  |  | 1 | 1 | 3 | return shift->amazon_order_item; | 
| 113 |  |  |  |  |  |  | } | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | sub currency { | 
| 117 | 0 |  |  | 0 | 1 | 0 | return shift->ItemPrice->{CurrencyCode}; | 
| 118 |  |  |  |  |  |  | } | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | =head2 price | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | Amazon report the item price's as the sum of the items, not the | 
| 123 |  |  |  |  |  |  | individual price. So we have to do a division for what we know as the | 
| 124 |  |  |  |  |  |  | item's price. This looks ugly anyway. | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | From | 
| 127 |  |  |  |  |  |  | L<http://docs.developer.amazonservices.com/en_US/orders/2013-09-01/Orders_ListOrderItems.html>: | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | The selling price of the order item. Note that an order item is an | 
| 130 |  |  |  |  |  |  | item and a quantity. This means that the value of ItemPrice is equal | 
| 131 |  |  |  |  |  |  | to the selling price of the item multiplied by the quantity ordered. | 
| 132 |  |  |  |  |  |  | Note that ItemPrice excludes ShippingPrice and GiftWrapPrice. | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | =cut | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | sub price { | 
| 137 | 2 |  |  | 2 | 1 | 1904 | my $self = shift; | 
| 138 | 2 |  |  |  |  | 7 | return sprintf('%.2f', $self->subtotal / $self->quantity); | 
| 139 |  |  |  |  |  |  | } | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | =head2 shipping | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | The ShippingPrice amount. | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | =head2 subtotal | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | The price of the items for the given quantity (see above, C<price>). | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | =cut | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | sub shipping { | 
| 152 | 0 |  |  | 0 | 1 | 0 | my $self = shift; | 
| 153 | 0 |  |  |  |  | 0 | my $shipping = 0; | 
| 154 | 0 | 0 |  |  |  | 0 | if (my $price = $self->ShippingPrice) { | 
| 155 | 0 |  | 0 |  |  | 0 | $shipping = $price->{Amount} || 0; | 
| 156 |  |  |  |  |  |  | } | 
| 157 | 0 |  |  |  |  | 0 | return sprintf('%.2f', $shipping); | 
| 158 |  |  |  |  |  |  | } | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  | =head2 as_ack_orderline_item_hashref | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | Return an hashref suitable for the building of an ack order feed. | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | =cut | 
| 165 |  |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | =head2 Aliases | 
| 167 |  |  |  |  |  |  |  | 
| 168 |  |  |  |  |  |  | =over 4 | 
| 169 |  |  |  |  |  |  |  | 
| 170 |  |  |  |  |  |  | =item sku (SellerSKU) | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | =item asin (ASIN) | 
| 173 |  |  |  |  |  |  |  | 
| 174 |  |  |  |  |  |  | =item quantity (QuantityOrdered) | 
| 175 |  |  |  |  |  |  |  | 
| 176 |  |  |  |  |  |  | =item name (Title) | 
| 177 |  |  |  |  |  |  |  | 
| 178 |  |  |  |  |  |  | =back | 
| 179 |  |  |  |  |  |  |  | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | =cut | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | sub sku { | 
| 184 | 0 |  |  | 0 | 1 | 0 | return shift->SellerSKU; | 
| 185 |  |  |  |  |  |  | } | 
| 186 |  |  |  |  |  |  | sub asin { | 
| 187 | 0 |  |  | 0 | 1 | 0 | return shift->ASIN; | 
| 188 |  |  |  |  |  |  | } | 
| 189 |  |  |  |  |  |  |  | 
| 190 |  |  |  |  |  |  | sub quantity { | 
| 191 | 2 |  |  | 2 | 1 | 23 | return shift->QuantityOrdered; | 
| 192 |  |  |  |  |  |  | } | 
| 193 |  |  |  |  |  |  |  | 
| 194 |  |  |  |  |  |  | sub name { | 
| 195 | 0 |  |  | 0 | 1 | 0 | return shift->Title; | 
| 196 |  |  |  |  |  |  | } | 
| 197 |  |  |  |  |  |  |  | 
| 198 |  |  |  |  |  |  | sub subtotal { | 
| 199 | 3 |  |  | 3 | 1 | 4 | my $self = shift; | 
| 200 | 3 |  |  |  |  | 5 | my $amount = 0; | 
| 201 | 3 | 50 |  |  |  | 15 | if (my $price = $self->ItemPrice) { | 
| 202 | 3 |  | 50 |  |  | 9 | $amount = $price->{Amount} || 0; | 
| 203 |  |  |  |  |  |  | } | 
| 204 | 3 |  |  |  |  | 57 | return sprintf('%.2f', $amount); | 
| 205 |  |  |  |  |  |  | } | 
| 206 |  |  |  |  |  |  |  | 
| 207 |  |  |  |  |  |  | sub as_ack_orderline_item_hashref { | 
| 208 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 209 |  |  |  |  |  |  | return { | 
| 210 | 0 |  |  |  |  |  | AmazonOrderItemCode => $self->amazon_order_item, | 
| 211 |  |  |  |  |  |  | MerchantOrderItemID => $self->merchant_order_item, | 
| 212 |  |  |  |  |  |  | }; | 
| 213 |  |  |  |  |  |  | } | 
| 214 |  |  |  |  |  |  |  | 
| 215 |  |  |  |  |  |  |  | 
| 216 |  |  |  |  |  |  | 1; |