cXML/ItemIn.pm

filter: Statementstmt 42.8% 24 / 56 Branchbran 0.0% 0 / 32 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 72.7% 8 / 11 Podpod 100% 2 / 2 totaltotal 33.6% 34 / 101 CC 19 SCAR 53.6
CC
19
Cov
27%
to_node
342.0
_bool
6.0
from_node
2.0
CRAP 213.0
↑ Summary cXML/Transmission.pm »
1 =encoding utf-8
2  
3 =head1 NAME
4  
5 Business::cXML::ItemIn - cXML line item, from seller to buyer
6  
7 =head1 SYNOPSIS
8  
9 use Business::cXML::ItemIn;
10  
11 =head1 DESCRIPTION
12  
13 Object representation of cXML C<ItemIn>.
14  
15 =head1 METHODS
16  
17 See L<Business::cXML::Object/COMMON METHODS>.
18  
19 =head1 PROPERTY METHODS
20  
21 See L<Business::cXML::Object/PROPERTY METHODS> for how the following operate.
22  
23 =over
24  
25 =cut
26  
27 1 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 package Business::cXML::ItemIn;
31 1 ▶use base qw(Business::cXML::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 1 ▶use constant NODENAME => 'ItemIn';
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use constant PROPERTIES => (
Subroutine BEGIN: called CC=1 SCAR=0.0
35 sku => '',
36 qty => 0,
37 qty_open => undef,
38 qty_promised => undef,
39 i => undef,
40 i_parent => undef,
41 is_group => undef,
42 is_parent_group => undef,
43 is_service => undef,
44 price => undef,
45 descriptions => [],
46 unit => 'EA',
47 class_domain => 'UNSPSC',
48 class => '',
49 manu_part => undef,
50 manu_name => undef,
51 manu_lang => 'en-US',
52 delay => undef,
53 chars => [],
54 url => undef,
55 shipping => undef,
56 tax => undef,
57 1 );
58 1 ▶use constant OBJ_PROPERTIES => (
Subroutine BEGIN: called CC=1 SCAR=0.0
59 price => [ 'Business::cXML::Amount', 'UnitPrice' ],
60 descriptions => 'Business::cXML::Description',
61 chars => 'Business::cXML::Characteristic',
62 shipping => [ 'Business::cXML::Amount', 'Shipping' ],
63 tax => [ 'Business::cXML::Amount', 'Tax' ],
64 1 );
65  
66 1 ▶use Business::cXML::Amount;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 1 ▶use XML::LibXML::Ferry;
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69 0 ▶sub _bool {
Subroutine _bool: not called CC=2 SCAR=17.9
70 0 my ($self, $val) = @_;
71 0 ▶ return 1 if $val =~ /^(composite|groupLevel|service)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ /^(composite|groupLevel|service)$/u 0 0 0
72 0 return 0; # DTD guarantees: item|itemLevel|material
73 }
74  
75 0 ▶sub from_node {
Subroutine from_node: not called CC=1 SCAR=6.9
Pod documented
76 0 my ($self, $el) = @_;
77  
78 0 $el->ferry($self, {
79 quantity => 'qty',
80 openQuantity => 'qty_open',
81 promisedQuantity => 'qty_promised',
82 lineNumber => 'i',
83 parentLineNumber => 'i_parent',
84 itemType => [ 'is_group', \&_bool ],
85 compositeItemType => [ 'is_parent_group', \&_bool ],
86 itemClassification => [ 'is_service', \&_bool ],
87 itemCategory => '__UNIMPLEMENTED',
88 ItemID => {
89 # UNIMPLEMENTED SupplierPartID.revisionID
90 SupplierPartID => 'sku',
91 SupplierPartAuxiliaryID => '__UNIMPLEMENTED',
92 BuyerPartID => '__UNIMPLEMENTED',
93 IdReference => '__UNIMPLEMENTED',
94 },
95 Path => '__UNIMPLEMENTED',
96 ItemDetail => {
97 UnitPrice => [ 'price', 'Business::cXML::Amount' ],
98 Description => [ 'descriptions', 'Business::cXML::Description' ],
99 OverallLimit => '__UNIMPLEMENTED',
100 ExpectedLimit => '__UNIMPLEMENTED',
101 UnitOfMeasure => 'unit',
102 PriceBasisQuantity => '__UNIMPLEMENTED',
103 Classification => {
104 # We only keep the last one that will be processed
105 domain => 'class_domain',
106 code => '__UNIMPLEMENTED',
107 __text => 'class',
108 },
109 ManufacturerPartID => 'manu_part',
110 ManufacturerName => {
111 'xml:lang' => 'manu_lang',
112 __text => 'manu_name',
113 },
114 # URL is implicit
115 LeadTime => 'delay',
116 Dimension => '__UNIMPLEMENTED',
117 ItemDetailIndustry => {
118 # Attribute isConfigurableMaterial is implied from the presence of characteristics
119 ItemDetailRetail => {
120 EANID => '__OBSOLETE',
121 EuropeanWasteCatalogID => '__UNIMPLEMENTED',
122 Characteristic => [ 'chars', 'Business::cXML::Characteristic' ],
123 },
124 },
125 AttachmentReference => '__UNIMPLEMENTED',
126 PlannedAcceptanceDays => '__UNIMPLEMENTED',
127 },
128 SupplierID => '__UNIMPLEMENTED',
129 SupplierList => '__UNIMPLEMENTED',
130 ShipTo => '__UNIMPLEMENTED',
131 Shipping => [ 'shipping', 'Business::cXML::Amount' ],
132 Tax => [ 'tax', 'Business::cXML::Amount' ],
133 SpendDetail => '__UNIMPLEMENTED',
134 Distribution => '__UNIMPLEMENTED',
135 Contact => '__UNIMPLEMENTED',
136 Comments => '__UNIMPLEMENTED',
137 ScheduleLine => '__UNIMPLEMENTED',
138 BillTo => '__UNIMPLEMENTED',
139 Batch => '__UNIMPLEMENTED',
140 DateInfo => '__UNIMPLEMENTED',
141 });
142 }
143  
144 0 ▶sub to_node {
Subroutine to_node: not called CC=18 SCAR=58.3
Pod documented
145 0 my ($self, $doc) = @_;
146 my $node = $doc->create($self->{_nodeName}, undef,
147 quantity => $self->{qty},
148 openQuantity => $self->{qty_open},
149 promisedQuantity => $self->{qty_promised},
150 lineNumber => $self->{i},
151 parentLineNumber => $self->{i_parent},
152 0 );
153 0 ▶ $node->{itemType} = ($self->is_group ? 'composite' : 'item' ) if defined $self->{is_group};
Branch: 2 branches
BranchTrueFalseTotal
if defined $self->{"is_group"} 0 0 0
$self->is_group ? : 0 0 0
154 0 ▶ $node->{compositeItemType} = ($self->is_parent_group ? 'groupLevel' : 'itemLevel') if defined $self->{is_parent_group};
Branch: 2 branches
BranchTrueFalseTotal
if defined $self->{"is_parent_group"} 0 0 0
$self->is_parent_group ? : 0 0 0
155 0 ▶ $node->{itemClassification} = ($self->is_service ? 'service' : 'material' ) if defined $self->{is_service};
Branch: 2 branches
BranchTrueFalseTotal
if defined $self->{"is_service"} 0 0 0
$self->is_service ? : 0 0 0
156  
157 0 $node->add('ItemID')->add('SupplierPartID', $self->{sku});
158  
159 0 my $idet = $node->add('ItemDetail');
160 0 ▶ $self->price({}) unless defined $self->{price};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"price"} 0 0 0
161 0 $idet->add($self->{price}->to_node($doc));
162 0 ▶ $self->descriptions({}) unless scalar(@{ $self->{descriptions} } > 0);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar(@{$self->{"descriptions"};} > 0) 0 0 0
163 0 $idet->add($_->to_node($doc)) foreach (@{ $self->{descriptions} });
164 0 $idet->add('UnitOfMeasure', $self->{unit});
165 0 $idet->add('Classification', $self->{class}, domain => $self->{class_domain});
166 0 ▶ $idet->add('ManufacturerPartID', $self->{manu_part}) if defined $self->{manu_part};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"manu_part"} 0 0 0
167 0 ▶ $idet->add('ManufacturerName', $self->{manu_name}, 'xml:lang' => $self->{manu_lang}) if defined $self->{manu_name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"manu_name"} 0 0 0
168 0 ▶ $idet->add('URL', $self->{url}) if defined $self->{url};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"url"} 0 0 0
169 0 ▶ $idet->add('LeadTime', $self->{delay}) if defined $self->{delay};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"delay"} 0 0 0
170 0 ▶ if (scalar(@{ $self->{chars} }) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->{"chars"};} > 0) 0 0 0
171 0 my $ret = $idet->add('ItemDetailIndustry', undef, isConfigurableMaterial => 'yes')->add('ItemDetailRetail');
172 0 $ret->add($_->to_node($doc)) foreach (@{ $self->{chars} });
173 };
174  
175 0 ▶ $node->add($self->{shipping}->to_node($doc)) if defined $self->{shipping};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"shipping"} 0 0 0
176 0 ▶ $node->add($self->{tax}->to_node($doc) ) if defined $self->{tax};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"tax"} 0 0 0
177  
178 0 return $node;
179 }
180  
181  
182 =item C<B<sku>>
183  
184 Mandatory SKU, a string uniquely identifying the product being sold, with the
185 L</chars> (colors, sizes) selected.
186  
187 =item C<B<qty>>
188  
189 Mandatory, how many items. Default: C<0>
190  
191 =item C<B<qty_open>>
192  
193 Optional, the quantity pending to be fulfilled by the seller to ship to the
194 buyer.
195  
196 =item C<B<qty_promised>>
197  
198 Optional, the quantity that has been promised by the selling party.
199  
200 =item C<B<i>>
201  
202 =item C<B<i_parent>>
203  
204 Optional, line number (starting from 1). I<C<i_parent>> refers to a parent
205 item's I<C<i>>. This allows nesting items.
206  
207 =item C<B<is_group>>
208  
209 =item C<B<is_parent_group>>
210  
211 Optional, whether the item (or its parent) contains child items.
212  
213 The current implementation B<does not set this for you> when you use
214 I<C<i_parent>>: you must set these according to your structure.
215  
216 =item C<B<is_service>>
217  
218 Optional, clarify whether the item is a service (true) or material (false).
219  
220 =item C<B<price>>
221  
222 Mandatory, L<Business::cXML::Amount> object of type C<UnitPrice>.
223  
224 =item C<B<descriptions>>
225  
226 Mandatory (at least one)
227  
228 =item C<B<unit>>
229  
230 Mandatory, UN/CEFACT Recommendation 20 unit of measure. Default: C<EA>
231 meaning "each", items are regarded as separate units. Also common: C<HUR>
232 means one hour.
233  
234 See
235 L<http://www.unece.org/tradewelcome/un-centre-for-trade-facilitation-and-e-business-uncefact/outputs/cefactrecommendationsrec-index/list-of-trade-facilitation-recommendations-n-16-to-20.html>
236 for more details about UN/CEFACT Recommendation 20 units of measure.
237  
238 =item C<B<class_domain>>
239  
240 =item C<B<class>>
241  
242 Mandatory, name of classification such as C<UNSPSC> (default) and the
243 classification itself (such as an 8+ digit UNSPSC number).
244  
245 See L<https://en.wikipedia.org/wiki/UNSPSC> and L<http://www.unspsc.org/> for
246 more details about UNSPSC classifications, for example, C<53101902> "Men's
247 suits"
248  
249 =item C<B<manu_part>>
250  
251 Optional, ID with which the item's manufacturer identifies the item.
252  
253 =item C<B<manu_name>>
254  
255 =item C<B<manu_lang>>
256  
257 Optional, name of the item's manufacturer and language of that name.
258 C<manu_lang> defaults to C<en-us> if only C<manu_name> is set.
259  
260 =item C<B<delay>>
261  
262 Optional, number of days to receive the item.
263  
264 =item C<B<chars>>
265  
266 Optional, list of L<Business::cXML::Characteristic> that define this specific
267 product item (colors, sizes, etc.) The item will be deemed "configurable" if
268 there are any characteristics.
269  
270 =item C<B<url>>
271  
272 Optional
273  
274 =item C<B<shipping>>
275  
276 Optional, L<Business::cXML::Amount> object of type C<Shipping>
277  
278 =item C<B<tax>>
279  
280 Optional, L<Business::cXML::Amount> object of type C<Tax>
281  
282 =back
283  
284 =head1 AUTHOR
285  
286 Stéphane Lavergne L<https://github.com/vphantom>
287  
288 =head1 ACKNOWLEDGEMENTS
289  
290 Graph X Design Inc. L<https://www.gxd.ca/> sponsored this project.
291  
292 =head1 COPYRIGHT & LICENSE
293  
294 Copyright (c) 2017-2018 Stéphane Lavergne L<https://github.com/vphantom>
295  
296 Permission is hereby granted, free of charge, to any person obtaining a copy
297 of this software and associated documentation files (the "Software"), to deal
298 in the Software without restriction, including without limitation the rights
299 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
300 copies of the Software, and to permit persons to whom the Software is
301 furnished to do so, subject to the following conditions:
302  
303 The above copyright notice and this permission notice shall be included in all
304 copies or substantial portions of the Software.
305  
306 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
307 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
308 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
309 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
310 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
311 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
312 SOFTWARE.
313  
314 =cut
315  
316 1 1;
↑ Summary cXML/Transmission.pm »