| 1 | package Stash::REST; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008_005; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | our $VERSION = '0.11'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use URI::QueryParam; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use HTTP::Request::Common qw(GET POST DELETE HEAD); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Carp qw/confess cluck/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Class::Trigger; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | has 'do_request' => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | isa => sub { die "$_[0] is not a CodeRef" unless ref $_[0] eq 'CODE' }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | required => 1 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | has 'decode_response' => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | isa => sub { die "$_[0] is not a CodeRef" unless ref $_[0] eq 'CODE' }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | required => 1 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | has 'stash' => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | isa => sub { die "$_[0] is not a HashRef" unless ref $_[0] eq 'HASH' }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | default => sub { {} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | has 'fixed_headers' => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | ▶ | isa => sub { die "$_[0] is not a ArrayRef" unless ref $_[0] eq 'ARRAY' }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | default => sub { [] } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 89 | ▶ | around 'stash' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 89 | my $orig = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 89 | my $c = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 89 | my $stash = $orig->($c); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 89 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 23 | ▶ | return $stash->{ $_[0] } if ( @_ == 1 && ref $_[0] eq '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ == 1 and ref $_[0] eq ""
MC/DC50%1/2
@_ == 1 and ref $_[0] eq ""
@_ == 1
ref $_[0] eq ""
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 18 | ▶ | my $new_stash = @_ > 1 ? {@_} : $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 18 | ▶ | die('stash takes a hash or hashref') unless ref $new_stash; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 18 | foreach my $key ( keys %$new_stash ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 19 | $stash->{$key} = $new_stash->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 84 | return $stash; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 20 | ▶ | sub _capture_args { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_capture_args: called CC=22 SCAR=33.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 20 | my ( $method, $self, @params ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 20 | my ( $uri, $data, %conf ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 20 | ▶ | confess 'invalid number of params' if @params < 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 19 | $uri = shift @params; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 19 | ▶ | confess 'invalid uri param' if ref $uri ne '' && ref $uri ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $uri ne "" and ref $uri ne "ARRAY"
MC/DC100%2/2
ref $uri ne "" and ref $uri ne "ARRAY"
ref $uri ne ""
ref $uri ne "ARRAY"
Truth table100%3/3
A and B
A= ref $uri ne ""B= ref $uri ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 18 | ▶ | $uri = join '/', @$uri if ref $uri eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # if number of params is odd, then, the last item is defined as $data | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 18 | ▶ | if ( scalar @params % 2 == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 12 | %conf = @params; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 12 | ▶ | $data = exists $conf{data} ? $conf{data} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 6 | $data = pop @params; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 6 | %conf = @params; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | $conf{headers} = [ %{ $conf{headers} } ] if exists $conf{headers} && ref $conf{headers} eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $conf{"headers"} and ref $conf{"headers"} eq "HASH"
MC/DC0%0/2
exists $conf{"headers"} and ref $conf{"headers"} eq "HASH"
exists $conf{"headers"}
ref $conf{"headers"} eq "HASH"
Truth table66%2/3
A and B
A= exists $conf{"headers"}B= ref $conf{"headers"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | confess "Can't use ->{files} helper with custom Content-Type." | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if exists $conf{files} && ( exists $conf{headers} && grep { /Content-Type/i } @{ $conf{headers} } ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
exists $conf{"files"} and (exists $conf{"headers"} and grep {/Content-Type/i;} @{$conf{"headers"};})
exists $conf{"headers"} and grep {/Content-Type/i;} @{$conf{"headers"};}
MC/DC0%0/3
exists $conf{"files"} and (exists $conf{"headers"} and grep {/Content-Type/i;} @{$conf{"headers"};})
exists $conf{"files"}
exists $conf{"headers"}
grep {/Content-Type/i;} @{$conf{"headers"};}
Truth table50%2/4
A and B and C
A= exists $conf{"files"}B= exists $conf{"headers"}C= grep {/Content-Type/i;} @{$conf{"headers"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 18 | my $can_have_body = $method =~ /POST|PUT|DELETE/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 18 | ▶ | if ( !$can_have_body && $data && exists $conf{params} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%6/6
not $can_have_body and $data and exists $conf{"params"}
not $can_have_body and $data
MC/DC100%3/3
not $can_have_body and $data and exists $conf{"params"}
not $can_have_body
$data
exists $conf{"params"}
Truth table100%4/4
not(A) and B and C
A= not $can_have_bodyB= $dataC= exists $conf{"params"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | confess "You are using {data} and {params} in $method. Please, use only {params} instead" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | unless $conf{allow_get_with_body}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $conf{data} = $data; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | ▶ | elsif ( !$can_have_body && $data && !exists $conf{params} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
not $can_have_body and $data and not exists $conf{"params"}
not $can_have_body and $data
MC/DC66%2/3
not $can_have_body and $data and not exists $conf{"params"}
not $can_have_body
$data
not exists $conf{"params"}
Truth table75%3/4
not(A) and B and not(C)
A= not $can_have_bodyB= $dataC= not exists $conf{"params"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 3 | $conf{params} = $data; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | ▶ | elsif ( !$can_have_body && $data ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not $can_have_body and $data
MC/DC0%0/2
not $can_have_body and $data
not $can_have_body
$data
Truth table66%2/3
not(A) and B
A= not $can_have_bodyB= $data
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | confess "$method does not allow body. You may have problems with proxy. Consider removing it" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | unless $conf{allow_get_with_body}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $conf{data} = $data; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 14 | $conf{data} = $data; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 17 | return ( $self, $uri, %conf ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | ▶ | sub rest_put { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rest_put: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | my ( $self, $url, %conf ) = &_capture_args( 'PUT', @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | $self->call_trigger( 'before_rest_put', { url => $url, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | $self->_rest_request( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | $url, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | code => ( exists $conf{is_fail} ? 400 : 202 ), | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | %conf, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | method => 'PUT' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | ▶ | sub rest_head { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rest_head: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | my ( $self, $url, %conf ) = &_capture_args( 'HEAD', @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | $self->call_trigger( 'before_rest_head', { url => $url, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | $self->_rest_request( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | $url, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | code => 200, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | %conf, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | method => 'HEAD' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | ▶ | sub rest_delete { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rest_delete: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | my ( $self, $url, %conf ) = &_capture_args( 'DELETE', @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | $self->call_trigger( 'before_rest_delete', { url => $url, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | $self->_rest_request( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | $url, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | code => 204, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | %conf, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | method => 'DELETE' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 10 | ▶ | sub rest_get { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rest_get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 10 | my ( $self, $url, %conf ) = &_capture_args( 'GET', @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 7 | $self->call_trigger( 'before_rest_get', { url => $url, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 7 | $self->_rest_request( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | $url, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | code => 200, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | %conf, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | method => 'GET' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 7 | ▶ | sub rest_post { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rest_post: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 7 | my ( $self, $url, %conf ) = &_capture_args( 'POST', @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 7 | $self->call_trigger( 'before_rest_post', { url => $url, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 7 | $self->_rest_request( $url, %conf, method => 'POST' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 17 | ▶ | sub _rest_request { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rest_request: called CC=51 SCAR=44.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 17 | my ( $self, $url, %conf ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 17 | ▶ | my $data = exists $conf{data} ? $conf{data} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 17 | ▶ | $conf{automatic_load_item} = 1 unless exists $conf{automatic_load_item}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 17 | ▶ | my $is_fail = exists $conf{is_fail} && $conf{is_fail}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
exists $conf{'is_fail'} && $conf{'is_fail'}
MC/DC100%2/2
exists $conf{'is_fail'} && $conf{'is_fail'}
exists $conf{'is_fail'}
$conf{'is_fail'}
Truth table100%3/3
A && B
A= exists $conf{'is_fail'}B= $conf{'is_fail'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 17 | my $code = $conf{code}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 17 | ▶ | $code ||= $is_fail ? 400 : 201; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$code ||= $is_fail ? 400 : 201
MC/DC0%0/2
$code ||= $is_fail ? 400 : 201
$code
$is_fail ? 400 : 201
Truth table66%2/3
A ||= B
A= $codeB= $is_fail ? 400 : 201
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 17 | $conf{code} = $code; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 17 | my $uri = URI->new($url); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 17 | ▶ | if ( $conf{params} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | my @old = ref $conf{params} eq 'ARRAY' ? @{ $conf{params} } : %{ $conf{params} }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 6 | ▶ | while ( my ( $k, $v ) = splice( @old, 0, 2 ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 8 | $uri->query_param_append( $k, $v ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 17 | $url = $uri->as_string; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 17 | ▶ | my $stashkey = exists $conf{stash} ? $conf{stash} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 17 | ▶ | my @headers = ( @{ $self->fixed_headers() }, @{ $conf{headers} || [] } ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$conf{'headers'} || []
MC/DC100%1/1
$conf{'headers'} || []
$conf{'headers'}
Truth table100%2/2
A
A= $conf{'headers'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 17 | my $req; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 17 | ▶ | if ( !exists $conf{files} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 16 | ▶ | if ( defined $data ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 9 | $req = POST $url, @headers, Content => $data; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 7 | $req = GET $url, @headers; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | $conf{files}{$_} = [ $conf{files}{$_} ] for keys %{ $conf{files} }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | $req = POST $url, @headers, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 'Content-Type' => 'form-data', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | ▶ | Content => [ ( $data && ref $data eq 'ARRAY' ? @$data : () ), %{ $conf{files} } ]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$data and ref $data eq "ARRAY"
MC/DC0%0/2
$data and ref $data eq "ARRAY"
$data
ref $data eq "ARRAY"
Truth table33%1/3
A and B
A= $dataB= ref $data eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | $conf{process_request}->( { req => $req, conf => \%conf } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 17 | ▶ | if ( exists $conf{process_request} && ref $conf{process_request} eq 'CODE' ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $conf{"process_request"} and ref $conf{"process_request"} eq "CODE"
MC/DC0%0/2
exists $conf{"process_request"} and ref $conf{"process_request"} eq "CODE"
exists $conf{"process_request"}
ref $conf{"process_request"} eq "CODE"
Truth table33%1/3
A and B
A= exists $conf{"process_request"}B= ref $conf{"process_request"} eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 17 | $self->call_trigger( 'process_request', { req => $req, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # change to correct method. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 17 | $req->method( $conf{method} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 17 | my $res = eval { $self->do_request()->($req) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 17 | ▶ | confess "request died: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | $conf{process_response}->( { req => $req, res => $res, conf => \%conf } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 17 | ▶ | if ( exists $conf{process_response} && ref $conf{process_response} eq 'CODE' ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $conf{"process_response"} and ref $conf{"process_response"} eq "CODE"
MC/DC0%0/2
exists $conf{"process_response"} and ref $conf{"process_response"} eq "CODE"
exists $conf{"process_response"}
ref $conf{"process_response"} eq "CODE"
Truth table33%1/3
A and B
A= exists $conf{"process_response"}B= ref $conf{"process_response"} eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 17 | $self->call_trigger( 'process_response', { req => $req, res => $res, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | #is( $res->code, $code, $name . ' status code is ' . $code ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 17 | ▶ | if ( !exists $conf{skip_response_tests} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 17 | ▶ | confess 'response expected fail and it is successed' if $is_fail && $res->is_success; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$is_fail and $res->is_success
MC/DC100%2/2
$is_fail and $res->is_success
$is_fail
$res->is_success
Truth table100%3/3
A and B
A= $is_failB= $res->is_success
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 16 | ▶ | confess 'response expected success and it is failed' if !$is_fail && !$res->is_success; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$is_fail or $res->is_success
MC/DC100%2/2
$is_fail or $res->is_success
$is_fail
$res->is_success
Truth table100%3/3
A or B
A= $is_failB= $res->is_success
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 15 | ▶ | confess 'response code [', $res->code, '] diverge expected [', $code, ']' if $code != $res->code; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | $conf{process_response_success}->( { req => $req, res => $res, conf => \%conf } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 14 | ▶ | if ( exists $conf{process_response_success} && ref $conf{process_response_success} eq 'CODE' ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $conf{"process_response_success"} and ref $conf{"process_response_success"} eq "CODE"
MC/DC0%0/2
exists $conf{"process_response_success"} and ref $conf{"process_response_success"} eq "CODE"
exists $conf{"process_response_success"}
ref $conf{"process_response_success"} eq "CODE"
Truth table33%1/3
A and B
A= exists $conf{"process_response_success"}B= ref $conf{"process_response_success"} eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 14 | $self->call_trigger( 'process_response_success', { req => $req, res => $res, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 14 | ▶ | return '' if $code == 204; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 13 | ▶ | return $res if exists $conf{method} && $conf{method} eq 'HEAD'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $conf{"method"} and $conf{"method"} eq "HEAD"
MC/DC50%1/2
exists $conf{"method"} and $conf{"method"} eq "HEAD"
exists $conf{"method"}
$conf{"method"} eq "HEAD"
Truth table66%2/3
A and B
A= exists $conf{"method"}B= $conf{"method"} eq "HEAD"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 12 | my $obj = eval { $self->decode_response()->($res) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 12 | ▶ | confess("decode_response failed: $@") if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | $conf{response_decoded}->( { req => $req, res => $res, decoded => $obj, conf => \%conf } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 12 | ▶ | if ( exists $conf{response_decoded} && ref $conf{response_decoded} eq 'CODE' ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $conf{"response_decoded"} and ref $conf{"response_decoded"} eq "CODE"
MC/DC0%0/2
exists $conf{"response_decoded"} and ref $conf{"response_decoded"} eq "CODE"
exists $conf{"response_decoded"}
ref $conf{"response_decoded"} eq "CODE"
Truth table33%1/3
A and B
A= exists $conf{"response_decoded"}B= ref $conf{"response_decoded"} eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 12 | $self->call_trigger( 'response_decoded', { req => $req, res => $res, decoded => $obj, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 12 | ▶ | if ($stashkey) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 11 | $self->stash->{$stashkey} = $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 11 | ▶ | $self->stash( $stashkey . '.prepare_request' => $conf{prepare_request} ) if exists $conf{prepare_request}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 11 | ▶ | if ( $code == 201 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 4 | ▶ | $self->stash( $stashkey . '.id' => $obj->{id} ) if ref $obj eq 'HASH' && exists $obj->{id}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $obj eq "HASH" and exists $obj->{"id"}
MC/DC0%0/2
ref $obj eq "HASH" and exists $obj->{"id"}
ref $obj eq "HASH"
exists $obj->{"id"}
Truth table33%1/3
A and B
A= ref $obj eq "HASH"B= exists $obj->{"id"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 4 | my $item_url = $res->header('Location'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 4 | ▶ | if ( $item_url && $conf{automatic_load_item} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$item_url and $conf{"automatic_load_item"}
MC/DC0%0/2
$item_url and $conf{"automatic_load_item"}
$item_url
$conf{"automatic_load_item"}
Truth table33%1/3
A and B
A= $item_urlB= $conf{"automatic_load_item"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 4 | $self->stash->{ $stashkey . '.url' } = $item_url; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 4 | $self->rest_reload($stashkey); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | $conf{item_loaded}->( { stash => $stashkey, conf => \%conf } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 3 | ▶ | if ( exists $conf{item_loaded} && ref $conf{item_loaded} eq 'CODE' ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $conf{"item_loaded"} and ref $conf{"item_loaded"} eq "CODE"
MC/DC0%0/2
exists $conf{"item_loaded"} and ref $conf{"item_loaded"} eq "CODE"
exists $conf{"item_loaded"}
ref $conf{"item_loaded"} eq "CODE"
Truth table33%1/3
A and B
A= exists $conf{"item_loaded"}B= ref $conf{"item_loaded"} eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 3 | $self->call_trigger( 'item_loaded', { stash => $stashkey, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | elsif ( $conf{automatic_load_item} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | confess 'requests with response code 201 should contain header Location'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | $conf{stash_added}->( { stash => $stashkey, conf => \%conf } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 3 | ▶ | if ( exists $conf{stash_added} && ref $conf{stash_added} eq 'CODE' ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $conf{"stash_added"} and ref $conf{"stash_added"} eq "CODE"
MC/DC0%0/2
exists $conf{"stash_added"} and ref $conf{"stash_added"} eq "CODE"
exists $conf{"stash_added"}
ref $conf{"stash_added"} eq "CODE"
Truth table33%1/3
A and B
A= exists $conf{"stash_added"}B= ref $conf{"stash_added"} eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 3 | $self->call_trigger( 'stash_added', { stash => $stashkey, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 11 | ▶ | if ( $stashkey && exists $conf{list} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$stashkey and exists $conf{"list"}
MC/DC100%2/2
$stashkey and exists $conf{"list"}
$stashkey
exists $conf{"list"}
Truth table100%3/3
A and B
A= $stashkeyB= exists $conf{"list"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 2 | $self->stash( $stashkey . '.list-url' => $url ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 2 | $self->rest_reload_list($stashkey); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | $conf{list_loaded}->( { stash => $stashkey, conf => \%conf } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 2 | ▶ | if ( exists $conf{list_loaded} && ref $conf{list_loaded} eq 'CODE' ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $conf{"list_loaded"} and ref $conf{"list_loaded"} eq "CODE"
MC/DC0%0/2
exists $conf{"list_loaded"} and ref $conf{"list_loaded"} eq "CODE"
exists $conf{"list_loaded"}
ref $conf{"list_loaded"} eq "CODE"
Truth table33%1/3
A and B
A= exists $conf{"list_loaded"}B= ref $conf{"list_loaded"} eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 2 | $self->call_trigger( 'list_loaded', { stash => $stashkey, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 11 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 6 | ▶ | sub rest_reload { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rest_reload: called CC=12 SCAR=25.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 6 | my $stashkey = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 6 | my %conf = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 6 | ▶ | my $code = exists $conf{code} ? $conf{code} : 200; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 6 | $conf{code} = $code; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 6 | ▶ | my @headers = ( @{ $self->fixed_headers() }, @{ $conf{headers} || [] } ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$conf{'headers'} || []
MC/DC0%0/1
$conf{'headers'} || []
$conf{'headers'}
Truth table50%1/2
A
A= $conf{'headers'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 6 | my $item_url = $self->stash->{ $stashkey . '.url' }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 6 | ▶ | confess "can't stash $stashkey.url is not valid" unless $item_url; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | my $prepare_request = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | exists $self->stash->{ $stashkey . '.prepare_request' } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 6 | ▶ | ? $self->stash->{ $stashkey . '.prepare_request' } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 6 | ▶ | confess 'prepare_request must be a coderef' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$prepare_request and ref $prepare_request ne "CODE"
MC/DC50%1/2
$prepare_request and ref $prepare_request ne "CODE"
$prepare_request
ref $prepare_request ne "CODE"
Truth table66%2/3
A and B
A= $prepare_requestB= ref $prepare_request ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | if $prepare_request && ref $prepare_request ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 5 | my $req = GET $item_url, @headers; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 5 | $req->method('GET'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 5 | ▶ | $prepare_request->($req) if $prepare_request; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 5 | $self->call_trigger( 'process_request', { req => $req, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 5 | my $res = $self->do_request()->($req); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 5 | $self->call_trigger( 'process_response', { req => $req, res => $res, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 5 | ▶ | confess 'request code diverge expected' if $code != $res->code; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 5 | $self->call_trigger( 'process_response_success', { req => $req, res => $res, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 5 | my $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 5 | ▶ | if ( $res->code == 200 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 4 | my $obj = eval { $self->decode_response()->($res) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 4 | ▶ | confess("decode_response failed: $@") if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 4 | $self->call_trigger( 'response_decoded', { req => $req, res => $res, decoded => $obj, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 4 | $self->stash( $stashkey . '.get' => $obj ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | elsif ( $res->code == 404 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 1 | $self->call_trigger( 'stash_removed', { stash => $stashkey, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | # $self->stash->{ $stashkey . '.get' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 1 | delete $self->stash->{ $stashkey . '.id' }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 1 | delete $self->stash->{ $stashkey . '.url' }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 1 | delete $self->stash->{$stashkey}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | confess 'response code ' . $res->code . ' is not valid for rest_reload'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 5 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 3 | ▶ | sub rest_reload_list { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rest_reload_list: called CC=11 SCAR=25.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 3 | my $stashkey = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 3 | my %conf = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 3 | ▶ | my $code = exists $conf{code} ? $conf{code} : 200; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 3 | $conf{code} = $code; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 3 | ▶ | my @headers = ( @{ $self->fixed_headers() }, @{ $conf{headers} || [] } ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$conf{'headers'} || []
MC/DC0%0/1
$conf{'headers'} || []
$conf{'headers'}
Truth table50%1/2
A
A= $conf{'headers'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 3 | my $item_url = $self->stash->{ $stashkey . '.list-url' }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 3 | ▶ | confess "can't stash $stashkey.list-url is not valid" unless $item_url; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | my $prepare_request = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | exists $self->stash->{ $stashkey . '.prepare_request' } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 3 | ▶ | ? $self->stash->{ $stashkey . '.prepare_request' } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 3 | ▶ | confess 'prepare_request must be a coderef' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$prepare_request and ref $prepare_request ne "CODE"
MC/DC0%0/2
$prepare_request and ref $prepare_request ne "CODE"
$prepare_request
ref $prepare_request ne "CODE"
Truth table33%1/3
A and B
A= $prepare_requestB= ref $prepare_request ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | if $prepare_request && ref $prepare_request ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 3 | my $req = GET $item_url, @headers; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 3 | ▶ | $prepare_request->($req) if $prepare_request; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 3 | $self->call_trigger( 'process_request', { req => $req, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 3 | my $res = $self->do_request()->($req); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 3 | $self->call_trigger( 'process_response', { req => $req, res => $res, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 3 | ▶ | confess 'request code diverge expected' if $code != $res->code; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 3 | $self->call_trigger( 'process_response_success', { req => $req, res => $res, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 3 | my $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 3 | ▶ | if ( $res->code == 200 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 3 | my $obj = eval { $self->decode_response()->($res) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 3 | ▶ | confess("decode_response failed: $@") if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 3 | $self->call_trigger( 'response_decoded', { req => $req, res => $res, decoded => $obj, conf => \%conf } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 3 | $self->stash( $stashkey . '.list' => $obj ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | confess 'response code ' . $res->code . ' is not valid for rest_reload'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 3 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 10 | ▶ | sub stash_ctx { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stash_ctx: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 10 | my ( $self, $staname, $sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 10 | $self->call_trigger( 'before_stash_ctx', { stash => $staname } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 10 | my @ret = $sub->( $self->stash->{$staname} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 10 | $self->call_trigger( 'after_stash_ctx', { stash => $staname, results => \@ret } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 10 | return @ret; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||