| 1 | package HTTP::API::Core::Pagination; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 43 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 43 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 72 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=54 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 72 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 72 | ▶ | die "pagination options must be key/value pairs\n" if @_ % 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | die "pagination option names must be scalars\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 72 | ▶ | if grep { ref($_) ne '' } @_[ grep { $_ % 2 == 0 } 0 .. $#_ ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 72 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 72 | ▶ | die "client is required\n" if !exists $args{client} || !defined $args{client}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $args{"client"} and defined $args{"client"}
MC/DC50%1/2
exists $args{"client"} and defined $args{"client"}
exists $args{"client"}
defined $args{"client"}
Truth table66%2/3
A and B
A= exists $args{"client"}B= defined $args{"client"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 71 | my $client = delete $args{client}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 71 | my $path = delete $args{path}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 71 | ▶ | die "path is required\n" if !defined $path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 70 | ▶ | die "path must be a scalar\n" if ref($path) ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 69 | my $mode = delete($args{mode}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 69 | ▶ | die "mode must be a scalar\n" if ref($mode) ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 67 | ▶ | $mode = 'next_url' if !defined($mode) || $mode eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $mode or $mode eq ""
MC/DC50%1/2
not defined $mode or $mode eq ""
not defined $mode
$mode eq ""
Truth table66%2/3
not(A) or B
A= not defined $modeB= $mode eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 67 | ▶ | die "unsupported pagination mode: $mode\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$mode ne "next_url" and $mode ne "page" and $mode ne "cursor" and $mode ne "offset"
$mode ne "next_url" and $mode ne "page" and $mode ne "cursor"
$mode ne "next_url" and $mode ne "page"
MC/DC100%4/4
$mode ne "next_url" and $mode ne "page" and $mode ne "cursor" and $mode ne "offset"
$mode ne "next_url"
$mode ne "page"
$mode ne "cursor"
$mode ne "offset"
Truth table100%5/5
A and B and C and D
A= $mode ne "next_url"B= $mode ne "page"C= $mode ne "cursor"D= $mode ne "offset"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | if $mode ne 'next_url' && $mode ne 'page' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | && $mode ne 'cursor' && $mode ne 'offset'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 66 | my $items = delete($args{items}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 66 | ▶ | $items = 'items' if !defined $items; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 66 | my $response_aware_extractors = delete($args{response_aware_extractors}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 66 | ▶ | die "response_aware_extractors must be a scalar\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $response_aware_extractors and ref $response_aware_extractors ne ""
MC/DC0%0/2
defined $response_aware_extractors and ref $response_aware_extractors ne ""
defined $response_aware_extractors
ref $response_aware_extractors ne ""
Truth table66%2/3
A and B
A= defined $response_aware_extractorsB= ref $response_aware_extractors ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | if defined($response_aware_extractors) && ref($response_aware_extractors) ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 66 | my $allow_cross_origin = delete($args{allow_cross_origin}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 66 | ▶ | die "allow_cross_origin must be a scalar\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $allow_cross_origin and ref $allow_cross_origin ne ""
MC/DC0%0/2
defined $allow_cross_origin and ref $allow_cross_origin ne ""
defined $allow_cross_origin
ref $allow_cross_origin ne ""
Truth table66%2/3
A and B
A= defined $allow_cross_originB= ref $allow_cross_origin ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | if defined($allow_cross_origin) && ref($allow_cross_origin) ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | client => $client, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | path => $path, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | mode => $mode, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | items => $items, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | next => exists($args{next}) ? delete($args{next}) : ($mode eq 'cursor' ? 'next_cursor' : 'next'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | has_more => delete($args{has_more}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | total => delete($args{total}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | response_aware_extractors => $response_aware_extractors ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | allow_cross_origin => $allow_cross_origin ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | page_param => exists($args{page_param}) ? delete($args{page_param}) : 'page', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | page_size_param => exists($args{page_size_param}) ? delete($args{page_size_param}) : 'per_page', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | page_size => delete($args{page_size}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | current_page => exists($args{start_page}) ? delete($args{start_page}) : 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | offset_param => exists($args{offset_param}) ? delete($args{offset_param}) : 'offset', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | current_offset => exists($args{start_offset}) ? delete($args{start_offset}) : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | cursor_param => exists($args{cursor_param}) ? delete($args{cursor_param}) : 'cursor', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | cursor => delete($args{cursor}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | query => exists($args{query}) ? delete($args{query}) : {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 66 | ▶ | request => exists($args{request}) ? delete($args{request}) : {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 12 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | buffer => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | finished => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | started => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | seen => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 66 | for my $name (qw(items next has_more total)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 264 | ▶ | next if !defined $self->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | die "pagination $name extractor must be a code reference or scalar path\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 142 | ▶ | if ref($self->{$name}) ne '' && ref($self->{$name}) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $self->{$name} ne "" and ref $self->{$name} ne "CODE"
MC/DC100%2/2
ref $self->{$name} ne "" and ref $self->{$name} ne "CODE"
ref $self->{$name} ne ""
ref $self->{$name} ne "CODE"
Truth table100%3/3
A and B
A= ref $self->{$name} ne ""B= ref $self->{$name} ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 65 | for my $name (qw(page_param page_size_param cursor_param offset_param)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | die "pagination $name must be a non-empty scalar\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 260 | ▶ | if !defined($self->{$name}) || ref($self->{$name}) ne '' || $self->{$name} eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not defined $self->{$name} or ref $self->{$name} ne "" or $self->{$name} eq ""
not defined $self->{$name} or ref $self->{$name} ne ""
MC/DC33%1/3
not defined $self->{$name} or ref $self->{$name} ne "" or $self->{$name} eq ""
not defined $self->{$name}
ref $self->{$name} ne ""
$self->{$name} eq ""
Truth table50%2/4
not(A) or B or C
A= not defined $self->{$name}B= ref $self->{$name} ne ""C= $self->{$name} eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | die "cursor must be a scalar or undef\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 64 | ▶ | if defined($self->{cursor}) && ref($self->{cursor}) ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"cursor"} and ref $self->{"cursor"} ne ""
MC/DC0%0/2
defined $self->{"cursor"} and ref $self->{"cursor"} ne ""
defined $self->{"cursor"}
ref $self->{"cursor"} ne ""
Truth table66%2/3
A and B
A= defined $self->{"cursor"}B= ref $self->{"cursor"} ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 64 | ▶ | die "query must be a hash reference\n" if ref($self->{query}) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 63 | ▶ | die "request must be a hash reference\n" if ref($self->{request}) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | die "page_size must be a positive integer\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 62 | ▶ | if defined($self->{page_size}) && (ref($self->{page_size}) ne '' || $self->{page_size} !~ /\A[0-9]+\z/ || $self->{page_size} < 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
defined $self->{"page_size"} and ref $self->{"page_size"} ne "" || !($self->{"page_size"} =~ /\A[0-9]+\z/) || $self->{"page_size"} < 1
ref $self->{"page_size"} ne "" or not $self->{"page_size"} =~ /\A[0-9]+\z/ or $self->{"page_size"} < 1
ref $self->{"page_size"} ne "" or not $self->{"page_size"} =~ /\A[0-9]+\z/
MC/DC100%4/4
defined $self->{"page_size"} and ref $self->{"page_size"} ne "" || !($self->{"page_size"} =~ /\A[0-9]+\z/) || $self->{"page_size"} < 1
defined $self->{"page_size"}
ref $self->{"page_size"} ne ""
not $self->{"page_size"} =~ /\A[0-9]+\z/
$self->{"page_size"} < 1
Truth table100%5/5
A and B or not(C) or D
A= defined $self->{"page_size"}B= ref $self->{"page_size"} ne ""C= not $self->{"page_size"} =~ /\A[0-9]+\z/D= $self->{"page_size"} < 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | die "start_page must be a positive integer\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 58 | ▶ | if ref($self->{current_page}) ne '' || $self->{current_page} !~ /\A[0-9]+\z/ || $self->{current_page} < 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
ref $self->{"current_page"} ne "" or not $self->{"current_page"} =~ /\A[0-9]+\z/ or $self->{"current_page"} < 1
ref $self->{"current_page"} ne "" or not $self->{"current_page"} =~ /\A[0-9]+\z/
MC/DC100%3/3
ref $self->{"current_page"} ne "" or not $self->{"current_page"} =~ /\A[0-9]+\z/ or $self->{"current_page"} < 1
ref $self->{"current_page"} ne ""
not $self->{"current_page"} =~ /\A[0-9]+\z/
$self->{"current_page"} < 1
Truth table100%4/4
A or not(B) or C
A= ref $self->{"current_page"} ne ""B= not $self->{"current_page"} =~ /\A[0-9]+\z/C= $self->{"current_page"} < 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | die "start_offset must be a non-negative integer\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | if !defined($self->{current_offset}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | || ref($self->{current_offset}) ne '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 54 | ▶ | || $self->{current_offset} !~ /\A[0-9]+\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not defined $self->{"current_offset"} or ref $self->{"current_offset"} ne "" or not $self->{"current_offset"} =~ /\A[0-9]+\z/
not defined $self->{"current_offset"} or ref $self->{"current_offset"} ne ""
MC/DC66%2/3
not defined $self->{"current_offset"} or ref $self->{"current_offset"} ne "" or not $self->{"current_offset"} =~ /\A[0-9]+\z/
not defined $self->{"current_offset"}
ref $self->{"current_offset"} ne ""
not $self->{"current_offset"} =~ /\A[0-9]+\z/
Truth table75%3/4
not(A) or B or not(C)
A= not defined $self->{"current_offset"}B= ref $self->{"current_offset"} ne ""C= not $self->{"current_offset"} =~ /\A[0-9]+\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 52 | die "unknown pagination option: $_\n" for sort keys %args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 51 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 137 | ▶ | sub next { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 137 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 137 | ▶ | while (!@{ $self->{buffer} }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 125 | ▶ | return undef if $self->{finished}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 88 | $self->_fetch_page; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 79 | return shift @{ $self->{buffer} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 46 | ▶ | sub all { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 46 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 46 | my @items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 46 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 121 | my $item = $self->next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 110 | ▶ | last if !defined $item; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 75 | push @items, $item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 35 | ▶ | return wantarray ? @items : \@items; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 88 | ▶ | sub _fetch_page { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fetch_page: called CC=38 SCAR=36.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 88 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 88 | my $url = $self->_request_url; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 86 | my $first_page = !$self->{started}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 86 | my $response = $self->{client}->get($url, %{ $self->{request} }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 86 | my $data = $response->json; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 86 | my $items = _extract($data, $self->{items}, $response, $self->{response_aware_extractors}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 86 | ▶ | die "pagination items extractor must return an array reference\n" if ref($items) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # Stage iterator updates until the continuation is fully validated. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # A failed page must not leave items in the buffer or advance the cursor. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 84 | my %update = (buffer => [ @$items ], started => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 84 | my %seen = %{ $self->{seen} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # Continuations must not revisit the initial page or a supplied cursor. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # These values were previously absent from the seen-continuation set. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 84 | ▶ | if ($first_page) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 53 | ▶ | if ($self->{mode} eq 'next_url') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 25 | $seen{"url:$url"} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | ▶ | elsif ($self->{mode} eq 'cursor' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$self->{"mode"} eq "cursor" and defined $self->{"cursor"} and $self->{"cursor"} ne ""
$self->{"mode"} eq "cursor" and defined $self->{"cursor"}
MC/DC66%2/3
$self->{"mode"} eq "cursor" and defined $self->{"cursor"} and $self->{"cursor"} ne ""
$self->{"mode"} eq "cursor"
defined $self->{"cursor"}
$self->{"cursor"} ne ""
Truth table75%3/4
A and B and C
A= $self->{"mode"} eq "cursor"B= defined $self->{"cursor"}C= $self->{"cursor"} ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | && defined($self->{cursor}) && $self->{cursor} ne '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 6 | $seen{"cursor:$self->{cursor}"} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 84 | ▶ | if ($self->{mode} eq 'next_url') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 37 | my $next = _extract($data, $self->{next}, $response, $self->{response_aware_extractors}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 37 | ▶ | die "pagination next URL continuation must be a scalar\n" if defined($next) && ref($next) ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $next and ref $next ne ""
MC/DC100%2/2
defined $next and ref $next ne ""
defined $next
ref $next ne ""
Truth table100%3/3
A and B
A= defined $nextB= ref $next ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 34 | ▶ | if (!defined($next) || $next eq '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $next or $next eq ""
MC/DC50%1/2
not defined $next or $next eq ""
not defined $next
$next eq ""
Truth table66%2/3
not(A) or B
A= not defined $nextB= $next eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 15 | $update{finished} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 19 | $self->_guard_next_url_origin($next); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 17 | $self->_guard_continuation("url:$next", \%seen); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 11 | $update{path} = $next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | elsif ($self->{mode} eq 'cursor') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 15 | my $next = _extract($data, $self->{next}, $response, $self->{response_aware_extractors}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 15 | ▶ | die "pagination cursor continuation must be a scalar\n" if defined($next) && ref($next) ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $next and ref $next ne ""
MC/DC100%2/2
defined $next and ref $next ne ""
defined $next
ref $next ne ""
Truth table100%3/3
A and B
A= defined $nextB= ref $next ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 13 | ▶ | if (!defined($next) || $next eq '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $next or $next eq ""
MC/DC100%2/2
not defined $next or $next eq ""
not defined $next
$next eq ""
Truth table100%3/3
not(A) or B
A= not defined $nextB= $next eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 6 | $update{finished} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 7 | $self->_guard_continuation("cursor:$next", \%seen); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 5 | $update{cursor} = $next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | elsif ($self->{mode} eq 'offset') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # Advance by the actual number of items returned. Services may impose | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # a smaller page size than requested, so an explicit total is the most | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # reliable completion signal for offset-based APIs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 14 | my $next_offset = $self->{current_offset} + @$items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 14 | my $finished = !@$items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 14 | ▶ | if (defined $self->{total}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 10 | my $total = _extract($data, $self->{total}, $response, $self->{response_aware_extractors}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 10 | ▶ | die "pagination total extractor must return a non-negative integer\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not defined $total or ref $total ne "" or not $total =~ /\A[0-9]+\z/
not defined $total or ref $total ne ""
MC/DC33%1/3
not defined $total or ref $total ne "" or not $total =~ /\A[0-9]+\z/
not defined $total
ref $total ne ""
not $total =~ /\A[0-9]+\z/
Truth table50%2/4
not(A) or B or not(C)
A= not defined $totalB= ref $total ne ""C= not $total =~ /\A[0-9]+\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | if !defined($total) || ref($total) ne '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | || $total !~ /\A[0-9]+\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 9 | ▶ | $finished = 1 if $next_offset >= $total; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | elsif (defined $self->{has_more}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | $finished = 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 2 | ▶ | if !_extract($data, $self->{has_more}, $response, $self->{response_aware_extractors}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | elsif (defined $self->{page_size}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 2 | ▶ | $finished = 1 if @$items < $self->{page_size}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 13 | ▶ | if ($finished) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 7 | $update{finished} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 6 | $update{current_offset} = $next_offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 18 | my $has_more; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 18 | ▶ | if (defined $self->{has_more}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 7 | ▶ | $has_more = _extract($data, $self->{has_more}, $response, $self->{response_aware_extractors}) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | elsif (defined $self->{page_size}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 10 | ▶ | $has_more = @$items >= $self->{page_size} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | ▶ | $has_more = @$items ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 17 | ▶ | if ($has_more) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 8 | $update{current_page} = $self->{current_page} + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 9 | $update{finished} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 67 | ▶ | $update{finished} = 1 if !@$items && $self->{mode} eq 'page' && !defined($self->{has_more}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not @$items and $self->{"mode"} eq "page" and not defined $self->{"has_more"}
not @$items and $self->{"mode"} eq "page"
MC/DC66%2/3
not @$items and $self->{"mode"} eq "page" and not defined $self->{"has_more"}
not @$items
$self->{"mode"} eq "page"
not defined $self->{"has_more"}
Truth table75%3/4
not(A) and B and not(C)
A= not @$itemsB= $self->{"mode"} eq "page"C= not defined $self->{"has_more"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 67 | $update{seen} = \%seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 67 | $self->{$_} = $update{$_} for keys %update; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 88 | ▶ | sub _request_url { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_request_url: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 88 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 88 | ▶ | return $self->{path} if $self->{mode} eq 'next_url' && $self->{started}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"mode"} eq "next_url" and $self->{"started"}
MC/DC100%2/2
$self->{"mode"} eq "next_url" and $self->{"started"}
$self->{"mode"} eq "next_url"
$self->{"started"}
Truth table100%3/3
A and B
A= $self->{"mode"} eq "next_url"B= $self->{"started"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 76 | my %query = %{ $self->{query} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 76 | ▶ | if ($self->{mode} eq 'page') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 20 | $query{ $self->{page_param} } = $self->{current_page}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 20 | ▶ | $query{ $self->{page_size_param} } = $self->{page_size} if defined $self->{page_size}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | elsif ($self->{mode} eq 'offset') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 14 | $query{ $self->{offset_param} } = $self->{current_offset}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 14 | ▶ | $query{ $self->{page_size_param} } = $self->{page_size} if defined $self->{page_size}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | ▶ | elsif ($self->{mode} eq 'cursor' && defined($self->{cursor}) && $self->{cursor} ne '') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$self->{"mode"} eq "cursor" and defined $self->{"cursor"} and $self->{"cursor"} ne ""
$self->{"mode"} eq "cursor" and defined $self->{"cursor"}
MC/DC66%2/3
$self->{"mode"} eq "cursor" and defined $self->{"cursor"} and $self->{"cursor"} ne ""
$self->{"mode"} eq "cursor"
defined $self->{"cursor"}
$self->{"cursor"} ne ""
Truth table75%3/4
A and B and C
A= $self->{"mode"} eq "cursor"B= defined $self->{"cursor"}C= $self->{"cursor"} ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 11 | $query{ $self->{cursor_param} } = $self->{cursor}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 76 | return _append_query($self->{path}, \%query); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 19 | ▶ | sub _guard_next_url_origin { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_guard_next_url_origin: called CC=7 SCAR=19.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 19 | my ($self, $next) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 19 | ▶ | return if $self->{allow_cross_origin}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 18 | ▶ | return if $next !~ m{\Ahttps?://}i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 4 | my $base = $self->{client}->base_url; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 4 | ▶ | return if !defined($base) || $base !~ m{\A(https?)://([^/]+)}i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $base and $base =~ m[\A(https?)://([^/]+)]i
MC/DC0%0/2
defined $base and $base =~ m[\A(https?)://([^/]+)]i
defined $base
$base =~ m[\A(https?)://([^/]+)]i
Truth table33%1/3
A and B
A= defined $baseB= $base =~ m[\A(https?)://([^/]+)]i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 4 | my ($base_scheme, $base_authority) = (lc($1), lc($2)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 4 | $next =~ m{\A(https?)://([^/]+)}i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 4 | my ($next_scheme, $next_authority) = (lc($1), lc($2)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 4 | ▶ | die "cross-origin pagination continuation rejected: $next\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$base_scheme ne $next_scheme or $base_authority ne $next_authority
MC/DC50%1/2
$base_scheme ne $next_scheme or $base_authority ne $next_authority
$base_scheme ne $next_scheme
$base_authority ne $next_authority
Truth table66%2/3
A or B
A= $base_scheme ne $next_schemeB= $base_authority ne $next_authority
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | if $base_scheme ne $next_scheme || $base_authority ne $next_authority; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 24 | ▶ | sub _guard_continuation { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_guard_continuation: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 24 | my ($self, $key, $seen) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 24 | ▶ | $seen = $self->{seen} if !defined $seen; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 24 | ▶ | die "pagination continuation repeated: $key\n" if $seen->{$key}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 157 | ▶ | sub _extract { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract: called CC=10 SCAR=23.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 157 | my ($data, $extractor, $response, $response_aware) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 157 | ▶ | return $response_aware ? $extractor->($data, $response) : $extractor->($data) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | if ref($extractor) eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 138 | ▶ | return $data if !defined($extractor) || $extractor eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $extractor or $extractor eq ""
MC/DC0%0/2
not defined $extractor or $extractor eq ""
not defined $extractor
$extractor eq ""
Truth table33%1/3
not(A) or B
A= not defined $extractorB= $extractor eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 138 | my $value = $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 138 | for my $part (split /\./, $extractor) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 146 | ▶ | return undef if !defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 146 | ▶ | if (ref($value) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 144 | $value = $value->{$part}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | ▶ | elsif (ref($value) eq 'ARRAY' && $part =~ /\A[0-9]+\z/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $value eq "ARRAY" and $part =~ /\A[0-9]+\z/
MC/DC50%1/2
ref $value eq "ARRAY" and $part =~ /\A[0-9]+\z/
ref $value eq "ARRAY"
$part =~ /\A[0-9]+\z/
Truth table66%2/3
A and B
A= ref $value eq "ARRAY"B= $part =~ /\A[0-9]+\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | $value = $value->[$part]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 137 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 76 | ▶ | sub _append_query { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_append_query: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 76 | my ($url, $query) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 76 | my @pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 76 | for my $key (sort keys %$query) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 103 | ▶ | die "query parameter names must be scalars\n" if ref($key) ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 103 | my $value = $query->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 103 | ▶ | next if !defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 93 | my @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 93 | ▶ | if (ref($value) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | die "query parameter array values must contain only scalars or undef\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 2 | ▶ | if grep { defined($_) && ref($_) ne '' } @$value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $_ && ref $_ ne ''
MC/DC100%2/2
defined $_ && ref $_ ne ''
defined $_
ref $_ ne ''
Truth table100%3/3
A && B
A= defined $_B= ref $_ ne ''
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 1 | @values = grep { defined $_ } @$value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | elsif (ref($value) ne '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 1 | die "query values must be scalars, array references, or undef\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 90 | @values = ($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 91 | push @pairs, map { _escape($key) . '=' . _escape($_) } @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 74 | ▶ | return $url if !@pairs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 48 | my $fragment = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 48 | ▶ | if ($url =~ s/(#.*)\z//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 2 | $fragment = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 48 | ▶ | my $sep = index($url, '?') >= 0 ? '&' : '?'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 48 | return $url . $sep . join('&', @pairs) . $fragment; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 184 | ▶ | sub _escape { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_escape: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 184 | my ($value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 184 | ▶ | $value = '' if !defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 184 | my $bytes = "$value"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 184 | ▶ | utf8::encode($bytes) if utf8::is_utf8($bytes); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 184 | $bytes =~ s/([^A-Za-z0-9\-._~])/sprintf('%%%02X', ord($1))/ge; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 184 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 43 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||