| 1 | #!perl | ||||||||||||||||||||||||||||||||||
| 2 | # vim: softtabstop=4 tabstop=4 shiftwidth=4 ft=perl expandtab smarttab | ||||||||||||||||||||||||||||||||||
| 3 | # PODNAME: RT::Client::REST | ||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Client for RT using REST API | ||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||
| 6 | # Dmitri Tikhonov <dtikhonov@yahoo.com> | ||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||
| 8 | # Part of the source is Copyright (c) 2007-2008 Damien Krotkine <dams@cpan.org> | ||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||
| 10 | # This code is adapted from /usr/bin/rt that came with RT. As of version 0.49, | ||||||||||||||||||||||||||||||||||
| 11 | # this module is licensed using Perl Artistic License, with permission from the | ||||||||||||||||||||||||||||||||||
| 12 | # original author of rt utility, Abhijit Menon-Sen. | ||||||||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||||||||
| 14 | # Original notice: | ||||||||||||||||||||||||||||||||||
| 15 | #------------------------ | ||||||||||||||||||||||||||||||||||
| 16 | # COPYRIGHT: | ||||||||||||||||||||||||||||||||||
| 17 | # This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC | ||||||||||||||||||||||||||||||||||
| 18 | # <jesse@bestpractical.com> | ||||||||||||||||||||||||||||||||||
| 19 | # Designed and implemented for Best Practical Solutions, LLC by | ||||||||||||||||||||||||||||||||||
| 20 | # Abhijit Menon-Sen <ams@wiw.org> | ||||||||||||||||||||||||||||||||||
| 21 | #------------------------ | ||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | 26 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 25 | 26 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | package RT::Client::REST; | ||||||||||||||||||||||||||||||||||
| 28 | 26 | $RT::Client::REST::VERSION = '0.73'; | |||||||||||||||||||||||||||||||||
| 29 | 26 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 30 | 26 | ▶ | use HTTP::Cookies; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 31 | 26 | ▶ | use HTTP::Request::Common; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 32 | 26 | ▶ | use RT::Client::REST::Exception; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 33 | 26 | ▶ | use RT::Client::REST::Forms; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 34 | 26 | ▶ | use RT::Client::REST::HTTPClient; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||
| 36 | # Generate accessors/mutators | ||||||||||||||||||||||||||||||||||
| 37 | 26 | for my $method (qw(server _cookie timeout verbose_errors user_agent_args)) { | |||||||||||||||||||||||||||||||||
| 38 | 26 | ▶ | no strict 'refs'; ## no critic (ProhibitNoStrict) | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 39 | 130 | ▶ | *{__PACKAGE__ . '::' . $method} = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 40 | 153 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 41 | 153 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 42 | 35 | my $val = shift; | |||||||||||||||||||||||||||||||||
| 43 | { | ||||||||||||||||||||||||||||||||||
| 44 | 26 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 45 | 35 | $self->logger->debug("set `$method' to $val"); | |||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||
| 47 | 35 | $self->{'_' . $method} = $val; | |||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||
| 49 | 153 | return $self->{'_' . $method}; | |||||||||||||||||||||||||||||||||
| 50 | 130 | }; | |||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | 25 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 54 | 25 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||
| 56 | 25 | $class->_assert_even(@_); | |||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||
| 58 | 25 | ▶ | my $self = bless { | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||
| 59 | _logger => RT::Client::REST::NoopLogger->new, | ||||||||||||||||||||||||||||||||||
| 60 | }, ref($class) || $class; | ||||||||||||||||||||||||||||||||||
| 61 | 25 | my %opts = @_; | |||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | 25 | ▶ | while (my ($k, $v) = each(%opts)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 64 | # in _rest we concatenate server with '/REST/1.0'; | ||||||||||||||||||||||||||||||||||
| 65 | 31 | ▶ | if ($k eq 'server') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 66 | 13 | $v =~ s!/$!!; | |||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||
| 68 | 31 | $self->$k($v); | |||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | 24 | return $self; | |||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||
| 74 | 5 | ▶ | sub login { | ||||||||||||||||||||||||||||||||
|
Subroutine
login: called CC=4 SCAR=14.7
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 75 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | 5 | $self->_assert_even(@_); | |||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||
| 79 | 5 | my %opts = @_; | |||||||||||||||||||||||||||||||||
| 80 | 5 | ▶ | unless (scalar(keys %opts) > 0) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 81 | 1 | RT::Client::REST::InvalidParameterValueException->throw( | |||||||||||||||||||||||||||||||||
| 82 | "You must provide credentials (user and pass) to log in", | ||||||||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||
| 85 | # back-compat hack | ||||||||||||||||||||||||||||||||||
| 86 | 4 | ▶ | if (defined $opts{username}){ $opts{user} = $opts{username}; delete $opts{username} } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 87 | 4 | ▶ | if (defined $opts{password}){ $opts{pass} = $opts{password}; delete $opts{password} } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | # OK, here's how login works. We request to see ticket 1. We don't | ||||||||||||||||||||||||||||||||||
| 90 | # even care if it exists. We watch exceptions: auth. failures and | ||||||||||||||||||||||||||||||||||
| 91 | # server-side errors we bubble up and ignore all others. | ||||||||||||||||||||||||||||||||||
| 92 | 4 | ▶ | try { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 93 | 4 | $self->_cookie(undef); # Start a new session. | |||||||||||||||||||||||||||||||||
| 94 | 4 | $self->_submit('ticket/1', undef, \%opts); | |||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||
| 96 | 4 | ▶ | catch { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=20.9
| |||||||||||||||||||||||||||||||||||
| 97 | 4 | ▶ | die $_ unless blessed $_ && $_->can('rethrow'); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$_->blessed and $_->can("rethrow")
MC/DC0%0/2
$_->blessed and $_->can("rethrow")
$_->blessed
$_->can("rethrow")
Truth table33%1/3
A and B
A= $_->blessedB= $_->can("rethrow")
| |||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||
| 99 | 4 | my $err = $_; | |||||||||||||||||||||||||||||||||
| 100 | 4 | ▶ | if (grep { $err->isa($_) } ( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 101 | 'RT::Client::REST::AuthenticationFailureException', | ||||||||||||||||||||||||||||||||||
| 102 | 'RT::Client::REST::MalformedRTResponseException', | ||||||||||||||||||||||||||||||||||
| 103 | 'RT::Client::REST::RequestTimedOutException', | ||||||||||||||||||||||||||||||||||
| 104 | 'RT::Client::REST::HTTPException', | ||||||||||||||||||||||||||||||||||
| 105 | )) { | ||||||||||||||||||||||||||||||||||
| 106 | shift->rethrow | ||||||||||||||||||||||||||||||||||
| 107 | 4 | } | |||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if (! $err->isa('Exception::Class::Base')) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 109 | 0 | die $err | |||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||
| 111 | # ignore others. | ||||||||||||||||||||||||||||||||||
| 112 | 4 | }; | |||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | sub show { | ||||||||||||||||||||||||||||||||
|
Subroutine
show: called CC=4 SCAR=18.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 116 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||
| 118 | 1 | $self->_assert_even(@_); | |||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||
| 120 | 1 | my %opts = @_; | |||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||
| 122 | 1 | my $type = $self->_valid_type(delete($opts{type})); | |||||||||||||||||||||||||||||||||
| 123 | 1 | my $id; | |||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||
| 125 | 1 | ▶ | if (grep { $type eq $_ } (qw(user queue group))) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 126 | # User or queue ID does not have to be numeric | ||||||||||||||||||||||||||||||||||
| 127 | 0 | $id = delete($opts{id}); | |||||||||||||||||||||||||||||||||
| 128 | } else { | ||||||||||||||||||||||||||||||||||
| 129 | 1 | $id = $self->_valid_numeric_object_id(delete($opts{id})); | |||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||
| 132 | 1 | my $form = form_parse($self->_submit("$type/$id")->decoded_content); | |||||||||||||||||||||||||||||||||
| 133 | 0 | my ($c, $o, $k) = @{$$form[0]}; # my ($c, $o, $k, $e) | |||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | if (!@$o && $c) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not @$o and $c
MC/DC0%0/2
not @$o and $c
not @$o
$c
Truth table0%0/3
not(A) and B
A= not @$oB= $c
| |||||||||||||||||||||||||||||||||||
| 136 | 0 | RT::Client::REST::Exception->_rt_content_to_exception($c)->throw; | |||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||
| 139 | 0 | return $k; | |||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||
| 142 | 1 | ▶ | sub get_attachment_ids { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_attachment_ids: called CC=4 SCAR=20.3
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 143 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||
| 145 | 1 | $self->_assert_even(@_); | |||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||
| 147 | 1 | my %opts = @_; | |||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||
| 149 | 1 | ▶ | my $type = $self->_valid_type(delete($opts{type}) || 'ticket'); | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $opts{'type'} || 'ticket'
MC/DC0%0/1
delete $opts{'type'} || 'ticket'
delete $opts{'type'}
Truth table50%1/2
A
A= delete $opts{'type'}
| |||||||||||||||||||||||||||||||||||
| 150 | 1 | my $id = $self->_valid_numeric_object_id(delete($opts{id})); | |||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||
| 152 | 1 | my $form = form_parse( | |||||||||||||||||||||||||||||||||
| 153 | $self->_submit("$type/$id/attachments/")->decoded_content | ||||||||||||||||||||||||||||||||||
| 154 | ); | ||||||||||||||||||||||||||||||||||
| 155 | 0 | my ($c, $o, $k) = @{$$form[0]}; # my ($c, $o, $k, $e) | |||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | if (!@$o && $c) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not @$o and $c
MC/DC0%0/2
not @$o and $c
not @$o
$c
Truth table0%0/3
not(A) and B
A= not @$oB= $c
| |||||||||||||||||||||||||||||||||||
| 158 | 0 | RT::Client::REST::Exception->_rt_content_to_exception($c)->throw; | |||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||
| 161 | 0 | return $k->{Attachments} =~ m/^\s*(\d+):/mg; | |||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | sub get_attachments_metadata { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_attachments_metadata: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 165 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||
| 167 | 0 | $self->_assert_even(@_); | |||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||
| 169 | 0 | my %opts = @_; | |||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | my $type = $self->_valid_type(delete($opts{type}) || 'ticket'); | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $opts{'type'} || 'ticket'
MC/DC0%0/1
delete $opts{'type'} || 'ticket'
delete $opts{'type'}
Truth table0%0/2
A
A= delete $opts{'type'}
| |||||||||||||||||||||||||||||||||||
| 172 | 0 | my $id = $self->_valid_numeric_object_id(delete($opts{id})); | |||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||
| 174 | 0 | my $form = form_parse( | |||||||||||||||||||||||||||||||||
| 175 | $self->_submit("$type/$id/attachments/")->decoded_content | ||||||||||||||||||||||||||||||||||
| 176 | ); | ||||||||||||||||||||||||||||||||||
| 177 | 0 | my ($c, $o, $k) = @{$$form[0]}; # my ($c, $o, $k, $e) | |||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | if (!@$o && $c) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not @$o and $c
MC/DC0%0/2
not @$o and $c
not @$o
$c
Truth table0%0/3
not(A) and B
A= not @$oB= $c
| |||||||||||||||||||||||||||||||||||
| 180 | 0 | RT::Client::REST::Exception->_rt_content_to_exception($c)->throw; | |||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||
| 182 | return map { | ||||||||||||||||||||||||||||||||||
| 183 | # Matches: '50008989: (Unnamed) (text/plain / 1.9k),' | ||||||||||||||||||||||||||||||||||
| 184 | 0 | my @c = $_ =~ m/^\s*(\d+):\s+(.+)\s+\(([^\s]+)\s+\/\s+([^\s]+)\)\s*,?\s*$/; | |||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | { id => $c[0], Filename => ( defined($c[1]) && ( $c[1] eq '(Unnamed)' ) ) ? undef : $c[1], Type => $c[2], Size => $c[3] }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $c[1] and $c[1] eq "(Unnamed)"
MC/DC0%0/2
defined $c[1] and $c[1] eq "(Unnamed)"
defined $c[1]
$c[1] eq "(Unnamed)"
Truth table0%0/3
A and B
A= defined $c[1]B= $c[1] eq "(Unnamed)"
| |||||||||||||||||||||||||||||||||||
| 186 | 0 | } split(/\n/, $k->{Attachments}); | |||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||
| 189 | 6 | ▶ | sub get_attachment { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_attachment: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 190 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||
| 192 | 6 | $self->_assert_even(@_); | |||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||
| 194 | 6 | my %opts = @_; | |||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||
| 196 | 6 | ▶ | my $type = $self->_valid_type(delete($opts{type}) || 'ticket'); | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $opts{'type'} || 'ticket'
MC/DC0%0/1
delete $opts{'type'} || 'ticket'
delete $opts{'type'}
Truth table50%1/2
A
A= delete $opts{'type'}
| |||||||||||||||||||||||||||||||||||
| 197 | 6 | my $parent_id = $self->_valid_numeric_object_id(delete($opts{parent_id})); | |||||||||||||||||||||||||||||||||
| 198 | 6 | my $id = $self->_valid_numeric_object_id(delete($opts{id})); | |||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||
| 200 | 6 | my $res = $self->_submit("$type/$parent_id/attachments/$id"); | |||||||||||||||||||||||||||||||||
| 201 | 6 | my $content; | |||||||||||||||||||||||||||||||||
| 202 | 6 | ▶ | if ($opts{undecoded}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 203 | 3 | $content = $res->content; | |||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||
| 205 | else { | ||||||||||||||||||||||||||||||||||
| 206 | 3 | $content = $res->decoded_content; | |||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||
| 208 | 6 | my $form = form_parse($content); | |||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||
| 210 | 6 | my ($c, $o, $k) = @{$$form[0]}; # my ($c, $o, $k, $e) | |||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||
| 212 | 6 | ▶ | if (!@$o && $c) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not @$o and $c
MC/DC0%0/2
not @$o and $c
not @$o
$c
Truth table33%1/3
not(A) and B
A= not @$oB= $c
| |||||||||||||||||||||||||||||||||||
| 213 | 0 | RT::Client::REST::Exception->_rt_content_to_exception($c)->throw; | |||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||
| 216 | 6 | return $k; | |||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | sub get_links { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_links: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 220 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||
| 222 | 0 | $self->_assert_even(@_); | |||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||
| 224 | 0 | my %opts = @_; | |||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | my $type = $self->_valid_type(delete($opts{type}) || 'ticket'); | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $opts{'type'} || 'ticket'
MC/DC0%0/1
delete $opts{'type'} || 'ticket'
delete $opts{'type'}
Truth table0%0/2
A
A= delete $opts{'type'}
| |||||||||||||||||||||||||||||||||||
| 227 | 0 | my $id = $self->_valid_numeric_object_id(delete($opts{id})); | |||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||
| 229 | 0 | my $form = form_parse( | |||||||||||||||||||||||||||||||||
| 230 | $self->_submit("$type/$id/links")->decoded_content | ||||||||||||||||||||||||||||||||||
| 231 | ); | ||||||||||||||||||||||||||||||||||
| 232 | 0 | my ($c, $o, $k) = @{$$form[0]}; # my ($c, $o, $k, $e) | |||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | if (!@$o && $c) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not @$o and $c
MC/DC0%0/2
not @$o and $c
not @$o
$c
Truth table0%0/3
not(A) and B
A= not @$oB= $c
| |||||||||||||||||||||||||||||||||||
| 235 | 0 | RT::Client::REST::Exception->_rt_content_to_exception($c)->throw; | |||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||
| 238 | # Turn the links into id lists | ||||||||||||||||||||||||||||||||||
| 239 | 0 | for my $key (keys(%$k)) { | |||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | try { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 241 | 0 | $self->_valid_link_type($key); | |||||||||||||||||||||||||||||||||
| 242 | 0 | my @list = split(/\s*,\s*/,$k->{$key}); | |||||||||||||||||||||||||||||||||
| 243 | #use Data::Dumper; | ||||||||||||||||||||||||||||||||||
| 244 | #print STDERR Dumper(\@list); | ||||||||||||||||||||||||||||||||||
| 245 | 0 | my @newlist = (); | |||||||||||||||||||||||||||||||||
| 246 | 0 | for my $val (@list) { | |||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | if ($val =~ /^fsck\.com-\w+\:\/\/(.*?)\/(.*?)\/(\d+)$/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 248 | # We just want the ids, not the URI | ||||||||||||||||||||||||||||||||||
| 249 | 0 | push(@newlist, {'type' => $2, 'instance' => $1, 'id' => $3 }); | |||||||||||||||||||||||||||||||||
| 250 | } else { | ||||||||||||||||||||||||||||||||||
| 251 | # Something we don't recognise | ||||||||||||||||||||||||||||||||||
| 252 | 0 | push(@newlist, { 'url' => $val }); | |||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||
| 255 | # Copy the newly created list | ||||||||||||||||||||||||||||||||||
| 256 | 0 | $k->{$key} = (); | |||||||||||||||||||||||||||||||||
| 257 | 0 | $k->{$key} = \@newlist; | |||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | catch { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | die $_ unless blessed $_ && $_->can('rethrow'); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_->blessed and $_->can("rethrow")
MC/DC0%0/2
$_->blessed and $_->can("rethrow")
$_->blessed
$_->can("rethrow")
Truth table0%0/3
A and B
A= $_->blessedB= $_->can("rethrow")
| |||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | if (! $_->isa('RT::Client::REST::InvalidParameterValueException')) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 263 | 0 | $_->rethrow; | |||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||
| 265 | # Skip it because the keys are not always valid e.g., 'id' | ||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||
| 267 | 0 | } | |||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||
| 269 | 0 | return $k; | |||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||
| 272 | 1 | ▶ | sub get_transaction_ids { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_transaction_ids: called CC=6 SCAR=27.3
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 273 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||
| 275 | 1 | $self->_assert_even(@_); | |||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||
| 277 | 1 | my %opts = @_; | |||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||
| 279 | 1 | my $parent_id = $self->_valid_numeric_object_id(delete($opts{parent_id})); | |||||||||||||||||||||||||||||||||
| 280 | 1 | ▶ | my $type = $self->_valid_type(delete($opts{type}) || 'ticket'); | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $opts{'type'} || 'ticket'
MC/DC0%0/1
delete $opts{'type'} || 'ticket'
delete $opts{'type'}
Truth table50%1/2
A
A= delete $opts{'type'}
| |||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||
| 282 | 1 | my $path; | |||||||||||||||||||||||||||||||||
| 283 | 1 | my $tr_type = delete($opts{transaction_type}); | |||||||||||||||||||||||||||||||||
| 284 | 1 | ▶ | if (!defined($tr_type)) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 285 | # Gotta catch 'em all! | ||||||||||||||||||||||||||||||||||
| 286 | 1 | $path = "$type/$parent_id/history"; | |||||||||||||||||||||||||||||||||
| 287 | } elsif ('ARRAY' eq ref($tr_type)) { | ||||||||||||||||||||||||||||||||||
| 288 | # OK, more than one type. Call ourselves for each. | ||||||||||||||||||||||||||||||||||
| 289 | # NOTE: this may be very expensive. | ||||||||||||||||||||||||||||||||||
| 290 | my @return = sort map { | ||||||||||||||||||||||||||||||||||
| 291 | 0 | $self->get_transaction_ids( | |||||||||||||||||||||||||||||||||
| 292 | parent_id => $parent_id, | ||||||||||||||||||||||||||||||||||
| 293 | transaction_type => $_, | ||||||||||||||||||||||||||||||||||
| 294 | ) | ||||||||||||||||||||||||||||||||||
| 295 | } map { | ||||||||||||||||||||||||||||||||||
| 296 | # Check all the types before recursing, cheaper to catch an | ||||||||||||||||||||||||||||||||||
| 297 | # error this way. | ||||||||||||||||||||||||||||||||||
| 298 | 0 | $self->_valid_transaction_type($_) | |||||||||||||||||||||||||||||||||
| 299 | } @$tr_type; | ||||||||||||||||||||||||||||||||||
| 300 | return @return | ||||||||||||||||||||||||||||||||||
| 301 | 0 | } else { | |||||||||||||||||||||||||||||||||
| 302 | 0 | $tr_type = $self->_valid_transaction_type($tr_type); | |||||||||||||||||||||||||||||||||
| 303 | 0 | $path = "$type/$parent_id/history/type/$tr_type" | |||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||
| 306 | 1 | my $form = form_parse( $self->_submit($path)->decoded_content ); | |||||||||||||||||||||||||||||||||
| 307 | 0 | my ($c, $o, $k, $e) = @{$$form[0]}; | |||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | if (!length($e)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 310 | 0 | my $ex = RT::Client::REST::Exception->_rt_content_to_exception($c); | |||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | unless ($ex->message =~ m~^0/~) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 312 | # We do not throw exception if the error is that no values | ||||||||||||||||||||||||||||||||||
| 313 | # were found. | ||||||||||||||||||||||||||||||||||
| 314 | 0 | $ex->throw; | |||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||
| 318 | 0 | return $e =~ m/^(?:>> )?(\d+):/mg; | |||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | sub get_transaction { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_transaction: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 322 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||
| 324 | 0 | $self->_assert_even(@_); | |||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||
| 326 | 0 | my %opts = @_; | |||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | my $type = $self->_valid_type(delete($opts{type}) || 'ticket'); | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $opts{'type'} || 'ticket'
MC/DC0%0/1
delete $opts{'type'} || 'ticket'
delete $opts{'type'}
Truth table0%0/2
A
A= delete $opts{'type'}
| |||||||||||||||||||||||||||||||||||
| 329 | 0 | my $parent_id = $self->_valid_numeric_object_id(delete($opts{parent_id})); | |||||||||||||||||||||||||||||||||
| 330 | 0 | my $id = $self->_valid_numeric_object_id(delete($opts{id})); | |||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||
| 332 | 0 | my $form = form_parse( | |||||||||||||||||||||||||||||||||
| 333 | $self->_submit("$type/$parent_id/history/id/$id")->decoded_content | ||||||||||||||||||||||||||||||||||
| 334 | ); | ||||||||||||||||||||||||||||||||||
| 335 | 0 | my ($c, $o, $k) = @{$$form[0]}; # my ($c, $o, $k, $e) | |||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | if (!@$o && $c) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not @$o and $c
MC/DC0%0/2
not @$o and $c
not @$o
$c
Truth table0%0/3
not(A) and B
A= not @$oB= $c
| |||||||||||||||||||||||||||||||||||
| 338 | 0 | RT::Client::REST::Exception->_rt_content_to_exception($c)->throw; | |||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||
| 341 | 0 | return $k; | |||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||
| 344 | 2 | ▶ | sub search { | ||||||||||||||||||||||||||||||||
|
Subroutine
search: called CC=8 SCAR=31.6
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 345 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||
| 347 | 2 | $self->_assert_even(@_); | |||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||
| 349 | 2 | my %opts = @_; | |||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||
| 351 | 2 | my $type = $self->_valid_type(delete($opts{type})); | |||||||||||||||||||||||||||||||||
| 352 | 2 | my $query = delete($opts{query}); | |||||||||||||||||||||||||||||||||
| 353 | 2 | my $orderby = delete($opts{orderby}); | |||||||||||||||||||||||||||||||||
| 354 | 2 | my $format = delete($opts{format}); | |||||||||||||||||||||||||||||||||
| 355 | 2 | ▶ | if (defined($format)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | $format = undef if $format ne 's' | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||
| 359 | 2 | ▶ | my $r = $self->_submit("search/$type", { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 360 | query => $query, | ||||||||||||||||||||||||||||||||||
| 361 | (defined($orderby) ? (orderby => $orderby) : ()), | ||||||||||||||||||||||||||||||||||
| 362 | (defined($format) ? (format => $format) : ()), | ||||||||||||||||||||||||||||||||||
| 363 | }); | ||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | if (defined($format) and $format eq 's') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $format and $format eq "s"
MC/DC0%0/2
defined $format and $format eq "s"
defined $format
$format eq "s"
Truth table0%0/3
A and B
A= defined $formatB= $format eq "s"
| |||||||||||||||||||||||||||||||||||
| 366 | 0 | my @results; | |||||||||||||||||||||||||||||||||
| 367 | # while() never stops if the method is used in the regex | ||||||||||||||||||||||||||||||||||
| 368 | 0 | my $text = $r->decoded_content; | |||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | while ($text =~ m/^(\d+): (.*)/gm) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 370 | 0 | push @results, [$1, $2] | |||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||
| 372 | return @results | ||||||||||||||||||||||||||||||||||
| 373 | 0 | } | |||||||||||||||||||||||||||||||||
| 374 | 0 | return $r->decoded_content =~ m/^(\d+):/gm; | |||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||
| 377 | 1 | ▶ | sub edit { | ||||||||||||||||||||||||||||||||
|
Subroutine
edit: called CC=7 SCAR=25.3
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 378 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 379 | 1 | $self->_assert_even(@_); | |||||||||||||||||||||||||||||||||
| 380 | 1 | my %opts = @_; | |||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||
| 382 | 1 | my $type = $self->_valid_type(delete($opts{type})); | |||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||
| 384 | 1 | my $id = delete($opts{id}); | |||||||||||||||||||||||||||||||||
| 385 | 1 | ▶ | unless ('new' eq $id) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 386 | 1 | $id = $self->_valid_numeric_object_id($id); | |||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||
| 389 | 1 | my %set; | |||||||||||||||||||||||||||||||||
| 390 | 1 | ▶ | if (defined(my $set = delete($opts{set}))) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 391 | 1 | ▶ | while (my ($k, $v) = each(%$set)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 392 | 0 | vpush(\%set, lc($k), $v); | |||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||
| 395 | 1 | ▶ | if (defined(my $text = delete($opts{text}))) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 396 | 0 | $text =~ s/(\n\r?)/$1 /g; | |||||||||||||||||||||||||||||||||
| 397 | 0 | vpush(\%set, 'text', $text); | |||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||
| 399 | 1 | $set{id} = "$type/$id"; | |||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||
| 401 | 1 | my $r = $self->_submit('edit', { | |||||||||||||||||||||||||||||||||
| 402 | content => form_compose([['', [keys %set], \%set]]) | ||||||||||||||||||||||||||||||||||
| 403 | }); | ||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||
| 405 | # This seems to be a bug on the server side: returning 200 Ok when | ||||||||||||||||||||||||||||||||||
| 406 | # ticket creation (for instance) fails. We check it here: | ||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | if ($r->decoded_content =~ /not/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 408 | 0 | RT::Client::REST::Exception->_rt_content_to_exception($r->decoded_content) | |||||||||||||||||||||||||||||||||
| 409 | ->throw( | ||||||||||||||||||||||||||||||||||
| 410 | code => $r->code, | ||||||||||||||||||||||||||||||||||
| 411 | message => "RT server returned this error: " . $r->decoded_content, | ||||||||||||||||||||||||||||||||||
| 412 | ); | ||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | if ($r->decoded_content =~ /^#[^\d]+(\d+) (?:created|updated)/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 416 | 0 | return $1; | |||||||||||||||||||||||||||||||||
| 417 | } else { | ||||||||||||||||||||||||||||||||||
| 418 | 0 | RT::Client::REST::MalformedRTResponseException->throw( | |||||||||||||||||||||||||||||||||
| 419 | message => "Cound not read ID of the modified object", | ||||||||||||||||||||||||||||||||||
| 420 | ); | ||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||
| 424 | 0 | ▶ | sub create { shift->edit(@_, id => 'new') } | ||||||||||||||||||||||||||||||||
|
Subroutine
create: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||
| 426 | 4 | ▶ | sub comment { | ||||||||||||||||||||||||||||||||
|
Subroutine
comment: called CC=11 SCAR=29.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 427 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 428 | 4 | $self->_assert_even(@_); | |||||||||||||||||||||||||||||||||
| 429 | 4 | my %opts = @_; | |||||||||||||||||||||||||||||||||
| 430 | my $action = $self->_valid_comment_action( | ||||||||||||||||||||||||||||||||||
| 431 | 4 | ▶ | delete($opts{comment_action}) || 'comment'); | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $opts{'comment_action'} || 'comment'
MC/DC100%1/1
delete $opts{'comment_action'} || 'comment'
delete $opts{'comment_action'}
Truth table100%2/2
A
A= delete $opts{'comment_action'}
| |||||||||||||||||||||||||||||||||||
| 432 | 4 | my $ticket_id = $self->_valid_numeric_object_id(delete($opts{ticket_id})); | |||||||||||||||||||||||||||||||||
| 433 | 4 | my $msg = $self->_valid_comment_message(delete($opts{message})); | |||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||
| 435 | 4 | my @objects = ('Ticket', 'Action', 'Text'); | |||||||||||||||||||||||||||||||||
| 436 | 4 | my %values = ( | |||||||||||||||||||||||||||||||||
| 437 | Ticket => $ticket_id, | ||||||||||||||||||||||||||||||||||
| 438 | Action => $action, | ||||||||||||||||||||||||||||||||||
| 439 | Text => $msg, | ||||||||||||||||||||||||||||||||||
| 440 | ); | ||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||
| 442 | 4 | ▶ | if (exists($opts{html})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | if ($opts{html}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 444 | 0 | push @objects, 'Content-Type'; | |||||||||||||||||||||||||||||||||
| 445 | 0 | $values{'Content-Type'} = 'text/html'; | |||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||
| 447 | 0 | delete($opts{html}); | |||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||
| 450 | 4 | ▶ | if (exists($opts{cc})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 451 | 0 | push @objects, 'Cc'; | |||||||||||||||||||||||||||||||||
| 452 | 0 | $values{Cc} = delete($opts{cc}); | |||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||
| 455 | 4 | ▶ | if (exists($opts{bcc})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 456 | 0 | push @objects, 'Bcc'; | |||||||||||||||||||||||||||||||||
| 457 | 0 | $values{Bcc} = delete($opts{bcc}); | |||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||
| 460 | 4 | my %data; | |||||||||||||||||||||||||||||||||
| 461 | 4 | ▶ | if (exists($opts{attachments})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 462 | 2 | my $files = delete($opts{attachments}); | |||||||||||||||||||||||||||||||||
| 463 | 2 | ▶ | unless ('ARRAY' eq ref($files)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 464 | 0 | RT::Client::REST::InvalidParameterValueException->throw( | |||||||||||||||||||||||||||||||||
| 465 | "'attachments' must be an array reference", | ||||||||||||||||||||||||||||||||||
| 466 | ); | ||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||
| 468 | 2 | push @objects, 'Attachment'; | |||||||||||||||||||||||||||||||||
| 469 | 2 | $values{Attachment} = $files; | |||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||
| 471 | 2 | ▶ | for (my $i = 0; $i < @$files; ++$i) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 472 | 2 | ▶ | unless (-f $files->[$i] && -r _) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-f $files->[$i] and -r _
MC/DC0%0/2
-f $files->[$i] and -r _
-f $files->[$i]
-r _
Truth table33%1/3
A and B
A= -f $files->[$i]B= -r _
| |||||||||||||||||||||||||||||||||||
| 473 | 2 | RT::Client::REST::CannotReadAttachmentException->throw( | |||||||||||||||||||||||||||||||||
| 474 | "File '" . $files->[$i] . "' is not readable", | ||||||||||||||||||||||||||||||||||
| 475 | ); | ||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||
| 478 | 0 | my $index = $i + 1; | |||||||||||||||||||||||||||||||||
| 479 | 0 | $data{"attachment_$index"} = bless([ $files->[$i] ], 'Attachment'); | |||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||
| 483 | 2 | my $text = form_compose([[ '', \@objects, \%values, ]]); | |||||||||||||||||||||||||||||||||
| 484 | 2 | $data{content} = $text; | |||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||
| 486 | 2 | $self->_submit("ticket/$ticket_id/comment", \%data); | |||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||
| 488 | 0 | return; | |||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||
| 491 | 2 | ▶ | sub correspond { shift->comment(@_, comment_action => 'correspond') } | ||||||||||||||||||||||||||||||||
|
Subroutine
correspond: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | sub merge_tickets { | ||||||||||||||||||||||||||||||||
|
Subroutine
merge_tickets: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 494 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 495 | 0 | $self->_assert_even(@_); | |||||||||||||||||||||||||||||||||
| 496 | 0 | my %opts = @_; | |||||||||||||||||||||||||||||||||
| 497 | 0 | my ($src, $dst) = map { $self->_valid_numeric_object_id($_) } | |||||||||||||||||||||||||||||||||
| 498 | 0 | @opts{qw(src dst)}; | |||||||||||||||||||||||||||||||||
| 499 | 0 | $self->_submit("ticket/$src/merge/$dst"); | |||||||||||||||||||||||||||||||||
| 500 | 0 | return; | |||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||
| 503 | 0 | ▶ | sub _link { | ||||||||||||||||||||||||||||||||
|
Subroutine
_link: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 504 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 505 | 0 | $self->_assert_even(@_); | |||||||||||||||||||||||||||||||||
| 506 | 0 | my %opts = @_; | |||||||||||||||||||||||||||||||||
| 507 | 0 | my ($src, $dst) = map { $self->_valid_numeric_object_id($_) } | |||||||||||||||||||||||||||||||||
| 508 | 0 | @opts{qw(src dst)}; | |||||||||||||||||||||||||||||||||
| 509 | 0 | my $ltype = $self->_valid_link_type(delete($opts{link_type})); | |||||||||||||||||||||||||||||||||
| 510 | 0 | ▶ | my $del = (exists($opts{'unlink'}) ? 1 : ''); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 511 | 0 | ▶ | my $type = $self->_valid_type(delete($opts{type}) || 'ticket'); | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $opts{'type'} || 'ticket'
MC/DC0%0/1
delete $opts{'type'} || 'ticket'
delete $opts{'type'}
Truth table0%0/2
A
A= delete $opts{'type'}
| |||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||
| 513 | #$self->_submit("$type/$src/link", { | ||||||||||||||||||||||||||||||||||
| 514 | #id => $from, rel => $rel, to => $to, del => $del | ||||||||||||||||||||||||||||||||||
| 515 | #} | ||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||
| 517 | 0 | $self->_submit("$type/link", { | |||||||||||||||||||||||||||||||||
| 518 | id => $src, | ||||||||||||||||||||||||||||||||||
| 519 | rel => $ltype, | ||||||||||||||||||||||||||||||||||
| 520 | to => $dst, | ||||||||||||||||||||||||||||||||||
| 521 | del => $del, | ||||||||||||||||||||||||||||||||||
| 522 | }); | ||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||
| 524 | 0 | return; | |||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||
| 527 | 0 | ▶ | sub link_tickets { shift->_link(@_, type => 'ticket') } | ||||||||||||||||||||||||||||||||
|
Subroutine
link_tickets: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||
| 529 | # sub unlink { shift->_link(@_, unlink => 1) } ## nothing calls this & undocumented, so commenting out for now | ||||||||||||||||||||||||||||||||||
| 530 | 0 | ▶ | sub unlink_tickets { shift->_link(@_, type => 'ticket', unlink => 1) } | ||||||||||||||||||||||||||||||||
|
Subroutine
unlink_tickets: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||
| 532 | 3 | ▶ | sub _ticket_action { | ||||||||||||||||||||||||||||||||
|
Subroutine
_ticket_action: called CC=2 SCAR=8.7
| |||||||||||||||||||||||||||||||||||
| 533 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||
| 535 | 3 | $self->_assert_even(@_); | |||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||
| 537 | 3 | my %opts = @_; | |||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||
| 539 | 3 | my $id = delete $opts{id}; | |||||||||||||||||||||||||||||||||
| 540 | 3 | my $action = delete $opts{action}; | |||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||
| 542 | 3 | my $text = form_compose([[ '', ['Action'], { Action => $action }, ]]); | |||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||
| 544 | 3 | my $form = form_parse( | |||||||||||||||||||||||||||||||||
| 545 | $self->_submit("/ticket/$id/take", { content => $text })->decoded_content | ||||||||||||||||||||||||||||||||||
| 546 | ); | ||||||||||||||||||||||||||||||||||
| 547 | 0 | my ($c, $o, $k, $e) = @{$$form[0]}; | |||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||
| 549 | 0 | ▶ | if ($e) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 550 | 0 | RT::Client::REST::Exception->_rt_content_to_exception($c)->throw; | |||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||
| 554 | 1 | ▶ | sub take { shift->_ticket_action(@_, action => 'take') } | ||||||||||||||||||||||||||||||||
|
Subroutine
take: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 555 | 1 | ▶ | sub untake { shift->_ticket_action(@_, action => 'untake') } | ||||||||||||||||||||||||||||||||
|
Subroutine
untake: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 556 | 1 | ▶ | sub steal { shift->_ticket_action(@_, action => 'steal') } | ||||||||||||||||||||||||||||||||
|
Subroutine
steal: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||
| 558 | 28 | ▶ | sub _submit { | ||||||||||||||||||||||||||||||||
|
Subroutine
_submit: called CC=28 SCAR=38.1
| |||||||||||||||||||||||||||||||||||
| 559 | 28 | my ($self, $uri, $content, $auth) = @_; | |||||||||||||||||||||||||||||||||
| 560 | 28 | my ($req, $data); | |||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||
| 562 | # Did the caller specify any data to send with the request? | ||||||||||||||||||||||||||||||||||
| 563 | 28 | $data = []; | |||||||||||||||||||||||||||||||||
| 564 | 28 | ▶ | if (defined $content) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 565 | 9 | ▶ | unless (ref $content) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 566 | # If it's just a string, make sure LWP handles it properly. | ||||||||||||||||||||||||||||||||||
| 567 | # (By pretending that it's a file!) | ||||||||||||||||||||||||||||||||||
| 568 | 1 | $content = [ content => [undef, q(), Content => $content] ]; | |||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||
| 570 | 0 | elsif (ref $content eq 'HASH') { | |||||||||||||||||||||||||||||||||
| 571 | 8 | my @data; | |||||||||||||||||||||||||||||||||
| 572 | 8 | for my $k (keys %$content) { | |||||||||||||||||||||||||||||||||
| 573 | 10 | ▶ | if (ref $content->{$k} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 574 | 0 | for my $v (@{ $content->{$k} }) { | |||||||||||||||||||||||||||||||||
| 575 | 0 | push @data, $k, $v; | |||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||
| 578 | 10 | else { push @data, $k, $content->{$k} } | |||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||
| 580 | 8 | $content = \@data; | |||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||
| 582 | 9 | $data = $content; | |||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||
| 585 | # Should we send authentication information to start a new session? | ||||||||||||||||||||||||||||||||||
| 586 | 28 | ▶ | unless ($self->_cookie || $self->basic_auth_cb) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->_cookie or $self->basic_auth_cb
MC/DC50%1/2
$self->_cookie or $self->basic_auth_cb
$self->_cookie
$self->basic_auth_cb
Truth table66%2/3
A or B
A= $self->_cookieB= $self->basic_auth_cb
| |||||||||||||||||||||||||||||||||||
| 587 | 22 | ▶ | unless (defined($auth)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 588 | 11 | RT::Client::REST::RequiredAttributeUnsetException->throw( | |||||||||||||||||||||||||||||||||
| 589 | 'You must log in first', | ||||||||||||||||||||||||||||||||||
| 590 | ); | ||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||
| 592 | 11 | push @$data, %$auth; | |||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||
| 595 | # Now, we construct the request. | ||||||||||||||||||||||||||||||||||
| 596 | 17 | ▶ | if (@$data) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 597 | # The request object expects "bytes", not strings | ||||||||||||||||||||||||||||||||||
| 598 | 11 | utf8::encode($_) for grep { !ref($_) } @$data; | |||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||
| 600 | 11 | $req = POST($self->_uri($uri), $data, Content_Type => 'form-data'); | |||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||
| 602 | else { | ||||||||||||||||||||||||||||||||||
| 603 | 6 | $req = GET($self->_uri($uri)); | |||||||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||||||||
| 605 | #$session->add_cookie_header($req); | ||||||||||||||||||||||||||||||||||
| 606 | 17 | ▶ | if ($self->_cookie) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 607 | 0 | $self->_cookie->add_cookie_header($req); | |||||||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||
| 610 | # Then we send the request and parse the response. | ||||||||||||||||||||||||||||||||||
| 611 | 17 | $self->logger->debug('request: ', $req->as_string); | |||||||||||||||||||||||||||||||||
| 612 | 17 | my $res = $self->_ua->request($req); | |||||||||||||||||||||||||||||||||
| 613 | 17 | $self->logger->debug('response: ', $res->as_string); | |||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||
| 615 | 17 | ▶ | if ($res->is_success) { | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 616 | # The content of the response we get from the RT server consists | ||||||||||||||||||||||||||||||||||
| 617 | # of an HTTP-like status line followed by optional header lines, | ||||||||||||||||||||||||||||||||||
| 618 | # a blank line, and arbitrary text. | ||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||
| 620 | 8 | my ($head, $text) = split /\n\n/, $res->decoded_content(charset => 'none'), 2; | |||||||||||||||||||||||||||||||||
| 621 | 8 | my ($status) = split /\n/, $head; # my ($status, @headers) = split /\n/, $head; | |||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||
| 623 | # Example: | ||||||||||||||||||||||||||||||||||
| 624 | # "RT/3.0.1 401 Credentials required" | ||||||||||||||||||||||||||||||||||
| 625 | 8 | ▶ | if ($status !~ m#^RT/\d+(?:\S+) (\d+) ([\w\s]+)$#) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 626 | 1 | my $err_msg = 'Malformed RT response received from ' . $self->server; | |||||||||||||||||||||||||||||||||
| 627 | 1 | ▶ | if ($self->verbose_errors) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 628 | 1 | ▶ | $err_msg = "Malformed RT response received from " . $self->_uri($uri) . | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$text || ''
MC/DC0%0/1
$text || ''
$text
Truth table50%1/2
A
A= $text
| |||||||||||||||||||||||||||||||||||
| 629 | " with this response: " . substr($text || '', 0, 200) . '....'; | ||||||||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||||||||
| 631 | 1 | RT::Client::REST::MalformedRTResponseException->throw($err_msg); | |||||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||
| 634 | # Our caller can pretend that the server returned a custom HTTP | ||||||||||||||||||||||||||||||||||
| 635 | # response code and message. (Doing that directly is apparently | ||||||||||||||||||||||||||||||||||
| 636 | # not sufficiently portable and uncomplicated.) | ||||||||||||||||||||||||||||||||||
| 637 | 7 | $res->code($1); | |||||||||||||||||||||||||||||||||
| 638 | 7 | $res->message($2); | |||||||||||||||||||||||||||||||||
| 639 | 7 | $res->content($text); | |||||||||||||||||||||||||||||||||
| 640 | #$session->update($res) if ($res->is_success || $res->code != 401); | ||||||||||||||||||||||||||||||||||
| 641 | 7 | ▶ | if ($res->header('set-cookie')) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 642 | 0 | my $jar = HTTP::Cookies->new; | |||||||||||||||||||||||||||||||||
| 643 | 0 | $jar->extract_cookies($res); | |||||||||||||||||||||||||||||||||
| 644 | 0 | $self->_cookie($jar); | |||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||
| 647 | 7 | ▶ | if (!$res->is_success) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 648 | # We can deal with authentication failures ourselves. Either | ||||||||||||||||||||||||||||||||||
| 649 | # we sent invalid credentials, or our session has expired. | ||||||||||||||||||||||||||||||||||
| 650 | 0 | ▶ | if ($res->code == 401) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 651 | 0 | my %d = @$data; | |||||||||||||||||||||||||||||||||
| 652 | 0 | ▶ | if (exists $d{user}) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 653 | 0 | RT::Client::REST::AuthenticationFailureException->throw( | |||||||||||||||||||||||||||||||||
| 654 | code => $res->code, | ||||||||||||||||||||||||||||||||||
| 655 | message => 'Incorrect username or password', | ||||||||||||||||||||||||||||||||||
| 656 | ); | ||||||||||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||||||||
| 658 | elsif ($req->header('Cookie')) { | ||||||||||||||||||||||||||||||||||
| 659 | # We'll retry the request with credentials, unless | ||||||||||||||||||||||||||||||||||
| 660 | # we only wanted to logout in the first place. | ||||||||||||||||||||||||||||||||||
| 661 | #$session->delete; | ||||||||||||||||||||||||||||||||||
| 662 | #return submit(@_) unless $uri eq "$REST/logout"; | ||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||
| 664 | else { | ||||||||||||||||||||||||||||||||||
| 665 | 0 | RT::Client::REST::AuthenticationFailureException->throw( | |||||||||||||||||||||||||||||||||
| 666 | code => $res->code, | ||||||||||||||||||||||||||||||||||
| 667 | message => 'Server said: '. $res->message, | ||||||||||||||||||||||||||||||||||
| 668 | ); | ||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||
| 671 | else { | ||||||||||||||||||||||||||||||||||
| 672 | 0 | RT::Client::REST::Exception->_rt_content_to_exception( | |||||||||||||||||||||||||||||||||
| 673 | $res->decoded_content) | ||||||||||||||||||||||||||||||||||
| 674 | ->throw( | ||||||||||||||||||||||||||||||||||
| 675 | code => $res->code, | ||||||||||||||||||||||||||||||||||
| 676 | message => 'RT server returned this error: ' . | ||||||||||||||||||||||||||||||||||
| 677 | $res->decoded_content, | ||||||||||||||||||||||||||||||||||
| 678 | ); | ||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||
| 681 | ▶ | } elsif ( | |||||||||||||||||||||||||||||||||
|
Condition50%3/6
500 == $res->code and ($res->decoded_content || $res->message) =~ /read timeout/
$res->decoded_content || $res->message
MC/DC33%1/3
500 == $res->code and ($res->decoded_content || $res->message) =~ /read timeout/
500 == $res->code
$res->decoded_content
$res->message
Truth table50%2/4
A and B || C
A= 500 == $res->codeB= $res->decoded_contentC= $res->message
| |||||||||||||||||||||||||||||||||||
| 682 | 500 == $res->code && | ||||||||||||||||||||||||||||||||||
| 683 | # Older versions of HTTP::Response populate 'message', newer | ||||||||||||||||||||||||||||||||||
| 684 | # versions populate 'content'. This catches both cases. | ||||||||||||||||||||||||||||||||||
| 685 | ($res->decoded_content || $res->message) =~ m/read timeout/ | ||||||||||||||||||||||||||||||||||
| 686 | ) { | ||||||||||||||||||||||||||||||||||
| 687 | 5 | RT::Client::REST::RequestTimedOutException->throw( | |||||||||||||||||||||||||||||||||
| 688 | 'Your request to ' . $self->server . ' timed out', | ||||||||||||||||||||||||||||||||||
| 689 | ); | ||||||||||||||||||||||||||||||||||
| 690 | ▶ | } elsif (302 == $res->code && !$self->{'_redirected'}) { | |||||||||||||||||||||||||||||||||
|
Condition66%2/3
302 == $res->code and not $self->{"_redirected"}
MC/DC50%1/2
302 == $res->code and not $self->{"_redirected"}
302 == $res->code
not $self->{"_redirected"}
Truth table66%2/3
A and not(B)
A= 302 == $res->codeB= not $self->{"_redirected"}
| |||||||||||||||||||||||||||||||||||
| 691 | 2 | $self->{'_redirected'} = 1; # We only allow one redirection | |||||||||||||||||||||||||||||||||
| 692 | # Figure out the new value of 'server'. We assume that the /REST/.. | ||||||||||||||||||||||||||||||||||
| 693 | # part of the URI stays the same. | ||||||||||||||||||||||||||||||||||
| 694 | 2 | my $new_location = $res->header('Location'); | |||||||||||||||||||||||||||||||||
| 695 | 2 | $self->logger->info("We're being redirected to $new_location"); | |||||||||||||||||||||||||||||||||
| 696 | 2 | my $orig_server = $self->server; | |||||||||||||||||||||||||||||||||
| 697 | 2 | (my $suffix = $self->_uri($uri)) =~ s/^\Q$orig_server//; | |||||||||||||||||||||||||||||||||
| 698 | 2 | (my $new_server = $new_location) =~ s/\Q$suffix\E$//; | |||||||||||||||||||||||||||||||||
| 699 | 2 | $self->server($new_server); | |||||||||||||||||||||||||||||||||
| 700 | 2 | return $self->_submit($uri, $content, $auth); | |||||||||||||||||||||||||||||||||
| 701 | } else { | ||||||||||||||||||||||||||||||||||
| 702 | 2 | my $err_msg = $res->message; | |||||||||||||||||||||||||||||||||
| 703 | 2 | ▶ | if ($self->verbose_errors) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 704 | 2 | $err_msg = $res->message . ' fetching ' . $self->_uri($uri); | |||||||||||||||||||||||||||||||||
| 705 | }; | ||||||||||||||||||||||||||||||||||
| 706 | 2 | RT::Client::REST::HTTPException->throw( | |||||||||||||||||||||||||||||||||
| 707 | code => $res->code, | ||||||||||||||||||||||||||||||||||
| 708 | message => $err_msg, | ||||||||||||||||||||||||||||||||||
| 709 | ); | ||||||||||||||||||||||||||||||||||
| 710 | } | ||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||
| 712 | 7 | return $res; | |||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||
| 715 | 21 | ▶ | sub _ua { | ||||||||||||||||||||||||||||||||
|
Subroutine
_ua: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||
| 716 | 21 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||
| 718 | 21 | ▶ | unless (exists($self->{_ua})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||
| 720 | 11 | ▶ | my $args = $self->user_agent_args || {}; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->user_agent_args || {}
MC/DC100%1/1
$self->user_agent_args || {}
$self->user_agent_args
Truth table100%2/2
A
A= $self->user_agent_args
| |||||||||||||||||||||||||||||||||||
| 721 | 11 | ▶ | die "user_agent_args must be a hashref" unless ref($args) eq 'HASH'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 722 | 11 | $self->{_ua} = RT::Client::REST::HTTPClient->new( | |||||||||||||||||||||||||||||||||
| 723 | agent => $self->_ua_string, | ||||||||||||||||||||||||||||||||||
| 724 | env_proxy => 1, | ||||||||||||||||||||||||||||||||||
| 725 | max_redirect => 1, | ||||||||||||||||||||||||||||||||||
| 726 | %$args, | ||||||||||||||||||||||||||||||||||
| 727 | ); | ||||||||||||||||||||||||||||||||||
| 728 | 11 | ▶ | if ($self->timeout) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 729 | 11 | $self->{_ua}->timeout($self->timeout); | |||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||
| 731 | 11 | ▶ | if ($self->basic_auth_cb) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 732 | 3 | $self->{_ua}->basic_auth_cb($self->basic_auth_cb); | |||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||
| 734 | } | ||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||
| 736 | 21 | return $self->{_ua}; | |||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||
| 739 | 4 | ▶ | sub user_agent { | ||||||||||||||||||||||||||||||||
|
Subroutine
user_agent: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 740 | 4 | shift->_ua; | |||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||
| 744 | 48 | ▶ | sub basic_auth_cb { | ||||||||||||||||||||||||||||||||
|
Subroutine
basic_auth_cb: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 745 | 48 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||
| 747 | 48 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 748 | 6 | my $sub = shift; | |||||||||||||||||||||||||||||||||
| 749 | 6 | ▶ | unless ('CODE' eq ref($sub)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 750 | 2 | RT::Client::REST::InvalidParameterValueException->throw( | |||||||||||||||||||||||||||||||||
| 751 | "'basic_auth_cb' must be a code reference", | ||||||||||||||||||||||||||||||||||
| 752 | ); | ||||||||||||||||||||||||||||||||||
| 753 | } | ||||||||||||||||||||||||||||||||||
| 754 | 4 | $self->{_basic_auth_cb} = $sub; | |||||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||||||||
| 757 | 46 | return $self->{_basic_auth_cb}; | |||||||||||||||||||||||||||||||||
| 758 | } | ||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||
| 760 | # Sometimes PodCoverageTests think LOGGER_METHODS is a vanilla sub | ||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||
| 762 | 26 | ▶ | use constant LOGGER_METHODS => (qw(debug warn info error)); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||
| 764 | 73 | ▶ | sub logger { | ||||||||||||||||||||||||||||||||
|
Subroutine
logger: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 765 | 73 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 766 | 73 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 767 | 2 | my $new_logger = shift; | |||||||||||||||||||||||||||||||||
| 768 | 2 | for my $method (LOGGER_METHODS) { | |||||||||||||||||||||||||||||||||
| 769 | 6 | ▶ | unless ($new_logger->can($method)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 770 | 1 | RT::Client::REST::InvalidParameterValueException->throw( | |||||||||||||||||||||||||||||||||
| 771 | "logger does not know how to `$method'", | ||||||||||||||||||||||||||||||||||
| 772 | ); | ||||||||||||||||||||||||||||||||||
| 773 | } | ||||||||||||||||||||||||||||||||||
| 774 | } | ||||||||||||||||||||||||||||||||||
| 775 | 1 | $self->{'_logger'} = $new_logger; | |||||||||||||||||||||||||||||||||
| 776 | } | ||||||||||||||||||||||||||||||||||
| 777 | 72 | return $self->{'_logger'}; | |||||||||||||||||||||||||||||||||
| 778 | } | ||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||||||||
| 781 | # Not a constant so that it can be overridden. | ||||||||||||||||||||||||||||||||||
| 782 | 0 | ▶ | sub _list_of_valid_transaction_types { | ||||||||||||||||||||||||||||||||
|
Subroutine
_list_of_valid_transaction_types: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 783 | 0 | sort +(qw( | |||||||||||||||||||||||||||||||||
| 784 | Create Set Status Correspond Comment Give Steal Take Told | ||||||||||||||||||||||||||||||||||
| 785 | CustomField AddLink DeleteLink AddWatcher DelWatcher EmailRecord | ||||||||||||||||||||||||||||||||||
| 786 | )); | ||||||||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||
| 789 | 12 | ▶ | sub _valid_type { | ||||||||||||||||||||||||||||||||
|
Subroutine
_valid_type: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||
| 790 | 12 | my ($self, $type) = @_; | |||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||
| 792 | 12 | ▶ | unless ($type =~ /^[A-Za-z0-9_.-]+$/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 793 | 0 | RT::Client::REST::InvalidObjectTypeException->throw( | |||||||||||||||||||||||||||||||||
| 794 | "'$type' is not a valid object type", | ||||||||||||||||||||||||||||||||||
| 795 | ); | ||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||
| 798 | 12 | return $type; | |||||||||||||||||||||||||||||||||
| 799 | } | ||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||
| 801 | 0 | ▶ | sub _valid_objects { | ||||||||||||||||||||||||||||||||
|
Subroutine
_valid_objects: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 802 | 0 | my ($self, $objects) = @_; | |||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||
| 804 | 0 | ▶ | unless ('ARRAY' eq ref($objects)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 805 | 0 | RT::Client::REST::InvalidParameterValueException->throw( | |||||||||||||||||||||||||||||||||
| 806 | "'objects' must be an array reference", | ||||||||||||||||||||||||||||||||||
| 807 | ); | ||||||||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||
| 810 | 0 | return $objects; | |||||||||||||||||||||||||||||||||
| 811 | } | ||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||
| 813 | 20 | ▶ | sub _valid_numeric_object_id { | ||||||||||||||||||||||||||||||||
|
Subroutine
_valid_numeric_object_id: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||
| 814 | 20 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||||||||
| 816 | 20 | ▶ | unless ($id =~ m/^\d+$/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 817 | 0 | RT::Client::REST::InvalidParameterValueException->throw( | |||||||||||||||||||||||||||||||||
| 818 | "'$id' is not a valid numeric object ID", | ||||||||||||||||||||||||||||||||||
| 819 | ); | ||||||||||||||||||||||||||||||||||
| 820 | } | ||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||
| 822 | 20 | return $id; | |||||||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||
| 825 | 4 | ▶ | sub _valid_comment_action { | ||||||||||||||||||||||||||||||||
|
Subroutine
_valid_comment_action: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||||||||
| 826 | 4 | my ($self, $action) = @_; | |||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||
| 828 | 4 | ▶ | unless (grep { $_ eq lc($action) } (qw(comment correspond))) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 829 | 0 | RT::Client::REST::InvalidParameterValueException->throw( | |||||||||||||||||||||||||||||||||
| 830 | "'$action' is not a valid comment action", | ||||||||||||||||||||||||||||||||||
| 831 | ); | ||||||||||||||||||||||||||||||||||
| 832 | } | ||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||
| 834 | 4 | return lc($action); | |||||||||||||||||||||||||||||||||
| 835 | } | ||||||||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||||||||
| 837 | 4 | ▶ | sub _valid_comment_message { | ||||||||||||||||||||||||||||||||
|
Subroutine
_valid_comment_message: called CC=3 SCAR=13.3
| |||||||||||||||||||||||||||||||||||
| 838 | 4 | my ($self, $message) = @_; | |||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||
| 840 | 4 | ▶ | unless (defined($message) and length($message)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $message and length $message
MC/DC0%0/2
defined $message and length $message
defined $message
length $message
Truth table33%1/3
A and B
A= defined $messageB= length $message
| |||||||||||||||||||||||||||||||||||
| 841 | 0 | RT::Client::REST::InvalidParameterValueException->throw( | |||||||||||||||||||||||||||||||||
| 842 | "Comment cannot be empty (specify 'message' parameter)", | ||||||||||||||||||||||||||||||||||
| 843 | ); | ||||||||||||||||||||||||||||||||||
| 844 | } | ||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||
| 846 | 4 | return $message; | |||||||||||||||||||||||||||||||||
| 847 | } | ||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||
| 849 | 0 | ▶ | sub _valid_link_type { | ||||||||||||||||||||||||||||||||
|
Subroutine
_valid_link_type: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 850 | 0 | my ($self, $type) = @_; | |||||||||||||||||||||||||||||||||
| 851 | 0 | my @types = qw(DependsOn DependedOnBy RefersTo ReferredToBy HasMember Members | |||||||||||||||||||||||||||||||||
| 852 | MemberOf RunsOn IsRunning ComponentOf HasComponent); | ||||||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||||
| 854 | 0 | ▶ | unless (grep { lc($type) eq lc($_) } @types) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 855 | 0 | RT::Client::REST::InvalidParameterValueException->throw( | |||||||||||||||||||||||||||||||||
| 856 | "'$type' is not a valid link type", | ||||||||||||||||||||||||||||||||||
| 857 | ); | ||||||||||||||||||||||||||||||||||
| 858 | } | ||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||
| 860 | 0 | return lc($type); | |||||||||||||||||||||||||||||||||
| 861 | } | ||||||||||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||||||||
| 863 | 0 | ▶ | sub _valid_transaction_type { | ||||||||||||||||||||||||||||||||
|
Subroutine
_valid_transaction_type: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 864 | 0 | my ($self, $type) = @_; | |||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||||
| 866 | 0 | ▶ | unless (grep { $type eq $_ } $self->_list_of_valid_transaction_types) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 867 | 0 | RT::Client::REST::InvalidParameterValueException->throw( | |||||||||||||||||||||||||||||||||
| 868 | "'$type' is not a valid transaction type. Allowed types: " . | ||||||||||||||||||||||||||||||||||
| 869 | join(', ', $self->_list_of_valid_transaction_types) | ||||||||||||||||||||||||||||||||||
| 870 | ); | ||||||||||||||||||||||||||||||||||
| 871 | } | ||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||
| 873 | 0 | return $type; | |||||||||||||||||||||||||||||||||
| 874 | } | ||||||||||||||||||||||||||||||||||
| 875 | |||||||||||||||||||||||||||||||||||
| 876 | 49 | ▶ | sub _assert_even { | ||||||||||||||||||||||||||||||||
|
Subroutine
_assert_even: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||
| 877 | 49 | shift; | |||||||||||||||||||||||||||||||||
| 878 | 49 | ▶ | RT::Client::REST::OddNumberOfArgumentsException->throw( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 879 | "odd number of arguments passed") if @_ & 1; | ||||||||||||||||||||||||||||||||||
| 880 | } | ||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||
| 882 | 24 | ▶ | sub _rest { | ||||||||||||||||||||||||||||||||
|
Subroutine
_rest: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||||||||
| 883 | 24 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 884 | 24 | my $server = $self->server; | |||||||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||||||||
| 886 | 24 | ▶ | unless (defined($server)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 887 | 0 | RT::Client::REST::RequiredAttributeUnsetException->throw( | |||||||||||||||||||||||||||||||||
| 888 | "'server' attribute is not set", | ||||||||||||||||||||||||||||||||||
| 889 | ); | ||||||||||||||||||||||||||||||||||
| 890 | } | ||||||||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||||||||
| 892 | 24 | return $server . '/REST/1.0'; | |||||||||||||||||||||||||||||||||
| 893 | } | ||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||
| 895 | 22 | ▶ | sub _uri { shift->_rest . '/' . shift } | ||||||||||||||||||||||||||||||||
|
Subroutine
_uri: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||
| 897 | 11 | ▶ | sub _ua_string { | ||||||||||||||||||||||||||||||||
|
Subroutine
_ua_string: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||
| 898 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 899 | 11 | ▶ | return ref($self) . '/' . ($self->_version || '???'); | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_version || '???'
MC/DC0%0/1
$self->_version || '???'
$self->_version
Truth table50%1/2
A
A= $self->_version
| |||||||||||||||||||||||||||||||||||
| 900 | } | ||||||||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||||||||
| 902 | 11 | ▶ | sub _version { $RT::Client::REST::VERSION } | ||||||||||||||||||||||||||||||||
|
Subroutine
_version: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||
| 904 | { | ||||||||||||||||||||||||||||||||||
| 905 | # This is a noop logger: it discards all log messages. It is the default | ||||||||||||||||||||||||||||||||||
| 906 | # logger. I think this approach is better than doing either checks all | ||||||||||||||||||||||||||||||||||
| 907 | # over the place like this: | ||||||||||||||||||||||||||||||||||
| 908 | # | ||||||||||||||||||||||||||||||||||
| 909 | # if ($self->logger) { | ||||||||||||||||||||||||||||||||||
| 910 | # $self->logger->warn("message"); | ||||||||||||||||||||||||||||||||||
| 911 | # } | ||||||||||||||||||||||||||||||||||
| 912 | # | ||||||||||||||||||||||||||||||||||
| 913 | # or creating our own logging methods which will hide the checks: | ||||||||||||||||||||||||||||||||||
| 914 | # | ||||||||||||||||||||||||||||||||||
| 915 | # sub warn { | ||||||||||||||||||||||||||||||||||
| 916 | # my $self = shift; | ||||||||||||||||||||||||||||||||||
| 917 | # if ($self->logger) { | ||||||||||||||||||||||||||||||||||
| 918 | # $self->logger->warn(@_); | ||||||||||||||||||||||||||||||||||
| 919 | # } | ||||||||||||||||||||||||||||||||||
| 920 | # } | ||||||||||||||||||||||||||||||||||
| 921 | # # and later: | ||||||||||||||||||||||||||||||||||
| 922 | # sub xyz { | ||||||||||||||||||||||||||||||||||
| 923 | # ... | ||||||||||||||||||||||||||||||||||
| 924 | # $self->warn("message"); | ||||||||||||||||||||||||||||||||||
| 925 | # } | ||||||||||||||||||||||||||||||||||
| 926 | # | ||||||||||||||||||||||||||||||||||
| 927 | # The problem with the second approach is that it creates unrelated | ||||||||||||||||||||||||||||||||||
| 928 | # methods in RT::Client::REST namespace. | ||||||||||||||||||||||||||||||||||
| 929 | 26 | package RT::Client::REST::NoopLogger; | |||||||||||||||||||||||||||||||||
| 930 | 26 | $RT::Client::REST::NoopLogger::VERSION = '0.73'; | |||||||||||||||||||||||||||||||||
| 931 | 25 | ▶ | sub new { bless \(my $logger), __PACKAGE__ } | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 932 | 26 | for my $method (RT::Client::REST::LOGGER_METHODS) { | |||||||||||||||||||||||||||||||||
| 933 | 26 | ▶ | no strict 'refs'; ## no critic (ProhibitNoStrict) | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 934 | 104 | ▶ | *{$method} = sub {}; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 935 | } | ||||||||||||||||||||||||||||||||||
| 936 | } | ||||||||||||||||||||||||||||||||||
| 937 | |||||||||||||||||||||||||||||||||||
| 938 | 26 | 1; | |||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||
| 940 | __END__ | ||||||||||||||||||||||||||||||||||