blib/lib/BZ/Client/Bug/Comment.pm untested

filter: Statementstmt 0.0% 0 / 74 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 10 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 15 totaltotal 0.0% 0 / 135 CC 10 SCAR 28.3
CC
10
Cov
0%
get
56.0
add
6.0
render
6.0
CRAP 16.9
1 #!/bin/false
2 # PODNAME: BZ::Client::Bug::Comment
3 # ABSTRACT: Client side representation of an Comment on a Bug in Bugzilla
4  
5 use strict;
6 use warnings 'all';
7  
8 package BZ::Client::Bug::Comment;
9 $BZ::Client::Bug::Comment::VERSION = '4.9';
10 use parent qw( BZ::Client::API );
11  
12 # See https://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html
13 # These are in order as per the above
14  
15 ## functions
16  
17 sub get {
18 my($class, $client, $params) = @_;
19 unless (ref $params) {
20 $params = { id => $params };
21 }
22 $client->log('debug', __PACKAGE__ . "::get: Asking for $params");
23 my $result = $class->api_call($client, 'Bug.comments', $params);
24  
25 if (my $comments = $result->{comments}) {
26 if (!$comments || 'HASH' ne ref($comments)) {
27 $class->error($client,
28 'Invalid reply by server, expected hash of comments.');
29 }
30 for my $id (keys %{$comments}) {
31 $comments->{$id} = __PACKAGE__->new( %{$comments->{$id}} );
32 }
33 }
34  
35 if (my $bugs = $result->{bugs}) {
36 if (!$bugs || 'HASH' ne ref($bugs)) {
37 $class->error($client,
38 'Invalid reply by server, expected array of bugs.');
39 }
40 for my $id (keys %{$bugs}) {
41 $bugs->{$id} = [
42 map { __PACKAGE__->new( %{$_} ) } @{$bugs->{$id}->{comments}} ];
43 }
44 }
45  
46 $client->log('debug', __PACKAGE__ . '::get: Got keys: ' . join(', ', sort keys %{$result}));
47  
48 return wantarray ? %{$result} : $result
49 }
50  
51 sub add {
52 my($class, $client, $params) = @_;
53 $client->log('debug', __PACKAGE__ . '::add: Adding');
54 my $result = $class->api_call($client, 'Bug.add_comment', $params);
55 my $id = $result->{'id'};
56 if (!$id) {
57 $class->error($client, 'Invalid reply by server, expected comment ID.');
58 }
59 return $id
60 }
61  
62 sub render {
63 my($class, $client, $params) = @_;
64 $client->log('debug', __PACKAGE__ . '::render: Rendering Comment');
65 my $result = $class->api_call($client, 'Bug.render_comment', $params);
66 my $html = $result->{'html'};
67 if (!$html) {
68 $class->error($client, 'Invalid reply by server, expected HTML.');
69 }
70 return $html
71 }
72  
73 ## rw methods
74  
75 sub bug_id { shift->_accessor('bug_id', @_) }
76  
77 sub comment {
78 my $self = shift;
79 if (@_) {
80 $self->{'text'} = shift;
81 delete $self->{'comment'};
82 }
83 else {
84 return $self->{'text'} || $self->{'comment'}
85 }
86 }
87  
88 sub text { goto &comment }
89  
90 sub is_private { shift->_accessor('is_private', @_) }
91  
92 sub work_time { shift->_accessor('work_time', @_) }
93  
94 ## ro methods
95  
96 sub id { my $self = shift; return $self->{'id'} }
97  
98 sub attachment_id { my $self = shift; return $self->{'attachment_id'} }
99  
100 sub count { my $self = shift; return $self->{'count'} }
101  
102 sub creator { my $self = shift; return $self->{'creator'} || $self->{'author'} }
103  
104 sub author { goto &creator }
105  
106 sub creation_time { my $self = shift; return $self->{'creation_time'} }
107  
108 sub time { goto &creation_time }
109  
110 1;
111  
112 __END__
113  
114 =pod
115  
116 =encoding UTF-8
117  
118 =head1 NAME
119  
120 BZ::Client::Bug::Comment - Client side representation of an Comment on a Bug in Bugzilla
121  
122 =head1 VERSION
123  
124 version 4.9
125  
126 =head1 SYNOPSIS
127  
128 This class provides methods for accessing and managing comments in Bugzilla. Instances
129 of this class are returned by L<BZ::Client::Bug::Comment::get>.
130  
131 my $client = BZ::Client->new( url => $url,
132 user => $user,
133 password => $password );
134  
135 my $comments = BZ::Client::Bug::Comment->get( $client, $ids );
136  
137 =head1 CLASS METHODS
138  
139 This section lists the class methods, which are available in this module.
140  
141 =head2 get
142  
143 my $comments = BZ::Client::Bug::Comment->get( $client, 1234 );
144 my $comments = BZ::Client::Bug::Comment->get( $client, { ids => \@list, commend_ids => \@list } );
145  
146 This allows you to get data about comments, given a list of bugs and/or comment ids.
147  
148 Actual Bugzilla API method is "comments".
149  
150 =head3 History
151  
152 Added in Bugzilla 3.4
153  
154 =head3 Parameters
155  
156 A single scalar is considered a search for L</ids>, otherwise a hash reference must be provided.
157  
158 Note: At least one of L</ids> or L</comment_ids> is required.
159  
160 In addition to the parameters below, this method also accepts the standard L<BZ::Client::Bug/include_fields> and L<BZ::Client::Bug/exclude_fields> arguments.
161  
162 =over 4
163  
164 =item ids
165  
166 I<ids> (array) - An array that can contain both bug ID's and bug aliases. All of the comments (that are visible to you) will be returned for the specified bugs.
167  
168 =item comment_ids
169  
170 I<comment_ids> (array) - An array of integer comment ID's. These comments will be returned individually, separate from any other comments in their respective bugs.
171  
172 =item new_since
173  
174 I<new_since> (L<DateTime>) - If specified, the method will only return comments newer than this time. This only affects comments returned from the L</ids> argument. You will always be returned all comments you request in the I<comment_ids> argument, even if they are older than this date.
175  
176 =back
177  
178 =head3 Returns
179  
180 A hash reference containing two items is returned. e.g.
181  
182 {
183  
184 bugs => {
185 123 => \@comments,
186 456 => \@comments,
187 },
188  
189 comments => {
190 789 => $comment,
191 },
192  
193 }
194  
195 The Bugzilla WebService documentation doesnt state what order the comments will be in, however they seem to be returned [ oldest, newest ]. If this order is important to you, then you should sort them just to be sure.
196  
197 More details on the above example:
198  
199 =over 4
200  
201 =item bugs
202  
203 This is used for bugs specified in L</ids> parameter.
204  
205 This is a hash, wherein the keys are the numeric IDs of the bugs, and the corresponding value is an array ref of comment objects.
206  
207 Note that any individual bug will only be returned once, so if you specify an ID multiple times in ID's, it will still only be returned once.
208  
209 =item comments
210  
211 Each individual comment requested in L</comment_ids> is returned here.
212  
213 This is a hash wherein the keys are the numeric comment ID, and the corresponding value is the comment object.
214  
215 =back
216  
217 A "comment" as described above is an object instance of this package i.e. L<BZ::Client::Bug::Comment>.
218  
219 =head3 Errors
220  
221 =over 4
222  
223 =item 100 - Invalid Bug Alias
224  
225 If you specified an alias and there is no bug with that alias.
226  
227 =item 101 - Invalid Bug ID
228  
229 The C<bug_id> you specified doesn't exist in the database.
230  
231 =item 102 - Access Denied
232  
233 You do not have access to the C<bug_id> you specified.
234  
235 =item 110 - Comment Is Private
236  
237 You specified the ID of a private comment in the I<comment_ids> argument, and you are not in the "insider group" that can see private comments.
238  
239 =item 111 - Invalid Comment ID
240  
241 You specified an ID in the L</comment_ids> argument that is invalid--either you specified something that wasn't a number, or there is no comment with that ID.
242  
243 =back
244  
245 =head2 add
246  
247 This allows you to add a comment to a bug in Bugzilla.
248  
249 Actual Bugzilla API method is "add_comment".
250  
251 =head3 History
252  
253 Added in Bugzilla 3.2.
254  
255 Modified to return the new comment's ID in Bugzilla 3.4
256  
257 Modified to throw an error if you try to add a private comment but can't, in Bugzilla 3.4.
258  
259 =head3 Parameters
260  
261 An instance of this package or a hash containing:
262  
263 =over 4
264  
265 =item id
266  
267 I<id> (int or string) Required - The ID or alias of the bug to append a comment to.
268  
269 =item comment
270  
271 I<comment> (string) Required - The comment to append to the bug. If this is empty or all whitespace, an error will be thrown saying that you did not set the comment parameter.
272  
273 =item is_private
274  
275 I<is_private> (boolean) - If set to true, the comment is private, otherwise it is assumed to be public.
276  
277 Before Bugzilla 3.6, the L</is_private argument> was called C<private>, and you can still call it C<private> for backwards-compatibility purposes if you wish.
278  
279 =item work_time
280  
281 I<work_time> (double) - Adds this many hours to the "Hours Worked" on the bug. If you are not in the time tracking group, this value will be ignored.
282  
283 =back
284  
285 =head3 Returns
286  
287 The id of the newly-created comment.
288  
289 =head3 Errors
290  
291 =over
292  
293 =item 54 - Hours Worked Too Large
294  
295 You specified a L</work_time> larger than the maximum allowed value of C<99999.99>.
296  
297 =item 100 - Invalid Bug Alias
298  
299 If you specified an alias and there is no bug with that alias.
300  
301 =item 101 - Invalid Bug ID
302  
303 The ID you specified doesn't exist in the database.
304  
305 =item 109 - Bug Edit Denied
306  
307 You did not have the necessary rights to edit the bug.
308  
309 =item 113 - Can't Make Private Comments
310  
311 You tried to add a private comment, but don't have the necessary rights.
312  
313 =item 114 - Comment Too Long
314  
315 You tried to add a comment longer than the maximum allowed length (65,535 characters).
316  
317 =back
318  
319 Before Bugzilla 3.6, error 54 and error 114 had a generic error code of 32000.
320  
321 =head2 render
322  
323 Returns the HTML rendering of the provided comment text.
324  
325 Actual Bugzilla API method is "render_comment".
326  
327 Note: this all takes place on your Bugzilla server.
328  
329 =head3 History
330  
331 Added in Bugzilla 5.0.
332  
333 =head3 Parameters
334  
335 =over 4
336  
337 =item text
338  
339 I<text> (string) Required - Text comment text to render
340  
341 =item id
342  
343 I<id> The ID of the bug to render the comment against.
344  
345 =back
346  
347 =head3 Returns
348  
349 The HTML rendering
350  
351 =head3 Errors
352  
353 =over 4
354  
355 =item 100 - Invalid Bug Alias
356  
357 If you specified an alias and there is no bug with that alias.
358  
359 =item 101 - Invalid Bug ID
360  
361 The C<bug_id> you specified doesn't exist in the database.
362  
363 =item 102 - Access Denied
364  
365 You do not have access to the C<bug_id> you specified.
366  
367 =back
368  
369 =head2 new
370  
371 my $comment = BZ::Client::Bug::Comment->new(
372 id => $bug_id,
373 comment => $comment,
374 is_private => 1 || 0,
375 work_time => 3.5
376 );
377  
378 Creates a new instance with the given details. Doesn't actually touch your Bugzilla Server - see L</add> for that.
379  
380 =head1 INSTANCE METHODS
381  
382 This section lists the modules instance methods.
383  
384 =head2 bug_id
385  
386 I<bug_id> (int) - The ID of the bug that this comment is on when reading
387  
388 I<bug_id> (int or string) - The ID or alias of the bug to append a comment to when writing
389  
390 =head2 comment
391  
392 I<comment> (string) The actual text of the comment when reading
393  
394 When writing, the comment to append to the bug. If this is empty or all whitespace, an error will be thrown saying that you did not set the L</comment> parameter.
395  
396 Max length is 65,535 characters.
397  
398 =head2 text
399  
400 Synonym for L</comment>
401  
402 =head2 is_private
403  
404 I<is_private> (boolean) - If set to true, the comment is private, otherwise it is assumed to be public.
405  
406 Read and Write.
407  
408 =head2 work_time
409  
410 I<work_time> (double) - Adds this many hours to the "Hours Worked" on the bug. If you are not in the time tracking group, this value will be ignored.
411  
412 Max value is 99999.99
413  
414 =head2 id
415  
416 I<id> (int) The globally unique ID for the comment.
417  
418 Read only.
419  
420 =head2 attachment_id
421  
422 I<attachment_id> (int) If the comment was made on an attachment, this will be the ID of that attachment. Otherwise it will be null.
423  
424 Read only.
425  
426 Added to the return value in Bugzilla 3.6
427  
428 =head2 count
429  
430 I<count> (int) - The number of the comment local to the bug. The Description is 0, comments start with 1.
431  
432 Read only.
433  
434 Added to the return value in Bugzilla 4.4.
435  
436 =head2 creator
437  
438 I<creator> (string) - The login name of the comment's author.
439  
440 Also returned as L</author>, for backwards-compatibility with older Bugzillas. (However, this backwards-compatibility will go away in Bugzilla 5.0)
441  
442 In bugzilla 4.0, the L</author> return value was renamed to L</creator>.
443  
444 =head2 author
445  
446 See creator
447  
448 =head2 time
449  
450 I<time> (L<DateTime>) - The time (in Bugzilla's timezone) that the comment was added.
451  
452 Read only.
453  
454 =head2 creation_time
455  
456 I<creation_time> (L<DateTime>) - This is exactly same as the L</time> key. Use this field instead of L</time> for consistency with other methods including L</get> and "attachments". For compatibility, I</time> is still usable. However, please note that I</time> may be deprecated and removed in a future release of Bugzilla.
457  
458 Read only.
459  
460 Added in Bugzilla 4.4.
461  
462 =head1 SEE ALSO
463  
464 L<BZ::Client>, L<BZ::Client::API>, L<Bugzilla API|https://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html>
465  
466 =head1 AUTHORS
467  
468 =over 4
469  
470 =item *
471  
472 Dean Hamstead <dean@bytefoundry.com.au>
473  
474 =item *
475  
476 Jochen Wiedmann <jochen.wiedmann@gmail.com>
477  
478 =back
479  
480 =head1 COPYRIGHT AND LICENSE
481  
482 This software is copyright (c) 2026 by Dean Hamstad.
483  
484 This is free software; you can redistribute it and/or modify it under
485 the same terms as the Perl 5 programming language system itself.
486  
487 =cut