REST/Ticket.pm

filter: Statementstmt 87.5% 70 / 80 Branchbran 66.6% 8 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 20 / 24 Podpod 100% 3 / 3 totaltotal 82.2% 102 / 124 CC 8 SCAR 7.7
CC
8
Cov
83%
__ANON__
5.5
transactions
3.4
__ANON__
3.0
CRAP 2.2
« REST/SearchResult.pm ↑ Summary REST/Attachment.pm »
1 #!perl
2 # vim: softtabstop=4 tabstop=4 shiftwidth=4 ft=perl expandtab smarttab
3 # PODNAME: RT::Client::REST::Ticket
4 # ABSTRACT: ticket object representation.
5  
6 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 package RT::Client::REST::Ticket;
10 4 $RT::Client::REST::Ticket::VERSION = '0.73';
11 4 ▶use parent 'RT::Client::REST::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Params::Validate qw(:types);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use RT::Client::REST;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use RT::Client::REST::Attachment;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use RT::Client::REST::Object::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶use RT::Client::REST::SearchResult;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use RT::Client::REST::Transaction;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21  
22 4 ▶sub _attributes {{
Subroutine _attributes: called CC=1 SCAR=3.5
23  
24 id => {
25 validation => {
26 type => SCALAR,
27 regex => qr/^\d+$/,
28 },
29 0 ▶ form2value => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 0 shift =~ m~^ticket/(\d+)$~i;
31 0 return $1;
32 },
33 0 ▶ value2form => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 0 return 'ticket/' . shift;
35 },
36 },
37  
38 4 queue => {
39 validation => {
40 type => SCALAR,
41 },
42 },
43  
44 owner => {
45 validation => {
46 type => SCALAR,
47 },
48 },
49  
50 creator => {
51 validation => {
52 type => SCALAR,
53 },
54 },
55  
56 subject => {
57 validation => {
58 type => SCALAR,
59 },
60 },
61  
62 status => {
63 validation => {
64 # That's it for validation... People can create their own
65 # custom statuses.
66 type => SCALAR,
67 },
68 rest_name => 'Status',
69 },
70  
71 priority => {
72 validation => {
73 type => SCALAR,
74 },
75 },
76  
77 initial_priority => {
78 validation => {
79 type => SCALAR,
80 },
81 rest_name => 'InitialPriority',
82 },
83  
84 final_priority => {
85 validation => {
86 type => SCALAR,
87 },
88 rest_name => 'FinalPriority',
89 },
90  
91 requestors => {
92 validation => {
93 type => ARRAYREF,
94 },
95 list => 1,
96 },
97  
98 requestor => {
99 validation => {
100 type => ARRAYREF,
101 },
102 list => 1,
103 },
104  
105 cc => {
106 validation => {
107 type => ARRAYREF,
108 },
109 list => 1,
110 },
111  
112 admin_cc => {
113 validation => {
114 type => ARRAYREF,
115 },
116 list => 1,
117 rest_name => 'AdminCc',
118 },
119  
120 created => {
121 validation => {
122 type => SCALAR,
123 },
124 is_datetime => 1,
125 },
126  
127 starts => {
128 validation => {
129 type => SCALAR|UNDEF,
130 },
131 is_datetime => 1,
132 },
133  
134 started => {
135 validation => {
136 type => SCALAR|UNDEF,
137 },
138 is_datetime => 1,
139 },
140  
141 due => {
142 validation => {
143 type => SCALAR|UNDEF,
144 },
145 is_datetime => 1,
146 },
147  
148 resolved => {
149 validation => {
150 type => SCALAR|UNDEF,
151 },
152 is_datetime => 1,
153 },
154  
155 told => {
156 validation => {
157 type => SCALAR|UNDEF,
158 },
159 is_datetime => 1,
160 },
161  
162 time_estimated => {
163 validation => {
164 type => SCALAR,
165 },
166 rest_name => 'TimeEstimated',
167 },
168  
169 time_worked => {
170 validation => {
171 type => SCALAR,
172 },
173 rest_name => 'TimeWorked',
174 },
175  
176 time_left => {
177 validation => {
178 type => SCALAR,
179 },
180 rest_name => 'TimeLeft',
181 },
182  
183 last_updated => {
184 validation => {
185 type => SCALAR,
186 },
187 rest_name => 'LastUpdated',
188 is_datetime => 1,
189 },
190  
191 sla => {
192 validation => {
193 type => SCALAR,
194 },
195 },
196  
197 }}
198  
199  
200 # comment and correspond are really the same method, so we save ourselves
201 # some duplication here.
202 4 for my $method (qw(comment correspond)) {
203 4 ▶ no strict 'refs'; ## no critic (ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
204 16 ▶ *$method = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
205 16 my $self = shift;
206  
207 16 ▶ if (@_ & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ & 1) 4 12 16
208 4 RT::Client::REST::Object::OddNumberOfArgumentsException->throw;
209 }
210  
211 12 $self->_assert_rt_and_id($method);
212  
213 8 my %opts = @_;
214  
215 8 ▶ unless (defined($opts{message})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts{"message"}) 4 4 8
216 4 RT::Client::REST::Object::InvalidValueException->throw(
217 "No message was provided",
218 );
219 }
220  
221 4 $self->rt->$method(
222 ticket_id => $self->id,
223 %opts,
224 );
225  
226 0 return;
227 8 };
228 }
229  
230  
231 3 ▶sub attachments {
Subroutine attachments: called CC=1 SCAR=0.2
Pod documented
232 3 my $self = shift;
233  
234 3 $self->_assert_rt_and_id;
235  
236 RT::Client::REST::SearchResult->new(
237 ids => [ $self->rt->get_attachment_ids(id => $self->id) ],
238 0 ▶ object => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
239 0 RT::Client::REST::Attachment->new(
240 id => shift,
241 parent_id => $self->id,
242 rt => $self->rt,
243 );
244 },
245 1 );
246 }
247  
248  
249 3 ▶sub transactions {
Subroutine transactions: called CC=3 SCAR=12.3
Pod documented
250 3 my $self = shift;
251  
252 3 ▶ if (@_ & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ & 1) 0 3 3
253 0 RT::Client::REST::Object::OddNumberOfArgumentsException->throw;
254 }
255  
256 3 $self->_assert_rt_and_id;
257  
258 1 my %opts = @_;
259 1 my %params = (
260 parent_id => $self->id,
261 );
262 1 ▶ if (defined(my $type = delete($opts{type}))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $type = delete $opts{"type"})) 0 1 1
263 0 $params{transaction_type} = $type;
264 }
265  
266 RT::Client::REST::SearchResult->new(
267 ids => [ $self->rt->get_transaction_ids(%params) ],
268 0 ▶ object => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
269 0 RT::Client::REST::Transaction->new(
270 id => shift,
271 parent_id => $self->id,
272 rt => $self->rt,
273 );
274 },
275 1 );
276 }
277  
278  
279 4 for my $method (qw(take untake steal)) {
280 4 ▶ no strict 'refs'; ## no critic (ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
281 9 ▶ *$method = sub {
Subroutine __ANON__: called CC=1 SCAR=0.5
282 9 my $self = shift;
283  
284 9 $self->_assert_rt_and_id($method);
285  
286 3 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
287 3 $self->rt->$method(id => $self->id);
288 }
289 3 ▶ catch {
Subroutine __ANON__: called CC=4 SCAR=17.1
290 3 ▶ die $_ unless blessed $_ && $_->can('rethrow');
Branch: 1 branch
BranchTrueFalseTotal
unless $_->blessed and $_->can("rethrow") 0 3 3
Condition33%1/3
$_->blessed and $_->can("rethrow")
!ll&&!rl&&r
003
MC/DC0%0/2
$_->blessed and $_->can("rethrow")
$_->blessed $_->can("rethrow")
Truth table33%1/3
A and B
A= $_->blessedB= $_->can("rethrow")
ABresult
0X0
100
111
291  
292 3 ▶ if ($_->isa('RT::Client::REST::AlreadyTicketOwnerException')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->isa('RT::Client::REST::AlreadyTicketOwnerException')) { } 0 3 3
293 # Rename the exception.
294 0 RT::Client::REST::Object::NoopOperationException
295 ->throw(shift->message);
296 }
297 else {
298 3 $_->rethrow;
299 }
300 3 };
301  
302 0 return;
303 12 };
304 }
305  
306  
307 1 ▶sub rt_type { 'ticket' }
Subroutine rt_type: called CC=1 SCAR=0.0
Pod documented
308  
309  
310 4 __PACKAGE__->_generate_methods;
311  
312 4 1;
313  
314 __END__
« REST/SearchResult.pm ↑ Summary REST/Attachment.pm »