Webservice/OVH/Order/Cart/Item.pm

filter: Statementstmt 11.5% 11 / 95 Branchbran 0.0% 0 / 38 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 15.0% 3 / 20 Podpod 100% 15 / 15 totaltotal 17.2% 29 / 168 CC 20 SCAR 27.7
CC
20
Cov
8%
_new
42.0
configuration_add
30.0
configuration_delete
20.0
CRAP 16.0
« Webservice/OVH/Helper.pm ↑ Summary Webservice/OVH/Me/Order/Detail.pm »
1 package Webservice::OVH::Order::Cart::Item;
2  
3 =encoding utf-8
4  
5 =head1 NAME
6  
7 Webservice::OVH::Order::Cart::Item
8  
9 =head1 SYNOPSIS
10  
11 use Webservice::OVH;
12  
13 my $ovh = Webservice::OVH->new_from_json("credentials.json");
14  
15 my $cart = $ovh->order->new_cart(ovh_subsidiary => 'DE');
16  
17 my $items = $cart->items;
18  
19 =head1 DESCRIPTION
20  
21 Provides info for a specific cart item.
22  
23 =head1 METHODS
24  
25 =cut
26  
27 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 36 ▶use Carp qw{ carp croak };
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 36 our $VERSION = 0.48;
32  
33 =head2 _new
34  
35 Internal Method to create the Item object.
36 This method is not ment to be called directly.
37  
38 =over
39  
40 =item * Parameter: $api_wrapper - ovh api wrapper object, $module - root object, $item_id - api id
41  
42 =item * Return: L<Webservice::OVH::Order::Cart>
43  
44 =item * Synopsis: Webservice::OVH::Order::Cart->_new($ovh_api_wrapper, $cart_id, $module);
45  
46 =back
47  
48 =cut
49  
50 0 ▶sub _new {
Subroutine _new: not called CC=6 SCAR=37.4
51  
52 0 my ( $class, %params ) = @_;
53  
54 0 ▶ die "Missing module" unless $params{module};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"module"} 0 0 0
55 0 ▶ die "Missing wrapper" unless $params{wrapper};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"wrapper"} 0 0 0
56 0 ▶ die "Missing id" unless $params{id};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"id"} 0 0 0
57 0 ▶ die "Missing cart" unless $params{cart};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"cart"} 0 0 0
58  
59 0 my $module = $params{module};
60 0 my $api_wrapper = $params{wrapper};
61 0 my $item_id = $params{id};
62 0 my $cart = $params{cart};
63  
64 0 my $cart_id = $cart->id;
65 0 my $response = $api_wrapper->rawCall( method => 'get', path => "/order/cart/$cart_id/item/$item_id", noSignature => 0 );
66 0 ▶ croak $response->error if $response->error;
Branch: 1 branch
BranchTrueFalseTotal
if $response->error 0 0 0
67  
68 0 my $porperties = $response->content;
69  
70 0 my $self = bless { _module => $module, _valid => 1, _api_wrapper => $api_wrapper, _id => $item_id, _properties => $porperties, _cart => $cart }, $class;
71  
72 0 return $self;
73 }
74  
75 =head2 is_valid
76  
77 When the item is deleted on the api side, this method returns 0.
78  
79 =over
80  
81 =item * Return: VALUE
82  
83 =item * Synopsis: print "Valid" if $item->is_valid;
84  
85 =back
86  
87 =cut
88  
89 0 ▶sub is_valid {
Subroutine is_valid: not called CC=1 SCAR=6.9
Pod documented
90  
91 0 my ($self) = @_;
92  
93 0 return $self->{_valid};
94 }
95  
96 =head2 _is_valid
97  
98 Intern method to check validity.
99 Difference is that this method carps an error.
100  
101 =over
102  
103 =item * Return: VALUE
104  
105 =item * Synopsis: $item->_is_valid;
106  
107 =back
108  
109 =cut
110  
111 0 ▶sub _is_valid {
Subroutine _is_valid: not called CC=2 SCAR=17.9
112  
113 0 my ($self) = @_;
114  
115 0 my $item_id = $self->id;
116 0 ▶ carp "Item $item_id is not valid anymore" unless $self->is_valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_valid 0 0 0
117 0 return $self->is_valid;
118 }
119  
120 =head2 _is_valid
121  
122 Gets the associated cart.
123  
124 =over
125  
126 =item * Return: L<Webservice::OVH::Order::Cart>
127  
128 =item * Synopsis: my $cart = $item->cart;
129  
130 =back
131  
132 =cut
133  
134 0 ▶sub cart {
Subroutine cart: not called CC=1 SCAR=6.9
Pod documented
135  
136 0 my ($self) = @_;
137  
138 0 return $self->{_cart};
139 }
140  
141 =head2 id
142  
143 Returns the api id.
144  
145 =over
146  
147 =item * Return: VALUE
148  
149 =item * Synopsis: my $id = $item->id;
150  
151 =back
152  
153 =cut
154  
155 0 ▶sub id {
Subroutine id: not called CC=1 SCAR=6.9
Pod documented
156  
157 0 my ($self) = @_;
158  
159 0 return $self->{_id};
160 }
161  
162 =head2 properties
163  
164 Retrieves properties.
165 This method updates the intern property variable.
166  
167 =over
168  
169 =item * Return: HASH
170  
171 =item * Synopsis: my $properties = $item->properties;
172  
173 =back
174  
175 =cut
176  
177 0 ▶sub properties {
Subroutine properties: not called CC=3 SCAR=24.8
Pod documented
178  
179 0 my ($self) = @_;
180  
181 0 ▶ return unless $self->_is_valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_valid 0 0 0
182  
183 0 my $api = $self->{_api_wrapper};
184 0 my $cart_id = $self->{_cart}->id;
185 0 my $item_id = $self->id;
186 0 my $response = $api->rawCall( method => 'get', path => "/order/cart/$cart_id/item/$item_id", noSignature => 0 );
187 0 ▶ croak $response->error if $response->error;
Branch: 1 branch
BranchTrueFalseTotal
if $response->error 0 0 0
188  
189 0 $self->{_properties} = $response->content;
190 0 return $self->{_properties};
191 }
192  
193 =head2 configuration_add
194  
195 Setup configuration item for the product
196  
197 =over
198  
199 =item * Return: L<HASHREF>
200  
201 =item * Synopsis: my $configurations = $item->configuration_add;
202  
203 =back
204  
205 =cut
206  
207 0 ▶sub configuration_add {
Subroutine configuration_add: not called CC=5 SCAR=34.0
Pod documented
208  
209 0 my ($self, $label, $value) = @_;
210  
211 0 ▶ return unless $self->_is_valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_valid 0 0 0
212  
213 0 my $api = $self->{_api_wrapper};
214 0 my $cart_id = $self->{_cart}->id;
215 0 my $item_id = $self->id;
216  
217 0 ▶ croak "Missing label" unless $label;
Branch: 1 branch
BranchTrueFalseTotal
unless $label 0 0 0
218 0 ▶ croak "Missing value" unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 0 0 0
219  
220 0 my $body = {label => $label, value => $value};
221 0 my $response = $api->rawCall( method => 'post', path => "/order/cart/$cart_id/item/$item_id/configuration", body => $body, noSignature => 0 );
222 0 ▶ croak $response->error if $response->error;
Branch: 1 branch
BranchTrueFalseTotal
if $response->error 0 0 0
223  
224 0 return $response->content;
225 }
226  
227 =head2 configuration_delete
228  
229 Delete configuration item
230  
231 =over
232  
233 =item * Return: L<HASHREF>
234  
235 =item * Synopsis: my $configurations = $item->configuration_delete;
236  
237 =back
238  
239 =cut
240  
241 0 ▶sub configuration_delete {
Subroutine configuration_delete: not called CC=4 SCAR=30.0
Pod documented
242  
243 0 my ($self, $configuration_id) = @_;
244  
245 0 ▶ return unless $self->_is_valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_valid 0 0 0
246  
247 0 my $api = $self->{_api_wrapper};
248 0 my $cart_id = $self->{_cart}->id;
249 0 my $item_id = $self->id;
250  
251 0 ▶ croak "Missing configuration_id" unless $configuration_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $configuration_id 0 0 0
252  
253 0 my $response = $api->rawCall( method => 'delete', path => "/order/cart/$cart_id/item/$item_id/configuration/$configuration_id", body => {}, noSignature => 0 );
254 0 ▶ croak $response->error if $response->error;
Branch: 1 branch
BranchTrueFalseTotal
if $response->error 0 0 0
255  
256 0 return $response->content;
257 }
258  
259 =head2 configurations
260  
261 Exposed property value.
262  
263 =over
264  
265 =item * Return: L<ARRAY>
266  
267 =item * Synopsis: my $configurations = $item->configurations;
268  
269 =back
270  
271 =cut
272  
273 0 ▶sub configurations {
Subroutine configurations: not called CC=1 SCAR=6.9
Pod documented
274  
275 0 my ($self) = @_;
276  
277 0 return $self->{_properties}->{configurations};
278 }
279  
280 =head2 duration
281  
282 Exposed property value.
283  
284 =over
285  
286 =item * Return: VALUE
287  
288 =item * Synopsis: my $duration = $item->duration;
289  
290 =back
291  
292 =cut
293  
294 0 ▶sub duration {
Subroutine duration: not called CC=1 SCAR=6.9
Pod documented
295  
296 0 my ($self) = @_;
297  
298 0 return $self->{_properties}->{duration};
299 }
300  
301 =head2 offer_id
302  
303 Exposed property value.
304  
305 =over
306  
307 =item * Return: VALUE
308  
309 =item * Synopsis: my $offer_id = $item->offer_id;
310  
311 =back
312  
313 =cut
314  
315 0 ▶sub offer_id {
Subroutine offer_id: not called CC=1 SCAR=6.9
Pod documented
316  
317 0 my ($self) = @_;
318  
319 0 return $self->{_properties}->{offerId};
320 }
321  
322 =head2 options
323  
324 Exposed property value.
325  
326 =over
327  
328 =item * Return: HASH
329  
330 =item * Synopsis: my $options = $item->options;
331  
332 =back
333  
334 =cut
335  
336 0 ▶sub options {
Subroutine options: not called CC=1 SCAR=6.9
Pod documented
337  
338 0 my ($self) = @_;
339  
340 0 return $self->{_properties}->{options};
341 }
342  
343 =head2 prices
344  
345 Exposed property value.
346  
347 =over
348  
349 =item * Return: HASH
350  
351 =item * Synopsis: my $prices = $item->prices;
352  
353 =back
354  
355 =cut
356  
357 0 ▶sub prices {
Subroutine prices: not called CC=1 SCAR=6.9
Pod documented
358  
359 0 my ($self) = @_;
360  
361 0 return $self->{_properties}->{prices};
362 }
363  
364 =head2 product_id
365  
366 Exposed property value.
367  
368 =over
369  
370 =item * Return: VALUE
371  
372 =item * Synopsis: my $product_id = $item->product_id;
373  
374 =back
375  
376 =cut
377  
378 0 ▶sub product_id {
Subroutine product_id: not called CC=1 SCAR=6.9
Pod documented
379  
380 0 my ($self) = @_;
381  
382 0 return $self->{_properties}->{productId};
383 }
384  
385 =head2 settings
386  
387 Exposed property value.
388  
389 =over
390  
391 =item * Return: HASH
392  
393 =item * Synopsis: my $settings = $item->settings;
394  
395 =back
396  
397 =cut
398  
399 0 ▶sub settings {
Subroutine settings: not called CC=1 SCAR=6.9
Pod documented
400  
401 0 my ($self) = @_;
402  
403 0 return $self->{_properties}->{settings};
404 }
405  
406 =head2 available_configuration
407  
408 Exposed property value.
409  
410 =over
411  
412 =item * Return: L<ARRAY>
413  
414 =item * Synopsis: my $available_configuration = $item->available_configuration;
415  
416 =back
417  
418 =cut
419  
420 0 ▶sub available_configuration {
Subroutine available_configuration: not called CC=3 SCAR=24.8
Pod documented
421  
422 0 my ($self) = @_;
423  
424 0 ▶ return unless $self->_is_valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_valid 0 0 0
425  
426 0 my $api = $self->{_api_wrapper};
427 0 my $cart_id = $self->{_cart}->id;
428 0 my $item_id = $self->id;
429  
430 0 my $response = $api->rawCall( method => 'get', path => "/order/cart/$cart_id/item/$item_id/configuration", noSignature => 0 );
431 0 ▶ croak $response->error if $response->error;
Branch: 1 branch
BranchTrueFalseTotal
if $response->error 0 0 0
432  
433 0 return $response->content;
434 }
435  
436 =head2 delete
437  
438 Deletes the item and sets the object to invalid.
439  
440 =over
441  
442 =item * Synopsis: $item->delete;
443  
444 =back
445  
446 =cut
447  
448 0 ▶sub delete {
Subroutine delete: not called CC=3 SCAR=24.8
Pod documented
449  
450 0 my ($self) = @_;
451  
452 0 ▶ return unless $self->_is_valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_valid 0 0 0
453  
454 0 my $api = $self->{_api_wrapper};
455 0 my $cart_id = $self->{_cart}->id;
456 0 my $item_id = $self->id;
457 0 my $response = $api->rawCall( method => 'delete', path => "/order/cart/$cart_id/item/$item_id", noSignature => 0 );
458 0 ▶ croak $response->error if $response->error;
Branch: 1 branch
BranchTrueFalseTotal
if $response->error 0 0 0
459  
460 0 $self->{_valid} = 0;
461 }
462  
463 36 1;
« Webservice/OVH/Helper.pm ↑ Summary Webservice/OVH/Me/Order/Detail.pm »