| 1 | 2 | ▶ | use v5.36; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use feature 'class'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | no warnings 'experimental::class'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Azure::SDK::Core::Policy; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | class Azure::SDK::AppConfiguration::SyncToken :isa(Azure::SDK::Core::Policy) { | |||||||||||||||||||||||||||
| 8 | 2 | field %tokens; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 26 | ▶ | method send ($context, $request, $next) { | ||||||||||||||||||||||||||
|
Subroutine
send: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 26 | my $header = join ',', map { $tokens{$_}{raw} } sort keys %tokens; | |||||||||||||||||||||||||||
| 12 | 26 | ▶ | $request->set_header('Sync-Token', $header) if length $header; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 26 | my $response = $next->($context, $request); | |||||||||||||||||||||||||||
| 15 | 26 | $self->_add_tokens($response->header('sync-token')); | |||||||||||||||||||||||||||
| 16 | 26 | return $response; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 26 | ▶ | method _add_tokens ($header) { | ||||||||||||||||||||||||||
|
Subroutine
_add_tokens: called CC=9 SCAR=22.2
| |||||||||||||||||||||||||||||
| 20 | 26 | ▶ | return unless defined $header && !ref $header; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $header and not ref $header
MC/DC50%1/2
defined $header and not ref $header
defined $header
not ref $header
Truth table66%2/3
A and not(B)
A= defined $headerB= not ref $header
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 3 | for my $raw (split /,/, $header) { | |||||||||||||||||||||||||||
| 23 | 6 | $raw =~ s/\A\s+|\s+\z//g; | |||||||||||||||||||||||||||
| 24 | 6 | my $sequence_at = index($raw, ';sn='); | |||||||||||||||||||||||||||
| 25 | 6 | ▶ | next if $sequence_at < 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 5 | my $id_and_value = substr($raw, 0, $sequence_at); | |||||||||||||||||||||||||||
| 28 | 5 | my $sequence = substr($raw, $sequence_at + 4); | |||||||||||||||||||||||||||
| 29 | 5 | my $equals_at = index($id_and_value, '='); | |||||||||||||||||||||||||||
| 30 | 5 | ▶ | next if $equals_at < 1 || $sequence !~ /\A\d+\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$equals_at < 1 or not $sequence =~ /\A\d+\z/u
MC/DC0%0/2
$equals_at < 1 or not $sequence =~ /\A\d+\z/u
$equals_at < 1
not $sequence =~ /\A\d+\z/u
Truth table33%1/3
A or not(B)
A= $equals_at < 1B= not $sequence =~ /\A\d+\z/u
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 5 | my $id = substr($id_and_value, 0, $equals_at); | |||||||||||||||||||||||||||
| 33 | 5 | $sequence =~ s/\A0+(?=\d)//; | |||||||||||||||||||||||||||
| 34 | next if exists $tokens{$id} | ||||||||||||||||||||||||||||
| 35 | 5 | ▶ | && !_sequence_is_newer($sequence, $tokens{$id}{sequence}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $tokens{$id} and not _sequence_is_newer($sequence, $tokens{$id}{"sequence"})
MC/DC100%2/2
exists $tokens{$id} and not _sequence_is_newer($sequence, $tokens{$id}{"sequence"})
exists $tokens{$id}
not _sequence_is_newer($sequence, $tokens{$id}{"sequence"})
Truth table100%3/3
A and not(B)
A= exists $tokens{$id}B= not _sequence_is_newer($sequence, $tokens{$id}{"sequence"})
| |||||||||||||||||||||||||||||
| 36 | 4 | $tokens{$id} = { | |||||||||||||||||||||||||||
| 37 | raw => $raw, | ||||||||||||||||||||||||||||
| 38 | sequence => $sequence, | ||||||||||||||||||||||||||||
| 39 | }; | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | ▶ | sub _sequence_is_newer ($candidate, $existing) { | ||||||||||||||||||||||||||
|
Subroutine
_sequence_is_newer: called CC=3 SCAR=11.7
| |||||||||||||||||||||||||||||
| 44 | 2 | ▶ | return 1 if length($candidate) > length($existing); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 2 | ▶ | return 0 if length($candidate) < length($existing); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 2 | return $candidate gt $existing; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | 1; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | __END__ | ||||||||||||||||||||||||||||