Ebay/Order/Item.pm

filter: Statementstmt 92.8% 39 / 42 Branchbran 50.0% 1 / 2 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 89.4% 17 / 19 Podpod 100% 13 / 13 totaltotal 87.6% 71 / 81 CC 3 SCAR 2.8
CC
3
Cov
87%
sku
2.3
variant_sku
2.1
shipping
2.0
CRAP 1.3
« Ebay/Order/Address.pm ↑ Summary
1 package Marketplace::Ebay::Order::Item;
2  
3 =head1 NAME
4  
5 Marketplace::Ebay::Order::Item.
6  
7 =head1 DESCRIPTION
8  
9 Class to handle the xml structures representing a orderline item.
10  
11 This modules doesn't do much, it just provides an uniform iterface
12 with other Marketplace modules.
13  
14 Items must implement the following methods:
15  
16 =over 4
17  
18 =item sku
19  
20 =item quantity
21  
22 =item price
23  
24 From the Ebay documentation:
25  
26 The price of the order line item (transaction). This amount does not
27 take into account shipping, sales tax, and other costs related to
28 the order line item. If multiple units were purchased through a non-
29 variation, fixed-price listing, consider this value the per-unit
30 price. In this case, the TransactionPrice would be multiplied by the
31 Transaction.QuantityPurchased value.
32  
33 =item subtotal
34  
35 =item remote_shop_order_item
36  
37 =item merchant_order_item
38  
39 This one should be a read-write accessor, because usually Ebay doesn't
40 know about it.
41  
42 =back
43  
44 =head1 ACCESSORS
45  
46 =head2 struct
47  
48 This hashref must be passed to the constructor, containing the XML
49 structure.
50  
51 =head1 OTHER SHORTCUTS
52  
53 =head2 canonical_sku
54  
55 The canonical sku.
56  
57 =head2 variant_sku
58  
59 The variant sku.
60  
61 =head2 sku
62  
63 This return either the variant's SKU, if present, or the canonical SKU.
64  
65 =cut
66  
67 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
69  
70 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 5 ▶use MooX::Types::MooseLike::Base qw(HashRef Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
72 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
73 5 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
74  
75 5 has struct => (is => 'ro', isa => HashRef);
76 5 has merchant_order_item => (is => 'rw', isa => Str);
77  
78 sub sku {
79 1 ▶ my $self = shift;
Subroutine sku: called CC=2 SCAR=8.1
Pod documented
80 1 ▶ return $self->variant_sku || $self->canonical_sku;
Condition33%1/3
$self->variant_sku || $self->canonical_sku
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->variant_sku || $self->canonical_sku
$self->variant_sku $self->canonical_sku
Truth table33%1/3
A || B
A= $self->variant_skuB= $self->canonical_sku
ABresult
1X1
011
000
81 }
82  
83 sub canonical_sku {
84 # Item is always present
85 1 ▶ return shift->struct->{Item}->{SKU};
Subroutine canonical_sku: called CC=1 SCAR=0.0
Pod documented
86 }
87  
88 sub variant_sku {
89 2 ▶ my $self = shift;
Subroutine variant_sku: called CC=2 SCAR=7.4
Pod documented
90 2 my $struct = $self->struct;
91 2 ▶ if ($struct->{Variation}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($struct->{'Variation'}) { } 2 0 2
92 2 return $struct->{Variation}->{SKU};
93 }
94 else {
95 0 return;
96 }
97 }
98  
99 sub remote_shop_order_item {
100 1 ▶ return shift->struct->{OrderLineItemID};
Subroutine remote_shop_order_item: called CC=1 SCAR=0.0
Pod documented
101 }
102  
103 # guaranteed to be there http://developer.ebay.com/devzone/xml/docs/Reference/ebay/GetOrders.html#Response.OrderArray.Order.TransactionArray.Transaction.QuantityPurchased
104  
105 sub quantity {
106 3 ▶ return shift->struct->{QuantityPurchased};
Subroutine quantity: called CC=1 SCAR=0.0
Pod documented
107 }
108  
109 sub price {
110 3 ▶ my $self = shift;
Subroutine price: called CC=1 SCAR=0.0
Pod documented
111 3 return sprintf('%.2f', $self->struct->{TransactionPrice}->{_});
112 }
113  
114 sub subtotal {
115 2 ▶ my $self = shift;
Subroutine subtotal: called CC=1 SCAR=0.0
Pod documented
116 2 return sprintf('%.2f', $self->price * $self->quantity);
117 }
118  
119 =head2 shipping
120  
121 The shipping costs. Always return 0, it's not something available in
122 the orderline item.
123  
124 =cut
125  
126 sub shipping {
127 0 ▶ return 0; # not available in the item
Subroutine shipping: not called CC=1 SCAR=6.9
Pod documented
128 }
129  
130 =head2 is_shipped
131  
132 Return the shipped time if defined. You should consider this a
133 boolean.
134  
135 =cut
136  
137 sub is_shipped {
138 2 ▶ my $self = shift;
Subroutine is_shipped: called CC=1 SCAR=0.0
Pod documented
139 2 return $self->struct->{ShippedTime};
140 }
141  
142 =head2 email
143  
144 Buyer's email.
145  
146 =cut
147  
148 sub email {
149 1 ▶ return shift->struct->{Buyer}->{Email};
Subroutine email: called CC=1 SCAR=0.0
Pod documented
150 }
151  
152 =head2 first_name
153  
154 Buyer's first name
155  
156 =cut
157  
158 sub first_name {
159 1 ▶ return shift->struct->{Buyer}->{UserFirstName};
Subroutine first_name: called CC=1 SCAR=0.0
Pod documented
160 }
161  
162 =head2 last_name
163  
164 Buyer's last name.
165  
166 =cut
167  
168 sub last_name {
169 1 ▶ return shift->struct->{Buyer}->{UserLastName};
Subroutine last_name: called CC=1 SCAR=0.0
Pod documented
170 }
171  
172 =head2 ebay_site
173  
174 The ebay site id.
175  
176 =cut
177  
178 sub ebay_site {
179 0 ▶ return shift->struct->{Item}->{Site};
Subroutine ebay_site: not called CC=1 SCAR=6.9
Pod documented
180 }
181  
182 5 1;
183  
« Ebay/Order/Address.pm ↑ Summary