| 1 | package Pithub::Result; | ||||||||||||||||||||||||||||
| 2 | 24 | our $AUTHORITY = 'cpan:PLU'; | |||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Github v3 result object | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 24 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 24 | our $VERSION = '0.01041'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 24 | ▶ | use Pithub::ResultSet (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 24 | ▶ | use JSON::MaybeXS qw( JSON ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 24 | ▶ | use URI (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 24 | ▶ | use Carp qw( confess croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | sub _isa_isa_maker { | ||||||||||||||||||||||||||||
| 16 | 48 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
_isa_isa_maker: called CC=1 SCAR=0.1
| |||||||||||||||||||||||||||||
| 17 | return sub { | ||||||||||||||||||||||||||||
| 18 | 580 | ▶ | confess "must be an instance of $class but isn't a reference" | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.7
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | if !ref $_[0]; | ||||||||||||||||||||||||||||
| 20 | confess "must be an instance of $class, but is a " . ref $_[0] | ||||||||||||||||||||||||||||
| 21 | 580 | ▶ | unless eval { $_[0]->isa($class) }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 48 | }; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | has 'auto_pagination' => ( | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | default => sub { 0 }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 28 | 24 | is => 'rw', | |||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 24 | has 'content' => ( | |||||||||||||||||||||||||||
| 33 | builder => '_build_content', | ||||||||||||||||||||||||||||
| 34 | clearer => 'clear_content', | ||||||||||||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||||||||||
| 36 | lazy => 1, | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 24 | has 'first_page_uri' => ( | |||||||||||||||||||||||||||
| 41 | builder => '_build_first_page_uri', | ||||||||||||||||||||||||||||
| 42 | clearer => 'clear_first_page_uri', | ||||||||||||||||||||||||||||
| 43 | is => 'ro', | ||||||||||||||||||||||||||||
| 44 | lazy => 1, | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 24 | has 'last_page_uri' => ( | |||||||||||||||||||||||||||
| 49 | builder => '_build_last_page_uri', | ||||||||||||||||||||||||||||
| 50 | clearer => 'clear_last_page_uri', | ||||||||||||||||||||||||||||
| 51 | is => 'ro', | ||||||||||||||||||||||||||||
| 52 | lazy => 1, | ||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 24 | has 'next_page_uri' => ( | |||||||||||||||||||||||||||
| 57 | builder => '_build_next_page_uri', | ||||||||||||||||||||||||||||
| 58 | clearer => 'clear_next_page_uri', | ||||||||||||||||||||||||||||
| 59 | is => 'ro', | ||||||||||||||||||||||||||||
| 60 | lazy => 1, | ||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 24 | has 'prev_page_uri' => ( | |||||||||||||||||||||||||||
| 65 | builder => '_build_prev_page_uri', | ||||||||||||||||||||||||||||
| 66 | clearer => 'clear_prev_page_uri', | ||||||||||||||||||||||||||||
| 67 | is => 'ro', | ||||||||||||||||||||||||||||
| 68 | lazy => 1, | ||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 24 | has 'response' => ( | |||||||||||||||||||||||||||
| 73 | handles => { | ||||||||||||||||||||||||||||
| 74 | code => 'code', | ||||||||||||||||||||||||||||
| 75 | raw_content => 'content', | ||||||||||||||||||||||||||||
| 76 | request => 'request', | ||||||||||||||||||||||||||||
| 77 | success => 'is_success', | ||||||||||||||||||||||||||||
| 78 | }, | ||||||||||||||||||||||||||||
| 79 | is => 'ro', | ||||||||||||||||||||||||||||
| 80 | isa => _isa_isa_maker('HTTP::Response'), | ||||||||||||||||||||||||||||
| 81 | required => 1, | ||||||||||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | # required for next_page etc | ||||||||||||||||||||||||||||
| 86 | has '_request' => ( | ||||||||||||||||||||||||||||
| 87 | is => 'ro', | ||||||||||||||||||||||||||||
| 88 | isa => sub { | ||||||||||||||||||||||||||||
| 89 | 568 | ▶ | croak 'must be a coderef, but is ' . ref $_[0] | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | unless ref $_[0] eq 'CODE'; | ||||||||||||||||||||||||||||
| 91 | }, | ||||||||||||||||||||||||||||
| 92 | 24 | required => 1, | |||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # required for next | ||||||||||||||||||||||||||||
| 96 | 24 | has '_iterator' => ( | |||||||||||||||||||||||||||
| 97 | builder => '_build__iterator', | ||||||||||||||||||||||||||||
| 98 | clearer => '_clear_iterator', | ||||||||||||||||||||||||||||
| 99 | is => 'ro', | ||||||||||||||||||||||||||||
| 100 | isa => _isa_isa_maker(Pithub::ResultSet::), | ||||||||||||||||||||||||||||
| 101 | lazy => 1, | ||||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 24 | has 'utf8' => ( | |||||||||||||||||||||||||||
| 106 | is => 'ro', | ||||||||||||||||||||||||||||
| 107 | default => 1, | ||||||||||||||||||||||||||||
| 108 | ); | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | has '_json' => ( | ||||||||||||||||||||||||||||
| 111 | builder => '_build__json', | ||||||||||||||||||||||||||||
| 112 | is => 'ro', | ||||||||||||||||||||||||||||
| 113 | isa => sub { | ||||||||||||||||||||||||||||
| 114 | confess "$_[0] is not a suitable JSON object" | ||||||||||||||||||||||||||||
| 115 | 13 | ▶ | unless eval { $_[0]->can('decode') }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | }, | ||||||||||||||||||||||||||||
| 117 | 24 | lazy => 1, | |||||||||||||||||||||||||||
| 118 | ); | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | sub count { | ||||||||||||||||||||||||||||
| 122 | 4 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
count: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | 4 | ▶ | return 0 unless $self->success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 3 | my $content = $self->content; | |||||||||||||||||||||||||||
| 125 | 3 | ▶ | if ( ref $content eq 'HASH' && scalar keys %$content == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $content eq "HASH" and scalar keys %$content == 0
MC/DC100%2/2
ref $content eq "HASH" and scalar keys %$content == 0
ref $content eq "HASH"
scalar keys %$content == 0
Truth table100%3/3
A and B
A= ref $content eq "HASH"B= scalar keys %$content == 0
| |||||||||||||||||||||||||||||
| 126 | 1 | return 0; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | 2 | return $self->_iterator->getLength; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | sub first { | ||||||||||||||||||||||||||||
| 133 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
first: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 134 | 2 | my $content = $self->content; | |||||||||||||||||||||||||||
| 135 | 2 | ▶ | if ( ref $content eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 1 | return $content->[0]; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | 1 | return $content; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | sub first_page { | ||||||||||||||||||||||||||||
| 143 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
first_page: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 144 | 5 | ▶ | return unless $self->first_page_uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 2 | return $self->_paginate( $self->first_page_uri ); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | sub get_page { | ||||||||||||||||||||||||||||
| 150 | 6 | ▶ | my ( $self, $page ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_page: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | # First we need to get an URI we can work with and replace | ||||||||||||||||||||||||||||
| 153 | # the page GET parameter properly with the given value. If | ||||||||||||||||||||||||||||
| 154 | # we cannot get the first or last page URI, then there is | ||||||||||||||||||||||||||||
| 155 | # only one page. | ||||||||||||||||||||||||||||
| 156 | 6 | ▶ | my $uri_str = $self->first_page_uri || $self->last_page_uri; | ||||||||||||||||||||||||||
|
Condition100%3/3
$self->first_page_uri || $self->last_page_uri
MC/DC100%2/2
$self->first_page_uri || $self->last_page_uri
$self->first_page_uri
$self->last_page_uri
Truth table100%3/3
A || B
A= $self->first_page_uriB= $self->last_page_uri
| |||||||||||||||||||||||||||||
| 157 | 6 | ▶ | return unless $uri_str; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 5 | my $uri = URI->new($uri_str); | |||||||||||||||||||||||||||
| 160 | 5 | my %query = $uri->query_form; | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 5 | $query{page} = $page; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | my $options = { | ||||||||||||||||||||||||||||
| 165 | prepare_request => sub { | ||||||||||||||||||||||||||||
| 166 | 5 | ▶ | my ($request) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 167 | 5 | %query = ( $request->uri->query_form, %query ); | |||||||||||||||||||||||||||
| 168 | 5 | $request->uri->query_form(%query); | |||||||||||||||||||||||||||
| 169 | }, | ||||||||||||||||||||||||||||
| 170 | 5 | }; | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 5 | return $self->_request->( | |||||||||||||||||||||||||||
| 173 | method => 'GET', | ||||||||||||||||||||||||||||
| 174 | path => $uri->path, | ||||||||||||||||||||||||||||
| 175 | options => $options, | ||||||||||||||||||||||||||||
| 176 | ); | ||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | sub last_page { | ||||||||||||||||||||||||||||
| 181 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
last_page: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 182 | 5 | ▶ | return unless $self->last_page_uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 3 | return $self->_paginate( $self->last_page_uri ); | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | ## no critic (Subroutines::ProhibitBuiltinHomonyms) | ||||||||||||||||||||||||||||
| 188 | sub next { | ||||||||||||||||||||||||||||
| 189 | 118 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
next: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 190 | 118 | my $row = $self->_iterator->getNext; | |||||||||||||||||||||||||||
| 191 | 118 | ▶ | return $row if $row; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | 10 | ▶ | if ( $self->auto_pagination ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 8 | my $result = $self->next_page; | |||||||||||||||||||||||||||
| 194 | 8 | ▶ | return unless $result; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | 6 | $self->_reset; | |||||||||||||||||||||||||||
| 196 | 6 | $self->{response} = $result->response; | |||||||||||||||||||||||||||
| 197 | 6 | return $self->_iterator->getNext; | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | 2 | return; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | ## use critic | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | sub next_page { | ||||||||||||||||||||||||||||
| 205 | 13 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
next_page: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 206 | 13 | ▶ | return unless $self->next_page_uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 9 | return $self->_paginate( $self->next_page_uri ); | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | sub prev_page { | ||||||||||||||||||||||||||||
| 212 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
prev_page: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 213 | 5 | ▶ | return unless $self->prev_page_uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | 2 | return $self->_paginate( $self->prev_page_uri ); | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | sub etag { | ||||||||||||||||||||||||||||
| 219 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
etag: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 220 | 0 | return $self->response->header('ETag'); | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | sub ratelimit { | ||||||||||||||||||||||||||||
| 225 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
ratelimit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 226 | 1 | return $self->response->header('X-RateLimit-Limit'); | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | sub ratelimit_remaining { | ||||||||||||||||||||||||||||
| 231 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
ratelimit_remaining: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 232 | 1 | return $self->response->header('X-RateLimit-Remaining'); | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | sub _build_content { | ||||||||||||||||||||||||||||
| 236 | 20 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_build_content: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 237 | 20 | ▶ | if ( $self->raw_content ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 19 | return $self->_json->decode( $self->raw_content ); | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | 1 | return {}; | |||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | sub _build_first_page_uri { | ||||||||||||||||||||||||||||
| 244 | 7 | ▶ | return shift->_get_link_header('first'); | ||||||||||||||||||||||||||
|
Subroutine
_build_first_page_uri: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | sub _build__iterator { | ||||||||||||||||||||||||||||
| 248 | 12 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_build__iterator: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 249 | 12 | my $content = $self->content; | |||||||||||||||||||||||||||
| 250 | 12 | ▶ | $content = [$content] unless ref $content eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | 12 | return Pithub::ResultSet->new($content); | |||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | sub _build_last_page_uri { | ||||||||||||||||||||||||||||
| 255 | 7 | ▶ | return shift->_get_link_header('last'); | ||||||||||||||||||||||||||
|
Subroutine
_build_last_page_uri: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | sub _build_next_page_uri { | ||||||||||||||||||||||||||||
| 259 | 13 | ▶ | return shift->_get_link_header('next'); | ||||||||||||||||||||||||||
|
Subroutine
_build_next_page_uri: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | sub _build_prev_page_uri { | ||||||||||||||||||||||||||||
| 263 | 6 | ▶ | return shift->_get_link_header('prev'); | ||||||||||||||||||||||||||
|
Subroutine
_build_prev_page_uri: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | sub _build__json { | ||||||||||||||||||||||||||||
| 267 | 13 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_build__json: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 268 | 13 | return JSON->new->utf8( $self->utf8 ); | |||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | sub _get_link_header { | ||||||||||||||||||||||||||||
| 272 | 33 | ▶ | my ( $self, $type ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_get_link_header: called CC=7 SCAR=19.9
| |||||||||||||||||||||||||||||
| 273 | return $self->{_get_link_header}{$type} | ||||||||||||||||||||||||||||
| 274 | 33 | ▶ | if $self->{_get_link_header}{$type}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | 24 | my $link = $self->response->header('Link'); | |||||||||||||||||||||||||||
| 276 | 24 | ▶ | return unless $link; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | 19 | ▶ | return unless $link =~ /(next|first|last|prev)/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 278 | 19 | foreach my $item ( split /,/, $link ) { | |||||||||||||||||||||||||||
| 279 | 48 | my @result = $item =~ /<([^>]+)>; rel="([^"]+)"/g; | |||||||||||||||||||||||||||
| 280 | 48 | ▶ | next if !$result[1] || !$result[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$result[1] and $result[0]
MC/DC0%0/2
$result[1] and $result[0]
$result[1]
$result[0]
Truth table33%1/3
A and B
A= $result[1]B= $result[0]
| |||||||||||||||||||||||||||||
| 281 | 48 | $self->{_get_link_header}{ $result[1] } = $result[0]; | |||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | 19 | return $self->{_get_link_header}{$type}; | |||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | sub _paginate { | ||||||||||||||||||||||||||||
| 287 | 16 | ▶ | my ( $self, $uri_str ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_paginate: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 288 | 16 | my $uri = URI->new($uri_str); | |||||||||||||||||||||||||||
| 289 | my $options = { | ||||||||||||||||||||||||||||
| 290 | prepare_request => sub { | ||||||||||||||||||||||||||||
| 291 | 16 | ▶ | my ($request) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 292 | 16 | my %query = ( $request->uri->query_form, $uri->query_form ); | |||||||||||||||||||||||||||
| 293 | 16 | $request->uri->query_form(%query); | |||||||||||||||||||||||||||
| 294 | }, | ||||||||||||||||||||||||||||
| 295 | 16 | }; | |||||||||||||||||||||||||||
| 296 | 16 | return $self->_request->( | |||||||||||||||||||||||||||
| 297 | method => 'GET', | ||||||||||||||||||||||||||||
| 298 | path => $uri->path, | ||||||||||||||||||||||||||||
| 299 | options => $options, | ||||||||||||||||||||||||||||
| 300 | ); | ||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | sub _reset { | ||||||||||||||||||||||||||||
| 304 | 6 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_reset: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 305 | 6 | $self->clear_content; | |||||||||||||||||||||||||||
| 306 | 6 | $self->clear_first_page_uri; | |||||||||||||||||||||||||||
| 307 | 6 | $self->clear_last_page_uri; | |||||||||||||||||||||||||||
| 308 | 6 | $self->clear_next_page_uri; | |||||||||||||||||||||||||||
| 309 | 6 | $self->clear_prev_page_uri; | |||||||||||||||||||||||||||
| 310 | 6 | $self->_clear_iterator; | |||||||||||||||||||||||||||
| 311 | 6 | delete $self->{_get_link_header}; | |||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 24 | 1; | |||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | __END__ | ||||||||||||||||||||||||||||