| 1 | package Twilio::TokenPaginationPage; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use 5.016; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use parent 'Twilio::Page'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Twilio::Exceptions::TwilioException; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 5 | our $VERSION = '2.001'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 65 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 65 | my ($class, @arguments) = @_; | |||||||||||||||||||||||||||
| 14 | 65 | my $self = $class->SUPER::new(@arguments); | |||||||||||||||||||||||||||
| 15 | 63 | $self->_read_last_request; | |||||||||||||||||||||||||||
| 16 | 63 | ▶ | $self->{page_size} = int($self->get_meta('pageSize') // 0); | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->get_meta("pageSize") // 0
MC/DC100%1/1
$self->get_meta("pageSize") // 0
$self->get_meta("pageSize")
Truth table100%2/2
A
A= $self->get_meta("pageSize")
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 63 | my $current = $self->_current_token; | |||||||||||||||||||||||||||
| 19 | 63 | $self->{next_token} = _usable_token($self->get_meta('nextToken'), $current); | |||||||||||||||||||||||||||
| 20 | 63 | $self->{previous_token} = _usable_token($self->get_meta('previousToken'), $current); | |||||||||||||||||||||||||||
| 21 | 63 | return $self; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 26 | ▶ | sub get_next_page_url { | ||||||||||||||||||||||||||
|
Subroutine
get_next_page_url: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 26 | my ($self) = @_; | |||||||||||||||||||||||||||
| 26 | 26 | return $self->_url_with_token($self->{next_token}); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 6 | ▶ | sub get_previous_page_url { | ||||||||||||||||||||||||||
|
Subroutine
get_previous_page_url: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||
| 31 | 6 | return $self->_url_with_token($self->{previous_token}); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # These APIs can list plain values, and instances are always built from a hash. | ||||||||||||||||||||||||||||
| 35 | 56 | ▶ | sub instance_for { | ||||||||||||||||||||||||||
|
Subroutine
instance_for: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 56 | my ($self, $item) = @_; | |||||||||||||||||||||||||||
| 37 | 56 | ▶ | return $self->build_instance(ref $item eq 'HASH' ? $item : { id => $item }); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # A token only says where to go, so the next URL is this page's URL with the token replaced. | ||||||||||||||||||||||||||||
| 41 | 63 | ▶ | sub _read_last_request { | ||||||||||||||||||||||||||
|
Subroutine
_read_last_request: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||
| 42 | 63 | my ($self) = @_; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 63 | ▶ | my $request = $self->_http_client->last_request // {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->_http_client->last_request // {}
MC/DC0%0/1
$self->_http_client->last_request // {}
$self->_http_client->last_request
Truth table50%1/2
A
A= $self->_http_client->last_request
| |||||||||||||||||||||||||||||
| 45 | 63 | ▶ | my ($url, $query) = split /[?]/, $request->{url} // q{}, 2; | ||||||||||||||||||||||||||
|
Condition50%1/2
$request->{"url"} // ""
MC/DC0%0/1
$request->{"url"} // ""
$request->{"url"}
Truth table50%1/2
A
A= $request->{"url"}
| |||||||||||||||||||||||||||||
| 46 | 63 | $self->{url} = $url; | |||||||||||||||||||||||||||
| 47 | 63 | ▶ | $self->{query_pairs} = [split /&/, $query // q{}]; | ||||||||||||||||||||||||||
|
Condition100%2/2
$query // ""
MC/DC100%1/1
$query // ""
$query
Truth table100%2/2
A
A= $query
| |||||||||||||||||||||||||||||
| 48 | 63 | return; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 78 | ▶ | sub _http_client { | ||||||||||||||||||||||||||
|
Subroutine
_http_client: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | 78 | my ($self) = @_; | |||||||||||||||||||||||||||
| 53 | 78 | return $self->get_version->get_domain->get_client->get_http_client; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 63 | ▶ | sub _current_token { | ||||||||||||||||||||||||||
|
Subroutine
_current_token: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 57 | 63 | my ($self) = @_; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 63 | my ($pair) = grep { /\ApageToken=/ } @{ $self->{query_pairs} }; | |||||||||||||||||||||||||||
| 60 | 63 | ▶ | return if !defined $pair; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 12 | my $token = $pair =~ s/\ApageToken=//r; | |||||||||||||||||||||||||||
| 63 | 12 | $token =~ tr/+/ /; | |||||||||||||||||||||||||||
| 64 | 12 | $token =~ s/%([0-9A-Fa-f]{2})/chr hex $1/ge; | |||||||||||||||||||||||||||
| 65 | 12 | return $token; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # A server that answers with the token just used would otherwise keep a stream reading forever. | ||||||||||||||||||||||||||||
| 69 | 126 | ▶ | sub _usable_token { | ||||||||||||||||||||||||||
|
Subroutine
_usable_token: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 70 | 126 | my ($token, $current) = @_; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 126 | ▶ | return if !defined $token || !length $token; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $token and length $token
MC/DC100%2/2
defined $token and length $token
defined $token
length $token
Truth table100%3/3
A and B
A= defined $tokenB= length $token
| |||||||||||||||||||||||||||||
| 73 | 25 | ▶ | return if defined $current && $token eq $current; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $current and $token eq $current
MC/DC100%2/2
defined $current and $token eq $current
defined $current
$token eq $current
Truth table100%3/3
A and B
A= defined $currentB= $token eq $current
| |||||||||||||||||||||||||||||
| 74 | 21 | return $token; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 32 | ▶ | sub _url_with_token { | ||||||||||||||||||||||||||
|
Subroutine
_url_with_token: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 78 | 32 | my ($self, $token) = @_; | |||||||||||||||||||||||||||
| 79 | 32 | ▶ | return if !defined $token; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # Without a URL the token cannot be used, and returning nothing would end the list early. | ||||||||||||||||||||||||||||
| 82 | 16 | ▶ | if (!length($self->{url} // q{})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->{"url"} // ""
MC/DC0%0/1
$self->{"url"} // ""
$self->{"url"}
Truth table50%1/2
A
A= $self->{"url"}
| |||||||||||||||||||||||||||||
| 83 | 1 | Twilio::Exceptions::TwilioException->throw('The HTTP client did not record the last request'); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 15 | my %params = (pageToken => $token); | |||||||||||||||||||||||||||
| 87 | 15 | ▶ | $params{pageSize} = $self->{page_size} if $self->{page_size}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 15 | my @kept = grep { my ($name) = /\A([^=]*)/; !exists $params{$name} } @{ $self->{query_pairs} }; | |||||||||||||||||||||||||||
| 90 | 15 | return "$self->{url}?" . join q{&}, @kept, $self->_http_client->build_query(\%params); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 5 | 1; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | __END__ | ||||||||||||||||||||||||||||