blib/lib/BZ/Client/Product.pm untested

filter: Statementstmt 0.0% 0 / 98 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 25 Podpod 0.0% 0 / 22 totaltotal 0.0% 0 / 189 CC 21 SCAR 19.2
CC
21
Cov
0%
_get
12.0
components
12.0
versions
12.0
CRAP 6.8
1 #!/bin/false
2 # PODNAME: BZ::Client::Product
3 # ABSTRACT: Client side representation of a product in Bugzilla
4 # vim: softtabstop=4 tabstop=4 shiftwidth=4 ft=perl expandtab smarttab
5  
6 use strict;
7 use warnings 'all';
8  
9 package BZ::Client::Product;
10 $BZ::Client::Product::VERSION = '4.4001';
11  
12 use parent qw( BZ::Client::API );
13  
14 # See https://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Product.html
15  
16 ## functions
17  
18 sub create {
19 my(undef, $client, $params) = @_;
20 return _create($client, 'Product.create', $params);
21 }
22  
23 sub update {
24 my($class, $client, $params) = @_;
25 return $class->_returns_array($client, 'Product.update', $params, 'components');
26 }
27  
28 # convenience function
29 sub _get_list {
30 my($class, $methodName, $client) = @_;
31 my $result = $class->api_call($client, $methodName);
32 my $ids = $result->{'ids'};
33 if (!$ids || 'ARRAY' ne ref($ids)) {
34 $class->error($client, 'Invalid reply by server, expected array of ids.');
35 }
36 return $ids
37 }
38  
39 sub get_selectable_products {
40 my($class, $client) = @_;
41 $client->log('debug', $class . '::get_selectable_products: Asking');
42 my $result = $class->_get_list('Product.get_selectable_products', $client);
43 $client->log('debug', $class . '::get_selectable_products: Got ' . @$result);
44 return wantarray ? @$result : $result
45 }
46  
47 sub get_enterable_products {
48 my($class, $client) = @_;
49 $client->log('debug', $class . '::get_enterable_products: Asking');
50 my $result = $class->_get_list('Product.get_enterable_products', $client);
51 $client->log('debug', $class . '::get_enterable_products: Got ' . @$result);
52 return wantarray ? @$result : $result
53 }
54  
55 sub get_accessible_products {
56 my($class, $client) = @_;
57 $client->log('debug', $class . '::get_accessible_products: Asking');
58 my $result = $class->_get_list('Product.get_accessible_products', $client);
59 $client->log('debug', $class . '::get_accessible_products: Got ' . @$result);
60 return wantarray ? @$result : $result
61 }
62  
63 # do everything in one place
64 sub _get {
65 my($class, $client, $result) = @_;
66 my $products = $result->{'products'};
67 if (!$products or 'ARRAY' ne ref $products) {
68 $class->error($client, 'Invalid reply by server, expected array of products.');
69 }
70 my @result;
71 for my $product (@$products) {
72 push @result, $class->new(
73 id => $product->{'id'},
74 name => $product->{'name'},
75 description => $product->{'description'},
76 internals => $product->{'internals'}
77 );
78 }
79 return wantarray ? @result : \@result
80 }
81  
82 sub get_products {
83 my($class, $client, $params) = @_;
84 my $result = $class->api_call($client, 'Product.get_products', $params);
85 return $class->_get($client, $result)
86 }
87  
88 sub get {
89 my($class, $client, $params) = @_;
90 my $result = $class->api_call($client, 'Product.get', $params);
91 return $class->_get($client, $result)
92 }
93  
94 ## rw methods
95  
96 sub name {
97 my $self = shift;
98 if (@_) {
99 $self->{'name'} = shift;
100 }
101 else {
102 return $self->{name};
103 }
104 }
105  
106 sub description {
107 my $self = shift;
108 if (@_) {
109 $self->{'description'} = shift;
110 }
111 else {
112 return $self->{'description'};
113 }
114 }
115  
116 sub version {
117 my $self = shift;
118 if (@_) {
119 $self->{'version'} = shift;
120 }
121 else {
122 return $self->{'version'};
123 }
124 }
125  
126 ## boolean
127 sub has_unconfirmed {
128 my $self = shift;
129 if (@_) {
130 $self->{'has_unconfirmed'} = shift;
131 }
132 else {
133 return $self->{'has_unconfirmed'};
134 }
135 }
136  
137 sub classification {
138 my $self = shift;
139 if (@_) {
140 $self->{'classification'} = shift;
141 }
142 else {
143 return $self->{'classification'};
144 }
145 }
146  
147 sub default_milestone {
148 my $self = shift;
149 if (@_) {
150 $self->{'default_milestone'} = shift;
151 }
152 else {
153 return $self->{'default_milestone'};
154 }
155 }
156  
157 ## boolean
158 sub is_open {
159 my $self = shift;
160 if (@_) {
161 $self->{'is_open'} = shift;
162 }
163 else {
164 return $self->{'is_open'};
165 }
166 }
167  
168 sub create_series {
169 my $self = shift;
170 if (@_) {
171 $self->{'create_series'} = shift;
172 }
173 else {
174 return $self->{'create_series'};
175 }
176 }
177  
178 ## ro methods
179  
180 sub id { my $self = shift; return $self->{'id'} }
181  
182 sub internals { my $self = shift; return $self->{'internals'} }
183  
184 sub components {
185 my $self = shift;
186 return unless $self->{'components'};
187  
188 return wantarray ? @{$self->{'components'}}
189 : $self->{'components'}
190 }
191  
192  
193 sub versions {
194 my $self = shift;
195 return unless $self->{'versions'};
196  
197 return wantarray ? @{$self->{'versions'}}
198 : $self->{'versions'}
199 }
200  
201  
202 sub milestones {
203 my $self = shift;
204 return unless $self->{'milestones'};
205  
206 return wantarray ? @{$self->{'milestones'}}
207 : $self->{'milestones'}
208 }
209  
210 1;
211  
212 __END__
213  
214 =pod
215  
216 =encoding UTF-8
217  
218 =head1 NAME
219  
220 BZ::Client::Product - Client side representation of a product in Bugzilla
221  
222 =head1 VERSION
223  
224 version 4.4001
225  
226 =head1 SYNOPSIS
227  
228 This class provides methods for accessing and managing products in Bugzilla. Instances
229 of this class are returned by L<BZ::Client::Product::get>.
230  
231 my $client = BZ::Client->new( url => $url,
232 user => $user,
233 password => $password );
234  
235 my $ids = BZ::Client::Product->get_accessible_products( $client );
236 my $products = BZ::Client::Product->get( $client, \%params );
237  
238 =head1 CLASS METHODS
239  
240 This section lists the class methods, which are available in this module.
241  
242 =head2 create
243  
244 $id = BZ::Client::Product->create( $client, \%params );
245  
246 This allows you to create a new Product in Bugzilla.
247  
248 =head3 History
249  
250 Marked as experimental as of Bugzilla 5.0.
251  
252 =head3 Parameters
253  
254 Some params must be set, or an error will be thrown. These params are noted as Required.
255  
256 =over 4
257  
258 =item name
259  
260 I<name> (string) The name of this product. Must be globally unique within Bugzilla.
261  
262 B<Required>.
263  
264 =item description
265  
266 I<description> (string) A description for this product. Allows some simple HTML.
267  
268 B<Required>.
269  
270 =item version
271  
272 I<version> (string) The default version for this product.
273  
274 B<Required>.
275  
276 =item has_unconfirmed
277  
278 I<has_unconfirmed> (boolean) Allow the UNCONFIRMED status to be set on bugs in this product. Default: true.
279  
280 =item classification
281  
282 I<classification> (string) The name of the Classification which contains this product.
283  
284 =item default_milestone
285  
286 I<default_milestone> (string) The default milestone for this product. Default '---'.
287  
288 =item is_open
289  
290 I<is_open> (boolean) True if the product is currently allowing bugs to be entered into it. Default: true.
291  
292 =item create_series
293  
294 I<create_series> (boolean) True if you want series for New Charts to be created for this new product. Default: true.
295  
296 =back
297  
298 =head3 Returns
299  
300 The ID of the newly-filed product.
301  
302 =head3 Errors
303  
304 =over 4
305  
306 =item 51 - Classification does not exist
307  
308 You must specify an existing classification name.
309  
310 =item 700 - Product blank name
311  
312 You must specify a non-blank name for this product.
313  
314 =item 701 - Product name too long
315  
316 The name specified for this product was longer than the maximum allowed length.
317  
318 =item 702 - Product name already exists
319  
320 You specified the name of a product that already exists. (Product names must be globally unique in Bugzilla.)
321  
322 =item 703 - Product must have description
323  
324 You must specify a description for this product.
325  
326 =item 704 - Product must have version
327  
328 You must specify a version for this product.
329  
330 =back
331  
332 =head2 update
333  
334 $id = BZ::Client::Product->update( $client, \%params );
335  
336 This allows you to update a Group in Bugzilla.
337  
338 =head3 History
339  
340 As of Bugzilla 5.0. this is marked as experimental.
341  
342 Added in Bugzilla 4.4.
343  
344 =head3 Parameters
345  
346 Either L</ids> or L</names> is required to select the bugs you want to update.
347  
348 All other values change or set something in the product.
349  
350 =over 4
351  
352 =item ids
353  
354 I<ids> (array) Numeric ID's of the products you wish to update.
355  
356 =item names
357  
358 I<names> (array) Text names of the products that you wish to update.
359  
360 =item default_milestone
361  
362 I<default_milestone> (string) When a new bug is filed, what milestone does it
363 get by default if the user does not choose one? Must represent a milestone that
364 is valid for this product.
365  
366 =item description
367  
368 I<description> (string) Update the long description for these products to this value.
369  
370 =item has_unconfirmed
371  
372 I<has_unconfirmed> (boolean) Allow the UNCONFIRMED status to be set on bugs in this products.
373  
374 =item is_open
375  
376 I<is_open> (boolean) True if the product is currently allowing bugs to be entered into it.
377 Otherwise false.
378  
379 =back
380  
381 =head3 Returns
382  
383 An array or arrayref of hashes containing the following:
384  
385 =over 4
386  
387 =item id
388  
389 I<id> (int) The ID of the product that was updated.
390  
391 =item changes
392  
393 The changes that were actually done on this product. The keys are the names of the
394 fields that were changed, and the values are a hash with two keys:
395  
396 =over 4
397  
398 =item added
399  
400 I<added> (string) The value that this field was changed to.
401  
402 =item removed
403  
404 I<removed> (string) The value that was previously set in this field.
405  
406 =back
407  
408 Note that booleans will be represented with the strings '1' and '0'.
409  
410 Here's an example of what a return value might look like:
411  
412 [
413 {
414 id => 123,
415 changes => {
416 name => {
417 removed => 'FooName',
418 added => 'BarName'
419 },
420 has_unconfirmed => {
421 removed => '1',
422 added => '0',
423 }
424 }
425 },
426 \%etc
427 ],
428  
429 =back
430  
431 =head3 Errors
432  
433 =over 4
434  
435 =item 700 - Product blank name
436  
437 You must specify a non-blank name for this product.
438  
439 =item 701 - Product name too long
440  
441 The name specified for this product was longer than the maximum allowed length.
442  
443 =item 702 - Product name already exists
444  
445 You specified the name of a product that already exists. (Product names must be globally unique in Bugzilla.)
446  
447 =item 703 - Product must have description
448  
449 You must specify a description for this product.
450  
451 =item 705 - Product must define a default milestone
452  
453 You must define a default milestone.
454  
455 =back
456  
457 =head2 get_selectable_products
458  
459 @products = BZ::Client::Product->get_selectable_products( $client );
460 $products = BZ::Client::Product->get_selectable_products( $client );
461  
462 Returns a list of the ID's of the products the user can search on.
463  
464 =head3 History
465  
466 Marked as experimental as of Bugzilla 5.0.
467  
468 =head3 Parameters
469  
470 (none)
471  
472 =head3 Returns
473  
474 An array of product ID's
475  
476 =head3 Errors
477  
478 (none)
479  
480 =head2 get_enterable_products
481  
482 @products = BZ::Client::Product->get_enterable_products( $client );
483 $products = BZ::Client::Product->get_enterable_products( $client );
484  
485 Returns a list of the ID's of the products the user can enter bugs against.
486  
487 =head3 History
488  
489 Marked as experimental as of Bugzilla 5.0.
490  
491 =head3 Parameters
492  
493 (none)
494  
495 =head3 Returns
496  
497 An array of product ID's
498  
499 =head3 Errors
500  
501 (none)
502  
503 =head2 get_accessible_products
504  
505 @products = BZ::Client::Product->get_selectable_products( $client );
506 $products = BZ::Client::Product->get_selectable_products( $client );
507  
508 Returns a list of the ID's of the products the user can search or enter bugs against.
509  
510 =head3 History
511  
512 Marked as unstable as of Bugzilla 5.0.
513  
514 =head3 Parameters
515  
516 (none)
517  
518 =head3 Returns
519  
520 An array of product ID's
521  
522 =head3 Errors
523  
524 (none)
525  
526 =head2 get
527  
528 @products = BZ::Client::Product->get( $client, \%params );
529 $products = BZ::Client::Product->get( $client, \%params );
530  
531 Returns a list of BZ::Client::Product instances based on the given parameters.
532  
533 Note, that if the user tries to access a product that is not in the list of
534 accessible products for the user, or a product that does not exist, that is
535 silently ignored, and no information about that product is returned.
536  
537 =head3 Parameters
538  
539 In addition to the parameters below, this method also accepts the standard
540 L<BZ::Client::Bug/include_fields> and L<BZ::Client::Bug/exclude_fields> arguments.
541  
542 Note: You must at least specify one of L</ids> or L</names>.
543  
544 =over 4
545  
546 =item ids
547  
548 I<ids> (array) An array of product ID's.
549  
550 =item names
551  
552 I<names> (array) An array of product names.
553  
554 Added in Bugzilla 4.2.
555  
556 =item type
557  
558 The group of products to return. Valid values are: C<accessible> (default),
559 C<selectable>, and C<enterable>. L</type> can be a single value or an array
560 of values if more than one group is needed with duplicates removed.
561  
562 =back
563  
564 =head3 Returns
565  
566 An array or arrayref of bug instance objects with the given ID's.
567  
568 See L</INSTANCE METHODS> for how to use them.
569  
570 =head3 Errors
571  
572 (none)
573  
574 =head2 get_products
575  
576 Compatibilty with Bugzilla 3.0 API. Exactly equivalent to L</get>.
577  
578 =head2 new
579  
580 my $product = BZ::Client::Product->new( id => $id,
581 name => $name,
582 description => $description );
583  
584 Creates a new instance with the given ID, name, and description.
585  
586 =head1 INSTANCE METHODS
587  
588 This section lists the modules instance methods.
589  
590 =head2 id
591  
592 $id = $product->id();
593  
594 Gets the products ID.
595  
596 Read only.
597  
598 =head2 name
599  
600 $name = $product->name();
601 $product->name( $name );
602  
603 Gets or sets the products name.
604  
605 =head2 description
606  
607 $description = $product->description();
608 $product->description( $description );
609  
610 Gets or sets the products description.
611  
612 =head2 version
613  
614 $version = $product->version();
615 $product->version( $version );
616  
617 Gets or sets the products version.
618  
619 (Set only works for new products, not updates)
620  
621 =head2 has_unconfirmed
622  
623 $bool = $product->has_unconfirmed();
624 $product->has_unconfirmed( $bool );
625  
626 Gets or sets the products has_unconfirmed setting.
627  
628 Added in Bugzilla 4.2 as a replacement for L</internals>.
629  
630 =head2 classification
631  
632 $classification = $product->classification();
633 $product->classification( $classification );
634  
635 Gets or sets the products classification.
636  
637 Added in Bugzilla 4.2 as a replacement for L</internals>.
638  
639 =head2 default_milestone
640  
641 $milestone = $product->default_milestone();
642 $product->default_milestone( $milestone );
643  
644 Gets or sets the products default milestone.
645  
646 Added in Bugzilla 4.2 as a replacement for L</internals>.
647  
648 =head2 is_open
649  
650 $bool = $product->is_open();
651 $product->is_open( $bool );
652  
653 Gets or sets the products is_open setting.
654  
655 =head2 create_series
656  
657 $series = $product->create_series();
658 $product->create_series( $series );
659  
660 Gets or sets the products is_open setting.
661  
662 =head2 components
663  
664 @components = $product->components();
665 $components = $product->components();
666  
667 An array of hashes, where each hash describes a component, and has the following items:
668  
669 =over 4
670  
671 =item id
672  
673 I<id> (int) An integer ID uniquely identifying the component in this installation only.
674  
675 =item name
676  
677 I<name> (string) The name of the component. This is a unique identifier for this component.
678  
679 =item description
680  
681 I<description> (string) A description of the component, which may contain HTML.
682  
683 =item default_assigned_to
684  
685 I<default_assigned_to> (string) The login name of the user to whom new bugs will be assigned
686 by default.
687  
688 =item default_qa_contact
689  
690 I<default_qa_contact> (string) The login name of the user who will be set as the QA Contact
691 for new bugs by default. Empty string if the QA contact is not defined.
692  
693 =item sort_key
694  
695 I<sort_key> (int) Components, when displayed in a list, are sorted first by this integer and
696 then secondly by their name.
697  
698 =item is_active
699  
700 I<is_active> (boolean) A boolean indicating if the component is active. Inactive components
701 are not enabled for new bugs.
702  
703 =item flag_types
704  
705 Added in Bugzilla 4.4.
706  
707 A hash containing the two items bug and attachment that each contains an array of hashes, where
708 each hash describes a flagtype, and has the following items:
709  
710 =over 4
711  
712 =item id
713  
714 I<id> (int) Returns the ID of the flagtype.
715  
716 =item name
717  
718 I<name> (string) Returns the name of the flagtype.
719  
720 =item description
721  
722 I<description> (string) Returns the description of the flagtype.
723  
724 =item cc_list
725  
726 I<cc_list> (string) Returns the concatenated CC list for the flagtype, as a single string.
727  
728 =item sort_key
729  
730 I<sort_key> (int) Returns the sortkey of the flagtype.
731  
732 =item is_active
733  
734 I<is_active> (boolean) Returns whether the flagtype is active or disabled. Flags being in a
735 disabled flagtype are not deleted. It only prevents you from adding new flags to it.
736  
737 =item is_requestable
738  
739 I<is_requestable> (boolean) Returns whether you can request for the given flagtype (i.e.
740 whether the '?' flag is available or not).
741  
742 =item is_requesteeble
743  
744 I<is_requesteeble> (boolean) Returns whether you can ask someone specifically or not.
745  
746 =item is_multiplicable
747  
748 I<is_multiplicable> (boolean) Returns whether you can have more than one flag for the given
749 flagtype in a given bug/attachment.
750  
751 =item grant_group
752  
753 I<grant_group> (int) the group ID that is allowed to grant/deny flags of this type. If the
754 item is not included all users are allowed to grant/deny this flagtype.
755  
756 =item request_group
757  
758 I<request_group> (int) the group ID that is allowed to request the flag if the flag is of
759 the type requestable. If the item is not included all users are allowed request this flagtype.
760  
761 =back
762  
763 =back
764  
765 Added in Bugzilla 4.2 as a replacement for L</internals>.
766  
767 =head2 versions
768  
769 $versions = $product->versions();
770  
771 Added in Bugzilla 4.2 as a replacement for L</internals>.
772  
773 Returns an array of hashes, where each hash describes a version, and has the
774 following items: C<name>, C<sort_key> and C<is_active>.
775  
776 =head2 milestones
777  
778 $milestones = $product->milestones();
779  
780 Returns an array of hashes, where each hash describes a milestones, and has the
781 following items: C<name>, C<sort_key> and C<is_active>.
782  
783 Added in Bugzilla 4.2 as a replacement for L</internals>.
784  
785 =head2 internals
786  
787 Returned by L</get> until version 4.2, at which point it was dropped.
788 Remains for compatibility. Please move away from using it asap.
789  
790 =head1 EXCEPTION HANDLING
791  
792 See L<BZ::Client::Exception>
793  
794 =head1 SEE ALSO
795  
796 L<BZ::Client>, L<BZ::Client::API>, L<Bugzilla API|https://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Product.html>
797  
798 =head1 AUTHORS
799  
800 =over 4
801  
802 =item *
803  
804 Dean Hamstead <dean@bytefoundry.com.au>
805  
806 =item *
807  
808 Jochen Wiedmann <jochen.wiedmann@gmail.com>
809  
810 =back
811  
812 =head1 COPYRIGHT AND LICENSE
813  
814 This software is copyright (c) 2017 by Dean Hamstad.
815  
816 This is free software; you can redistribute it and/or modify it under
817 the same terms as the Perl 5 programming language system itself.
818  
819 =cut