| 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.91'; | ||
| 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($class, $client, $params) = @_; | ||
| 20 | return $class->_create($client, 'Product.create', $params); | ||
| 21 | } | ||
| 22 | |||
| 23 | sub update { | ||
| 24 | my($class, $client, $params) = @_; | ||
| 25 | return $class->_returns_array($client, 'Product.update', $params, 'products'); | ||
| 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(%{$product}); | ||
| 73 | } | ||
| 74 | return wantarray ? @result : \@result | ||
| 75 | } | ||
| 76 | |||
| 77 | sub get_products { | ||
| 78 | my($class, $client, $params) = @_; | ||
| 79 | my $result = $class->api_call($client, 'Product.get_products', $params); | ||
| 80 | return $class->_get($client, $result) | ||
| 81 | } | ||
| 82 | |||
| 83 | sub get { | ||
| 84 | my($class, $client, $params) = @_; | ||
| 85 | my $result = $class->api_call($client, 'Product.get', $params); | ||
| 86 | return $class->_get($client, $result) | ||
| 87 | } | ||
| 88 | |||
| 89 | ## rw methods | ||
| 90 | |||
| 91 | sub name { | ||
| 92 | my $self = shift; | ||
| 93 | if (@_) { | ||
| 94 | $self->{'name'} = shift; | ||
| 95 | } | ||
| 96 | else { | ||
| 97 | return $self->{name}; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | |||
| 101 | sub description { | ||
| 102 | my $self = shift; | ||
| 103 | if (@_) { | ||
| 104 | $self->{'description'} = shift; | ||
| 105 | } | ||
| 106 | else { | ||
| 107 | return $self->{'description'}; | ||
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | sub version { | ||
| 112 | my $self = shift; | ||
| 113 | if (@_) { | ||
| 114 | $self->{'version'} = shift; | ||
| 115 | } | ||
| 116 | else { | ||
| 117 | return $self->{'version'}; | ||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | ## boolean | ||
| 122 | sub has_unconfirmed { | ||
| 123 | my $self = shift; | ||
| 124 | if (@_) { | ||
| 125 | $self->{'has_unconfirmed'} = shift; | ||
| 126 | } | ||
| 127 | else { | ||
| 128 | return $self->{'has_unconfirmed'}; | ||
| 129 | } | ||
| 130 | } | ||
| 131 | |||
| 132 | sub classification { | ||
| 133 | my $self = shift; | ||
| 134 | if (@_) { | ||
| 135 | $self->{'classification'} = shift; | ||
| 136 | } | ||
| 137 | else { | ||
| 138 | return $self->{'classification'}; | ||
| 139 | } | ||
| 140 | } | ||
| 141 | |||
| 142 | sub default_milestone { | ||
| 143 | my $self = shift; | ||
| 144 | if (@_) { | ||
| 145 | $self->{'default_milestone'} = shift; | ||
| 146 | } | ||
| 147 | else { | ||
| 148 | return $self->{'default_milestone'}; | ||
| 149 | } | ||
| 150 | } | ||
| 151 | |||
| 152 | ## boolean | ||
| 153 | sub is_open { | ||
| 154 | my $self = shift; | ||
| 155 | if (@_) { | ||
| 156 | $self->{'is_open'} = shift; | ||
| 157 | } | ||
| 158 | else { | ||
| 159 | return $self->{'is_open'}; | ||
| 160 | } | ||
| 161 | } | ||
| 162 | |||
| 163 | sub create_series { | ||
| 164 | my $self = shift; | ||
| 165 | if (@_) { | ||
| 166 | $self->{'create_series'} = shift; | ||
| 167 | } | ||
| 168 | else { | ||
| 169 | return $self->{'create_series'}; | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 173 | ## ro methods | ||
| 174 | |||
| 175 | sub id { my $self = shift; return $self->{'id'} } | ||
| 176 | |||
| 177 | sub internals { my $self = shift; return $self->{'internals'} } | ||
| 178 | |||
| 179 | sub components { | ||
| 180 | my $self = shift; | ||
| 181 | return unless $self->{'components'}; | ||
| 182 | |||
| 183 | return wantarray ? @{$self->{'components'}} | ||
| 184 | : $self->{'components'} | ||
| 185 | } | ||
| 186 | |||
| 187 | |||
| 188 | sub versions { | ||
| 189 | my $self = shift; | ||
| 190 | return unless $self->{'versions'}; | ||
| 191 | |||
| 192 | return wantarray ? @{$self->{'versions'}} | ||
| 193 | : $self->{'versions'} | ||
| 194 | } | ||
| 195 | |||
| 196 | |||
| 197 | sub milestones { | ||
| 198 | my $self = shift; | ||
| 199 | return unless $self->{'milestones'}; | ||
| 200 | |||
| 201 | return wantarray ? @{$self->{'milestones'}} | ||
| 202 | : $self->{'milestones'} | ||
| 203 | } | ||
| 204 | |||
| 205 | 1; | ||
| 206 | |||
| 207 | __END__ |