Client/Bug/Comment.pm untested

filter: Statementstmt 0.0% 0 / 74 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 15 totaltotal 0.0% 0 / 141 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.91';
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__