REST/Object.pm

filter: Statementstmt 66.0% 214 / 324 Branchbran 42.1% 54 / 128 Conditioncond 37.1% 23 / 62 MC/DCmcdc 8.1% 3 / 37 Subroutinesub 83.8% 52 / 62 Podpod 100% 18 / 18 totaltotal 57.6% 364 / 631 CC 92 SCAR 35.8
CC
92
Cov
57%
from_form
272.0
to_form
30.5
cf
30.0
CRAP 36.1
« REST/Forms.pm ↑ Summary REST.pm »
1 #!perl
2 # vim: softtabstop=4 tabstop=4 shiftwidth=4 ft=perl expandtab smarttab
3 # PODNAME: RT::Client::REST::Object
4 # ABSTRACT: base class for RT objects
5  
6 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 package RT::Client::REST::Object;
10 16 $RT::Client::REST::Object::VERSION = '0.73';
11  
12 16 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 16 ▶use Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 16 ▶use RT::Client::REST::Object::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 16 ▶use RT::Client::REST::SearchResult;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 16 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 16 ▶use DateTime::Format::DateParse;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19  
20 20 ▶sub new {
Subroutine new: called CC=8 SCAR=24.5
Pod documented
21 20 my $class = shift;
22  
23 20 ▶ if (@_ & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ & 1) 0 20 20
24 0 RT::Client::REST::Object::OddNumberOfArgumentsException->throw;
25 }
26  
27 20 ▶ my $self = bless {}, ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0200
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
28 20 my %opts = @_;
29  
30 20 my $id = delete($opts{id});
31 20 ▶ if (defined($id)) {{
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id) 2 18 20
32 2 $self->id($id);
33 2 ▶ if ($self->can('parent_id')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("parent_id")) 0 2 2
34 # If object can parent_id, we assume that it's needed for
35 # retrieval.
36 0 my $parent_id = delete($opts{parent_id});
37 0 ▶ if (defined($parent_id)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent_id) { } 0 0 0
38 0 $self->parent_id($parent_id);
39 } else {
40 0 last;
41 }
42 }
43 2 ▶ if ($self->autoget) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->autoget) 1 1 2
44 1 $self->retrieve;
45 }
46 }}
47  
48 20 ▶ while (my ($k, $v) = each(%opts)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %opts) 0 20 20
49 0 $self->$k($v);
50 }
51  
52 20 return $self;
53 }
54  
55  
56 23 ▶sub _generate_methods {
Subroutine _generate_methods: called CC=4 SCAR=13.9
57 23 my $class = shift;
58 23 my $attributes = $class->_attributes;
59  
60 23 ▶ while (my ($method, $settings) = each(%$attributes)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$attributes) 336 23 359
61 16 ▶ no strict 'refs'; ## no critic (ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63 336 ▶ *{$class . '::' . $method} = sub {
Subroutine __ANON__: called CC=12 SCAR=25.0
64 67 my $self = shift;
65  
66 67 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 24 43 67
67 24 ▶ my $caller = defined((caller(1))[3]) ? (caller(1))[3] : '';
Branch: 1 branch
BranchTrueFalseTotal
defined((caller 1)[3]) ? : 20 4 24
68  
69 24 ▶ if ($settings->{validation} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($settings->{"validation"} and $caller ne "RT::Client::REST::Object::from_form") 21 3 24
Condition66%2/3
$settings->{"validation"} and $caller ne "RT::Client::REST::Object::from_form"
!ll&&!rl&&r
3021
MC/DC50%1/2
$settings->{"validation"} and $caller ne "RT::Client::REST::Object::from_form"
$settings->{"validation"} $caller ne "RT::Client::REST::Object::from_form"
Truth table66%2/3
A and B
A= $settings->{"validation"}B= $caller ne "RT::Client::REST::Object::from_form"
ABresult
0X0
100
111
70 # Don't validate values from the server
71 $caller ne __PACKAGE__ . '::from_form')
72 {
73 21 my @v = @_;
74 Params::Validate::validation_options(
75 2 ▶ on_fail => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
76 16 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
77 2 RT::Client::REST::Object::InvalidValueException
78 ->throw(
79 "'@v' is not a valid value for attribute '$method'"
80 );
81 },
82 21 );
83 21 validate_pos(@_, $settings->{validation});
84 }
85  
86 22 $self->{'_' . $method} = shift;
87 22 $self->_mark_dirty($method);
88  
89 # Let's try to autosync, shall we? Logic is a bit hairy
90 # in order to make it efficient.
91 22 ▶ if ($self->autosync && $self->can('store') &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->autosync and $self->can("store") and "id" ne $method and "parent_id" ne $method and $caller ne "RT::Client::REST::Object::from_form") 2 20 22
Condition75%9/12
$self->autosync and $self->can("store") and "id" ne $method and "parent_id" ne $method and $caller ne "RT::Client::REST::Object::from_form"
!ll&&!rl&&r
2002
$self->autosync and $self->can("store") and "id" ne $method and "parent_id" ne $method
!ll&&!rl&&r
2002
$self->autosync and $self->can("store") and "id" ne $method
!ll&&!rl&&r
1822
$self->autosync and $self->can("store")
!ll&&!rl&&r
1804
MC/DC40%2/5
$self->autosync and $self->can("store") and "id" ne $method and "parent_id" ne $method and $caller ne "RT::Client::REST::Object::from_form"
$self->autosync $self->can("store") "id" ne $method "parent_id" ne $method $caller ne "RT::Client::REST::Object::from_form"
Truth table50%3/6
A and B and C and D and E
A= $self->autosyncB= $self->can("store")C= "id" ne $methodD= "parent_id" ne $methodE= $caller ne "RT::Client::REST::Object::from_form"
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
92 # OK, so id is special. This is so that 'new' would
93 # work.
94 'id' ne $method &&
95 'parent_id' ne $method &&
96  
97 # Plus we don't want to store right after retrieving
98 # (that's where from_form is called from).
99 $caller ne __PACKAGE__ . '::from_form')
100 {
101 2 $self->store;
102 }
103 }
104  
105 65 ▶ if ($settings->{list}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($settings->{'list'}) { } 10 55 65
106 10 ▶ my $retval = $self->{'_' . $method} || [];
Condition50%1/2
$$self{'_' . $method} || []
l!l
100
MC/DC0%0/1
$$self{'_' . $method} || []
$$self{'_' . $method}
Truth table50%1/2
A
A= $$self{'_' . $method}
Aresult
11
00
107 10 return @$retval;
108 }
109 else {
110 55 return $self->{'_' . $method};
111 }
112 336 };
113  
114 336 ▶ if ($settings->{is_datetime}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($settings->{"is_datetime"}) 40 296 336
115 40 ▶ *{$class. '::' . $method . '_datetime'} = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
116 # All dates are in UTC
117 # http://requesttracker.wikia.com/wiki/REST#Data_format
118  
119 3 my ($self) = shift;
120 3 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 1 3
121 2 ▶ unless ($_[0]->isa('DateTime')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[0]->isa("DateTime")) 1 1 2
122 1 RT::Client::REST::Object::InvalidValueException
123 ->throw(
124 "'$_[0]' is not a valid value for attribute '${method}_datetime'"
125 );
126  
127 }
128 1 my $z = $_[0]->clone;
129 1 $z->set_time_zone('UTC');
130 1 $self->$method($_[0]->strftime('%a %b %d %T %Y'));
131 1 return $z;
132 }
133  
134 1 return DateTime::Format::DateParse->parse_datetime($self->$method, 'UTC');
135  
136 40 };
137 }
138  
139 336 ▶ if ($settings->{list}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($settings->{"list"}) 18 318 336
140 # Generate convenience methods for list manipulation.
141 18 my $add_method = $class . '::add_' . $method;
142 18 my $delete_method = $class . '::delete_' . $method;
143  
144 1 ▶ *$add_method = sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
145 1 my $self = shift;
146  
147 1 ▶ unless (@_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 0 1 1
148 0 RT::Client::REST::Object::NoValuesProvidedException
149 ->throw;
150 }
151  
152 1 my @values = $self->$method;
153 1 my %values = map { $_, 1 } @values;
154  
155 # Now add new values
156 1 for (@_) {
157 3 $values{$_} = 1;
158 }
159  
160 1 $self->$method([keys %values]);
161 18 };
162  
163 1 ▶ *$delete_method = sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
164 1 my $self = shift;
165  
166 1 ▶ unless (@_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 0 1 1
167 0 RT::Client::REST::Object::NoValuesProvidedException
168 ->throw;
169 }
170  
171 1 my @values = $self->$method;
172 1 my %values = map { $_, 1 } @values;
173  
174 # Now delete values
175 1 for (@_) {
176 1 delete $values{$_};
177 }
178  
179 1 $self->$method([keys %values]);
180 18 };
181 }
182 }
183 }
184  
185  
186 22 ▶sub _mark_dirty {
Subroutine _mark_dirty: called CC=1 SCAR=0.0
187 22 my ($self, $attr) = @_;
188 22 $self->{__dirty}{$attr} = 1;
189 }
190  
191  
192 3 ▶sub _dirty {
Subroutine _dirty: called CC=2 SCAR=6.9
193 3 my $self = shift;
194  
195 3 ▶ if (exists($self->{__dirty})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"__dirty"}) 2 1 3
196 2 return keys %{$self->{__dirty}};
197 }
198  
199 1 return;
200 }
201  
202  
203 0 ▶sub _mark_dirty_cf {
Subroutine _mark_dirty_cf: not called CC=1 SCAR=6.9
204 0 my ($self, $cf) = @_;
205 0 $self->{__dirty_cf}{$cf} = 1;
206 }
207  
208  
209 1 ▶sub _dirty_cf {
Subroutine _dirty_cf: called CC=2 SCAR=8.4
210 1 my $self = shift;
211  
212 1 ▶ if (exists($self->{__dirty_cf})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"__dirty_cf"}) 0 1 1
213 0 return keys %{$self->{__dirty_cf}};
214 }
215  
216 1 return;
217 }
218  
219  
220 1 ▶sub to_form {
Subroutine to_form: called CC=9 SCAR=34.2
Pod documented
221 1 my ($self, $all) = @_;
222 1 my $attributes = $self->_attributes;
223  
224 1 ▶ my @attrs = ($all ? keys(%$attributes) : $self->_dirty);
Branch: 1 branch
BranchTrueFalseTotal
$all ? : 0 1 1
225  
226 1 my %hash;
227  
228 1 for my $attr (@attrs) {
229 my $rest_name = (exists($attributes->{$attr}{rest_name}) ?
230 0 ▶ $attributes->{$attr}{rest_name} : ucfirst($attr));
Branch: 1 branch
BranchTrueFalseTotal
exists $attributes->{$attr}{'rest_name'} ? : 0 0 0
231  
232 0 my $value;
233 0 ▶ if (exists($attributes->{$attr}{value2form})) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $attributes->{$attr}{'value2form'}) { } 0 0 0
elsif ($attributes->{$attr}{'list'}) { } 0 0 0
234 0 $value = $attributes->{$attr}{value2form}($self->$attr)
235 } elsif ($attributes->{$attr}{list}) {
236 0 $value = join(',', $self->$attr)
237 } else {
238 0 ▶ $value = (defined($self->$attr) ? $self->$attr : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $self->$attr ? : 0 0 0
239 }
240  
241 0 $hash{$rest_name} = $value;
242 }
243 1 ▶ my @cfs = ($all ? $self->cf : $self->_dirty_cf);
Branch: 1 branch
BranchTrueFalseTotal
$all ? : 0 1 1
244 1 for my $cf (@cfs) {
245 0 $hash{'CF-' . $cf} = $self->cf($cf);
246 }
247  
248 1 return \%hash;
249 }
250  
251  
252 0 ▶sub from_form {
Subroutine from_form: not called CC=16 SCAR=56.1
Pod documented
253 0 my $self = shift;
254  
255 0 ▶ unless (@_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 0 0 0
256 0 RT::Client::REST::Object::NoValuesProvidedException->throw;
257 }
258  
259 0 my $hash = shift;
260  
261 0 ▶ unless ('HASH' eq ref($hash)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("HASH" eq ref $hash) 0 0 0
262 0 RT::Client::REST::Object::InvalidValueException->throw(
263 q|Expecting a hash reference as argument to 'from_form'|,
264 );
265 }
266  
267 # lowercase hash keys
268 0 my $i = 0;
269 0 ▶ $hash = { map { ($i++ & 1) ? $_ : lc } %$hash };
Branch: 1 branch
BranchTrueFalseTotal
$i++ & 1 ? : 0 0 0
270  
271 0 my $attributes = $self->_attributes;
272 0 my %rest2attr; # Mapping of REST names to our attributes;
273 0 ▶ while (my ($attr, $settings) = each(%$attributes)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$attributes) 0 0 0
274 my $rest_name = (exists($attributes->{$attr}{rest_name}) ?
275 0 ▶ lc($attributes->{$attr}{rest_name}) : $attr);
Branch: 1 branch
BranchTrueFalseTotal
exists $attributes->{$attr}{'rest_name'} ? : 0 0 0
276 0 $rest2attr{$rest_name} = [ $attr, $settings ];
277 }
278  
279 # Now set attributes:
280 0 ▶ while (my ($key, $value) = each(%$hash)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$hash) 0 0 0
281  
282 # Handle custom fields, ideally /(?(1)})/ would be appened to RE
283 0 ▶ if ( $key =~ m%^(?:cf|customfield)(?:-|\.\{)([#\s\w_:()?/-]+)% ){
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ m[^(?:cf|customfield)(?:-|\.\{)([#\s\w_:()?/-]+)]) 0 0 0
284 0 $key = $1;
285  
286 # XXX very sketchy. Will fail on long form data e.g; wiki CF
287 0 ▶ if (defined $value and $value =~ /,/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and $value =~ /,/) 0 0 0
Condition0%0/3
defined $value and $value =~ /,/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and $value =~ /,/
defined $value $value =~ /,/
Truth table0%0/3
A and B
A= defined $valueB= $value =~ /,/
ABresult
0X0
100
111
288 0 $value = [ split(/\s*,\s*/, $value) ];
289 }
290  
291 0 $self->cf($key, $value);
292 next
293 0 }
294  
295 0 ▶ unless (exists($rest2attr{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $rest2attr{$key}) 0 0 0
296 0 warn "Unknown key: $key\n";
297 0 next;
298 }
299  
300 0 my ($method, $settings) = @{$rest2attr{$key}};
301  
302 0 ▶ if ($settings->{is_datetime} and $value eq 'Not set') {
Branch: 1 branch
BranchTrueFalseTotal
if ($settings->{"is_datetime"} and $value eq "Not set") 0 0 0
Condition0%0/3
$settings->{"is_datetime"} and $value eq "Not set"
!ll&&!rl&&r
000
MC/DC0%0/2
$settings->{"is_datetime"} and $value eq "Not set"
$settings->{"is_datetime"} $value eq "Not set"
Truth table0%0/3
A and B
A= $settings->{"is_datetime"}B= $value eq "Not set"
ABresult
0X0
100
111
303 0 $value = undef
304 }
305  
306 0 ▶ if (exists($attributes->{$method}{form2value})) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $attributes->{$method}{'form2value'}) { } 0 0 0
elsif ($attributes->{$method}{'list'}) { } 0 0 0
307 0 $value = $attributes->{$method}{form2value}($value);
308 }
309 elsif ($attributes->{$method}{list}) {
310 0 ▶ $value = defined $value ? [split(/\s*,\s*/, $value)] : []
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 0 0 0
311 }
312  
313 0 $self->$method($value);
314 }
315  
316 0 return;
317 }
318  
319 3 ▶sub retrieve {
Subroutine retrieve: called CC=1 SCAR=1.2
Pod documented
320 3 my $self = shift;
321  
322 3 $self->_assert_rt_and_id;
323  
324 1 my $rt = $self->rt;
325  
326 1 my ($hash) = $rt->show(type => $self->rt_type, id => $self->id);
327 0 $self->from_form($hash);
328  
329 0 $self->{__dirty} = {};
330 0 $self->{__dirty_cf} = {};
331  
332 0 return $self;
333 }
334  
335 2 ▶sub store {
Subroutine store: called CC=2 SCAR=8.7
Pod documented
336 2 my $self = shift;
337  
338 2 $self->_assert_rt;
339  
340 1 my $rt = $self->rt;
341  
342 1 ▶ if (defined($self->id)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->id) { } 1 0 1
343 1 $rt->edit(
344 type => $self->rt_type,
345 id => $self->id,
346 set => $self->to_form,
347 );
348 }
349 else {
350 0 my $id = $rt->create(
351 type => $self->rt_type,
352 set => $self->to_form,
353 @_,
354 );
355 0 $self->id($id);
356 }
357  
358 0 $self->{__dirty} = {};
359  
360 0 return $self;
361 }
362  
363 3 ▶sub search {
Subroutine search: called CC=6 SCAR=28.0
Pod documented
364 3 my $self = shift;
365  
366 3 ▶ if (@_ & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ & 1) 0 3 3
367 0 RT::Client::REST::Object::OddNumberOfArgumentsException->throw;
368 }
369  
370 3 $self->_assert_rt;
371  
372 2 my %opts = @_;
373  
374 2 ▶ my $limits = delete($opts{limits}) || [];
Condition50%1/2
delete $opts{'limits'} || []
l!l
02
MC/DC0%0/1
delete $opts{'limits'} || []
delete $opts{'limits'}
Truth table50%1/2
A
A= delete $opts{'limits'}
Aresult
11
00
375 2 my $query = '';
376  
377 2 for my $limit (@$limits) {
378 0 my $kw;
379 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
380 0 $kw = $self->_attr2keyword($limit->{attribute});
381 }
382 0 ▶ catch {
Subroutine __ANON__: not called CC=4 SCAR=30.0
383 0 ▶ die $_ unless blessed $_ && $_->can('rethrow');
Branch: 1 branch
BranchTrueFalseTotal
unless $_->blessed and $_->can("rethrow") 0 0 0
Condition0%0/3
$_->blessed and $_->can("rethrow")
!ll&&!rl&&r
000
MC/DC0%0/2
$_->blessed and $_->can("rethrow")
$_->blessed $_->can("rethrow")
Truth table0%0/3
A and B
A= $_->blessedB= $_->can("rethrow")
ABresult
0X0
100
111
384  
385 0 ▶ if ($_->isa('RT::Client::REST::Object::InvalidAttributeException')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->isa('RT::Client::REST::Object::InvalidAttributeException')) { } 0 0 0
386 0 RT::Client::REST::Object::InvalidSearchParametersException
387 ->throw(shift->message);
388 }
389 else {
390 0 $_->rethrow
391 }
392 0 };
393 0 my $op = $limit->{operator};
394 0 my $val = $limit->{value};
395 0 ▶ my $agg = $limit->{aggregator} || 'and';
Condition0%0/2
$limit->{'aggregator'} || 'and'
l!l
00
MC/DC0%0/1
$limit->{'aggregator'} || 'and'
$limit->{'aggregator'}
Truth table0%0/2
A
A= $limit->{'aggregator'}
Aresult
11
00
396  
397 0 ▶ if (length($query)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $query) { } 0 0 0
398 0 $query = "($query) $agg $kw $op '$val'";
399 } else {
400 0 $query = "$kw $op '$val'";
401 }
402 }
403  
404 2 my $orderby;
405 2 ▶ try {
Subroutine __ANON__: called CC=3 SCAR=12.7
406 # Defaults to 'id' at the moment. Do not rely on this --
407 # implementation may change!
408 $orderby = (delete($opts{reverseorder}) ? '-' : '+') .
409 2 ▶ ($self->_attr2keyword(delete($opts{orderby}) || 'id'));
Branch: 1 branch
BranchTrueFalseTotal
delete $opts{'reverseorder'} ? : 0 2 2
Condition50%1/2
delete $opts{'orderby'} || 'id'
l!l
02
MC/DC0%0/1
delete $opts{'orderby'} || 'id'
delete $opts{'orderby'}
Truth table50%1/2
A
A= delete $opts{'orderby'}
Aresult
11
00
410 }
411 0 ▶ catch {
Subroutine __ANON__: not called CC=4 SCAR=30.0
412 0 ▶ die $_ unless blessed $_ && $_->can('rethrow');
Branch: 1 branch
BranchTrueFalseTotal
unless $_->blessed and $_->can("rethrow") 0 0 0
Condition0%0/3
$_->blessed and $_->can("rethrow")
!ll&&!rl&&r
000
MC/DC0%0/2
$_->blessed and $_->can("rethrow")
$_->blessed $_->can("rethrow")
Truth table0%0/3
A and B
A= $_->blessedB= $_->can("rethrow")
ABresult
0X0
100
111
413  
414 0 ▶ if ($_->isa('RT::Client::REST::Object::InvalidAttributeException')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->isa('RT::Client::REST::Object::InvalidAttributeException')) { } 0 0 0
415 0 RT::Client::REST::Object::InvalidSearchParametersException->throw(
416 shift->message,
417 )
418 }
419 else {
420 0 $_->rethrow;
421 }
422 2 };
423  
424 2 my $rt = $self->rt;
425 2 my @results;
426 2 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
427 2 @results = $rt->search(
428 type => $self->rt_type,
429 query => $query,
430 orderby => $orderby,
431 );
432 }
433 2 ▶ catch {
Subroutine __ANON__: called CC=4 SCAR=17.1
434 2 ▶ die $_ unless blessed $_ && $_->can('rethrow');
Branch: 1 branch
BranchTrueFalseTotal
unless $_->blessed and $_->can("rethrow") 0 2 2
Condition33%1/3
$_->blessed and $_->can("rethrow")
!ll&&!rl&&r
002
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
435  
436 2 ▶ if ($_->isa('RT::Client::REST::InvalidQueryException')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->isa('RT::Client::REST::InvalidQueryException')) { } 0 2 2
437 0 RT::Client::REST::Object::InvalidSearchParametersException->throw;
438 }
439 else {
440 2 $_->rethrow;
441 }
442 2 };
443  
444 return RT::Client::REST::SearchResult->new(
445 ids => \@results,
446 0 ▶ object => sub { $self->new(id => shift, rt => $rt) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
447 0 );
448 }
449  
450 2 ▶sub count {
Subroutine count: called CC=1 SCAR=0.0
Pod documented
451 2 my $self = shift;
452 2 $self->_assert_rt;
453 1 return $self->search(@_)->count;
454 }
455  
456 2 ▶sub _attr2keyword {
Subroutine _attr2keyword: called CC=3 SCAR=11.4
457 2 my ($self, $attr) = @_;
458 2 my $attributes = $self->_attributes;
459  
460 2 ▶ unless (exists($attributes->{$attr})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $attributes->{$attr}) 0 2 2
461 16 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
462 0 RT::Client::REST::Object::InvalidAttributeException->throw(
463 "Attribute '$attr' does not exist in object type '" .
464 ref($self) . "'"
465 );
466 }
467  
468 return (exists($attributes->{$attr}{rest_name}) ?
469 $attributes->{$attr}{rest_name} :
470 2 ▶ ucfirst($attr));
Branch: 1 branch
BranchTrueFalseTotal
exists $attributes->{$attr}{'rest_name'} ? : 0 2 2
471 }
472  
473 30 ▶sub _assert_rt_and_id {
Subroutine _assert_rt_and_id: called CC=4 SCAR=13.9
474 30 my $self = shift;
475 30 ▶ my $method = shift || (caller(1))[3];
Condition66%2/3
shift() || (caller 1)[3]
l!l&&r!l&&!r
2190
MC/DC0%0/2
shift() || (caller 1)[3]
shift() (caller 1)[3]
Truth table66%2/3
A || B
A= shift()B= (caller 1)[3]
ABresult
1X1
011
000
476  
477 30 ▶ unless (defined($self->rt)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->rt) 8 22 30
478 8 RT::Client::REST::Object::RequiredAttributeUnsetException
479 ->throw("Cannot '$method': 'rt' attribute of the object ".
480 "is not set");
481 }
482  
483 22 ▶ unless (defined($self->id)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->id) 8 14 22
484 8 RT::Client::REST::Object::RequiredAttributeUnsetException
485 ->throw("Cannot '$method': 'id' attribute of the object ".
486 "is not set");
487 }
488 }
489  
490 7 ▶sub _assert_rt {
Subroutine _assert_rt: called CC=3 SCAR=11.3
491 7 my $self = shift;
492 7 ▶ my $method = shift || (caller(1))[3];
Condition33%1/3
shift() || (caller 1)[3]
l!l&&r!l&&!r
070
MC/DC0%0/2
shift() || (caller 1)[3]
shift() (caller 1)[3]
Truth table33%1/3
A || B
A= shift()B= (caller 1)[3]
ABresult
1X1
011
000
493  
494 7 ▶ unless (defined($self->rt)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->rt) 3 4 7
495 3 RT::Client::REST::Object::RequiredAttributeUnsetException
496 ->throw("Cannot '$method': 'rt' attribute of the object ".
497 "is not set");
498 }
499 }
500  
501  
502 0 ▶sub param {
Subroutine param: not called CC=3 SCAR=24.8
Pod documented
503 0 my $self = shift;
504  
505 0 ▶ unless (@_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 0 0 0
506 0 RT::Client::REST::Object::NoValuesProvidedException->throw;
507 }
508  
509 0 my $name = shift;
510  
511 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
512 0 $self->{__param}{$name} = shift;
513 }
514  
515 0 return $self->{__param}{$name};
516 }
517  
518  
519 0 ▶sub cf {
Subroutine cf: not called CC=5 SCAR=34.0
Pod documented
520 0 my $self = shift;
521  
522 0 ▶ unless (@_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 0 0 0
523 # Return a list of CFs.
524 0 return keys %{$self->{__cf}};
525 }
526  
527 0 my $name = shift;
528 0 ▶ if ('HASH' eq ref($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ('HASH' eq ref $name) { } 0 0 0
529 0 ▶ while (my ($k, $v) = each(%$name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$name) 0 0 0
530 0 $self->{__cf}{lc($k)} = $v;
531 0 $self->_mark_dirty_cf($k);
532 }
533 0 return keys %{$self->{__cf}};
534 } else {
535 0 $name = lc $name;
536 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
537 0 $self->{__cf}{$name} = shift;
538 0 $self->_mark_dirty_cf($name);
539 }
540 0 return $self->{__cf}{$name};
541 }
542 }
543  
544  
545 68 ▶sub rt {
Subroutine rt: called CC=3 SCAR=11.0
Pod documented
546 68 my $self = shift;
547  
548 68 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 18 50 68
549 18 my $rt = shift;
550 18 ▶ unless (UNIVERSAL::isa($rt, 'RT::Client::REST')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($rt, "RT::Client::REST")) 7 11 18
551 7 RT::Client::REST::Object::InvalidValueException->throw;
552 }
553 11 $self->{__rt} = $rt;
554 }
555  
556 61 return $self->{__rt};
557 }
558  
559  
560 2 ▶sub use_single_rt {
Subroutine use_single_rt: called CC=3 SCAR=11.0
Pod documented
561 2 my ($class, $rt) = @_;
562  
563 2 ▶ unless (UNIVERSAL::isa($rt, 'RT::Client::REST')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($rt, "RT::Client::REST")) 1 1 2
564 1 RT::Client::REST::Object::InvalidValueException->throw;
565 }
566  
567 16 ▶ no strict 'refs'; ## no critic (ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
568 16 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
569 1 ▶ *{(ref($class) || $class) . '::rt'} = sub { $rt };
Subroutine __ANON__: called CC=1 SCAR=0.4
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
570 }
571  
572  
573 41 ▶sub autostore {}
Subroutine autostore: called CC=1 SCAR=0.0
Pod documented
574  
575 0 ▶sub use_autostore {
Subroutine use_autostore: not called CC=2 SCAR=9.6
Pod documented
576 0 my ($class, $autostore) = @_;
577  
578 16 ▶ no strict 'refs'; ## no critic (ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
579 16 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
580 0 ▶ *{(ref($class) || $class) . '::autostore'} = sub { $autostore };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
581 }
582  
583 38 ▶sub DESTROY {
Subroutine DESTROY: called CC=3 SCAR=13.1
584 38 my $self = shift;
585  
586 38 ▶ $self->autostore && $self->can('store') && $self->store;
Branch: 1 branch
BranchTrueFalseTotal
$self->autostore and $self->can("store") and $self->store 0 38 38
Condition33%1/3
$self->autostore and $self->can("store")
!ll&&!rl&&r
3800
MC/DC0%0/2
$self->autostore and $self->can("store")
$self->autostore $self->can("store")
Truth table33%1/3
A and B
A= $self->autostoreB= $self->can("store")
ABresult
0X0
100
111
587 }
588  
589  
590 21 ▶sub autoget {}
Subroutine autoget: called CC=1 SCAR=0.0
Pod documented
591  
592 2 ▶sub use_autoget {
Subroutine use_autoget: called CC=2 SCAR=7.0
Pod documented
593 2 my ($class, $autoget) = @_;
594  
595 16 ▶ no strict 'refs'; ## no critic (ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
596 16 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
597 2 ▶ *{(ref($class) || $class) . '::autoget'} = sub { $autoget };
Subroutine __ANON__: called CC=1 SCAR=0.4
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
598 }
599  
600  
601 20 ▶sub autosync {}
Subroutine autosync: called CC=1 SCAR=0.0
Pod documented
602  
603 2 ▶sub use_autosync {
Subroutine use_autosync: called CC=2 SCAR=7.0
Pod documented
604 2 my ($class, $autosync) = @_;
605  
606 16 ▶ no strict 'refs'; ## no critic (ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
607 16 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
608 2 ▶ *{(ref($class) || $class) . '::autosync'} = sub { $autosync };
Subroutine __ANON__: called CC=1 SCAR=0.4
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
609 }
610  
611  
612 2 ▶sub be_transparent {
Subroutine be_transparent: called CC=1 SCAR=0.0
Pod documented
613 2 my ($class, $rt) = @_;
614 2 $class->use_autosync(1);
615 2 $class->use_autoget(1);
616 2 $class->use_single_rt($rt);
617 }
618  
619  
620 16 1;
621  
622 __END__
« REST/Forms.pm ↑ Summary REST.pm »