| 1 | 4 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use feature 'class'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | no warnings 'experimental::class'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | class Azure::SDK::Storage::Queues::Uri { | |||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use URI (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | field $endpoint :param :reader = undef; | |||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | field $endpoint_path :reader = undef; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 25 | ▶ | ADJUST { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 25 | ▶ | croak 'Azure::SDK::Storage::Queues::Uri requires an endpoint' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $endpoint and length $endpoint
MC/DC0%0/2
defined $endpoint and length $endpoint
defined $endpoint
length $endpoint
Truth table33%1/3
A and B
A= defined $endpointB= length $endpoint
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | unless defined $endpoint && length $endpoint; | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 25 | ( $endpoint, $endpoint_path ) = _normalize_endpoint($endpoint); | |||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 17 | ▶ | sub from_connection_string ( $class, $connection ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_connection_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 17 | return $class->new( endpoint => $connection->queue_endpoint ); | |||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 25 | ▶ | sub normalize_endpoint ( $class, $value ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_endpoint: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 25 | return _normalize_endpoint($value); | |||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | ▶ | method for_service ( $query = {} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
for_service: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 6 | return $self->_build( [], $query ); | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 24 | ▶ | method for_queue ( $queue, $query = {} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
for_queue: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 24 | return $self->_build( [ _validate_queue_name($queue) ], $query ); | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 10 | ▶ | method for_messages ( $queue, $query = {} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
for_messages: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 10 | return $self->_build( [ _validate_queue_name($queue), 'messages' ], $query ); | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 4 | ▶ | method for_message ( $queue, $message_id, $query = {} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
for_message: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 4 | return $self->_build( | |||||||||||||||||||||||||||||||||||||||||
| 41 | [ _validate_queue_name($queue), 'messages', _validate_message_id($message_id) ], | ||||||||||||||||||||||||||||||||||||||||||
| 42 | $query, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 38 | ▶ | method _build ( $segments, $query ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 38 | my %normalized = _validate_query($query); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 37 | my $suffix = @{$segments} | |||||||||||||||||||||||||||||||||||||||||
| 49 | 37 | ▶ | ? '/' . join( '/', map { _encode_segment($_) } @{$segments} ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | : ''; | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 37 | my %canonical_query; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 37 | for my $name (keys %normalized) { | |||||||||||||||||||||||||||||||||||||||||
| 54 | 42 | my $value = $normalized{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 42 | utf8::encode($value); | |||||||||||||||||||||||||||||||||||||||||
| 56 | 42 | $canonical_query{$name} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 37 | my $url = $endpoint . $suffix; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 37 | ▶ | if (%normalized) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | $url .= '?' . join '&', | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 23 | map { _encode_segment($_) . '=' . _encode_segment($normalized{$_}) } | |||||||||||||||||||||||||||||||||||||||||
| 63 | sort keys %normalized; | ||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 37 | url => $url, | |||||||||||||||||||||||||||||||||||||||||
| 68 | canonical_path => $endpoint_path . $suffix, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | canonical_query => \%canonical_query, | ||||||||||||||||||||||||||||||||||||||||||
| 70 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 130 | ▶ | sub _encode_segment ($value) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_segment: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 130 | my $bytes = $value; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 130 | utf8::encode($bytes); | |||||||||||||||||||||||||||||||||||||||||
| 76 | 130 | $bytes =~ s/([^A-Za-z0-9\-\._~])/sprintf( '%%%02X', ord $1 )/ge; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 130 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 50 | ▶ | sub _normalize_endpoint ($value) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize_endpoint: called CC=12 SCAR=27.0
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 50 | ▶ | croak 'Queue endpoint is required' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $value and length $value
MC/DC0%0/2
defined $value and length $value
defined $value
length $value
Truth table33%1/3
A and B
A= defined $valueB= length $value
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | unless defined $value && length $value; | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 50 | my $uri = URI->new($value); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 50 | ▶ | croak 'Queue endpoint must be an absolute http or https URI' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u
MC/DC0%0/2
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u
defined $uri->scheme
$uri->scheme =~ /\Ahttps?\z/u
Truth table33%1/3
A and B
A= defined $uri->schemeB= $uri->scheme =~ /\Ahttps?\z/u
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | unless defined $uri->scheme && $uri->scheme =~ /\Ahttps?\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 50 | ▶ | croak 'Queue endpoint must include a host' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $uri->host and length $uri->host
MC/DC0%0/2
defined $uri->host and length $uri->host
defined $uri->host
length $uri->host
Truth table33%1/3
A and B
A= defined $uri->hostB= length $uri->host
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | unless defined $uri->host && length $uri->host; | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 50 | ▶ | croak 'Queue endpoint must not include userinfo' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | if defined $uri->userinfo; | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 48 | ▶ | croak 'Queue endpoint must not include a query string' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | if defined $uri->query; | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 47 | ▶ | croak 'Queue endpoint must not include a fragment' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | if defined $uri->fragment; | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 46 | ▶ | my $path = $uri->path // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$uri->path // ""
MC/DC0%0/1
$uri->path // ""
$uri->path
Truth table50%1/2
A
A= $uri->path
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 46 | $path =~ s{/+\z}{}; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 46 | ▶ | croak 'Queue endpoint path must not contain relative segments' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | if $path =~ m{(?:\A|/)\.\.?(?:/|\z)}; | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 45 | my $authority = $uri->scheme . '://' . $uri->authority; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 45 | return ( $authority . $path, $path ); | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 38 | ▶ | sub _validate_queue_name ($name) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_queue_name: called CC=7 SCAR=21.5
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 38 | ▶ | croak 'Queue name is required' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $name and not ref $name and length $name
defined $name and not ref $name
MC/DC0%0/3
defined $name and not ref $name and length $name
defined $name
not ref $name
length $name
Truth table25%1/4
A and not(B) and C
A= defined $nameB= not ref $nameC= length $name
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | unless defined $name && !ref $name && length $name; | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 38 | ▶ | croak 'Queue name must be 3-63 characters of lowercase letters, ' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$name =~ /\A[a-z0-9]+(?:-[a-z0-9]+)*\z/u and length $name >= 3 and length $name <= 63
$name =~ /\A[a-z0-9]+(?:-[a-z0-9]+)*\z/u and length $name >= 3
MC/DC66%2/3
$name =~ /\A[a-z0-9]+(?:-[a-z0-9]+)*\z/u and length $name >= 3 and length $name <= 63
$name =~ /\A[a-z0-9]+(?:-[a-z0-9]+)*\z/u
length $name >= 3
length $name <= 63
Truth table75%3/4
A and B and C
A= $name =~ /\A[a-z0-9]+(?:-[a-z0-9]+)*\z/uB= length $name >= 3C= length $name <= 63
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | . 'digits, and single hyphens, starting and ending alphanumerically' | ||||||||||||||||||||||||||||||||||||||||||
| 110 | unless $name =~ /\A[a-z0-9]+(?:-[a-z0-9]+)*\z/ | ||||||||||||||||||||||||||||||||||||||||||
| 111 | && length($name) >= 3 | ||||||||||||||||||||||||||||||||||||||||||
| 112 | && length($name) <= 63; | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 33 | return $name; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 4 | ▶ | sub _validate_message_id ($message_id) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_message_id: called CC=5 SCAR=18.6
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 4 | ▶ | croak 'Message id is required' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $message_id and not ref $message_id and length $message_id
defined $message_id and not ref $message_id
MC/DC0%0/3
defined $message_id and not ref $message_id and length $message_id
defined $message_id
not ref $message_id
length $message_id
Truth table25%1/4
A and not(B) and C
A= defined $message_idB= not ref $message_idC= length $message_id
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | unless defined $message_id && !ref $message_id && length $message_id; | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 4 | ▶ | croak 'Message id must not contain control characters' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | if $message_id =~ /[\x00-\x1f\x7f]/; | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 3 | return $message_id; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 38 | ▶ | sub _validate_query ($query) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_query: called CC=10 SCAR=24.1
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 38 | ▶ | return () unless defined $query; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 38 | ▶ | croak 'Query parameters must be a hash reference' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | unless ref $query eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 38 | my %normalized; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 38 | for my $name (keys %{$query}) { | |||||||||||||||||||||||||||||||||||||||||
| 131 | 43 | ▶ | croak 'Query parameter names must be alphanumeric, "-", "_", or "."' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $name and $name =~ /\A[A-Za-z0-9_.\-]+\z/u
MC/DC50%1/2
defined $name and $name =~ /\A[A-Za-z0-9_.\-]+\z/u
defined $name
$name =~ /\A[A-Za-z0-9_.\-]+\z/u
Truth table66%2/3
A and B
A= defined $nameB= $name =~ /\A[A-Za-z0-9_.\-]+\z/u
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | unless defined $name && $name =~ /\A[A-Za-z0-9_.\-]+\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 42 | my $key = lc $name; | |||||||||||||||||||||||||||||||||||||||||
| 135 | croak "Query parameter '$name' is repeated" | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 42 | ▶ | if exists $normalized{$key}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 42 | my $value = $query->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 42 | ▶ | next unless defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 42 | ▶ | croak "Query parameter '$name' must be a scalar" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | if ref $value; | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 42 | ▶ | croak "Query parameter '$name' must not contain control characters" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | if $value =~ /[\x00-\x1f\x7f]/; | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 42 | $normalized{$key} = "$value"; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 37 | return %normalized; | |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | __END__ | ||||||||||||||||||||||||||||||||||||||||||