« OpenTelemetry/Propagator/TraceContext/TraceFlags.pm
↑ Summary
OpenTelemetry/Instrumentation/LWP/UserAgent.pm »
| 1 | 16 | ▶ | use Object::Pad; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Represents the TraceState in a W3C TraceContext | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | package OpenTelemetry::Propagator::TraceContext::TraceState; | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 16 | our $VERSION = '0.040'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | class OpenTelemetry::Propagator::TraceContext::TraceState { | ||||||||||||||||||||||||||||
| 9 | 16 | ▶ | use List::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 16 | ▶ | use OpenTelemetry::Common (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 16 | my $logger = OpenTelemetry::Common::internal_logger; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 16 | my $MAX_MEMBERS = 32 * 2; # The member list is a flat list of pairs | |||||||||||||||||||||||||||
| 15 | 16 | my $VALID_KEY = qr/ | |||||||||||||||||||||||||||
| 16 | ^ | ||||||||||||||||||||||||||||
| 17 | (?: | ||||||||||||||||||||||||||||
| 18 | [ a-z ] [ a-z 0-9 _ * \/ - ]{0,255} # simple-key | ||||||||||||||||||||||||||||
| 19 | | (?: # multi-tenant-key | ||||||||||||||||||||||||||||
| 20 | [ a-z 0-9 ] [ a-z 0-9 _ * \/ - ]{0,240} # tenant-id | ||||||||||||||||||||||||||||
| 21 | @ | ||||||||||||||||||||||||||||
| 22 | [ a-z ] [ a-z 0-9 _ * \/ - ]{0,13} # system-id | ||||||||||||||||||||||||||||
| 23 | ) | ||||||||||||||||||||||||||||
| 24 | ) | ||||||||||||||||||||||||||||
| 25 | $ | ||||||||||||||||||||||||||||
| 26 | /xx; | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 16 | my $VALID_VALUE = qr/ | |||||||||||||||||||||||||||
| 29 | ^ | ||||||||||||||||||||||||||||
| 30 | [ \x{20} \x{21}-\x{2B} \x{2D}-\x{3C} \x{3E}-\x{7E} ]{0,255} | ||||||||||||||||||||||||||||
| 31 | [ \x{21}-\x{2B} \x{2D}-\x{3C} \x{3E}-\x{7E} ] | ||||||||||||||||||||||||||||
| 32 | $ | ||||||||||||||||||||||||||||
| 33 | /xx; | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 16 | field @members; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # Private methods | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | method $init ( @new ) { | ||||||||||||||||||||||||||||
| 40 | @members = splice @new, 0, $MAX_MEMBERS; | ||||||||||||||||||||||||||||
| 41 | $self | ||||||||||||||||||||||||||||
| 42 | 16 | } | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # Internal setting method: assumes parameters are validated | ||||||||||||||||||||||||||||
| 45 | # Having this in a separate method means we can call it from an | ||||||||||||||||||||||||||||
| 46 | # instance other than $self (eg. the one returned by the call to | ||||||||||||||||||||||||||||
| 47 | # 'delete' in the public 'set' method) | ||||||||||||||||||||||||||||
| 48 | method $set ( $key, $value ) { | ||||||||||||||||||||||||||||
| 49 | unshift @members, $key => $value; | ||||||||||||||||||||||||||||
| 50 | @members = splice @members, 0, $MAX_MEMBERS if @members > $MAX_MEMBERS; | ||||||||||||||||||||||||||||
| 51 | $self; | ||||||||||||||||||||||||||||
| 52 | 16 | } | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # Public interface | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 13 | ▶ | sub from_string ( $class, $string = undef ) { | ||||||||||||||||||||||||||
|
Subroutine
from_string: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 13 | ▶ | $logger->debug('Got an undefined value instead of a string when parsing TraceState') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | unless defined $string; | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 13 | my @members; | |||||||||||||||||||||||||||
| 61 | 13 | ▶ | for ( grep $_, split ',', $string // '' ) { | ||||||||||||||||||||||||||
|
Condition100%2/2
$string // ""
MC/DC100%1/1
$string // ""
$string
Truth table100%2/2
A
A= $string
| |||||||||||||||||||||||||||||
| 62 | 20 | my ( $key, $value ) = split '=', s/^\s+|\s+$//gr, 2; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 20 | ▶ | next unless $key =~ $VALID_KEY && $value =~ $VALID_VALUE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key =~ /$VALID_KEY/ and $value =~ /$VALID_VALUE/
MC/DC100%2/2
$key =~ /$VALID_KEY/ and $value =~ /$VALID_VALUE/
$key =~ /$VALID_KEY/
$value =~ /$VALID_VALUE/
Truth table100%3/3
A and B
A= $key =~ /$VALID_KEY/B= $value =~ /$VALID_VALUE/
| |||||||||||||||||||||||||||||
| 65 | 18 | push @members, $key => $value; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 13 | $class->new->$init(@members); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 20 | ▶ | method to_string () { | ||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 31 | ▶ | join ',', List::Util::pairmap { join '=', $a, $b } @members | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 73 | 20 | } | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # Gets the value | ||||||||||||||||||||||||||||
| 76 | 5 | ▶ | method get ( $key ) { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 5 | ▶ | my ( undef, $value ) = List::Util::pairfirst { $a eq $key } @members; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 78 | 5 | $value; | |||||||||||||||||||||||||||
| 79 | 16 | } | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # Sets a new pair, overwriting any existing one with the same key | ||||||||||||||||||||||||||||
| 82 | 9 | ▶ | method set ( $key, $value ) { | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 9 | ▶ | if ( $key !~ $VALID_KEY ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 84 | 2 | $logger->debugf("Invalid TraceState member key: '%s' => '%s'", $key, $value ); | |||||||||||||||||||||||||||
| 85 | 2 | return $self; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | elsif ( $value !~ $VALID_VALUE ) { | ||||||||||||||||||||||||||||
| 88 | 5 | $logger->debugf("Invalid TraceState member value: '%s' => '%s'", $key, $value ); | |||||||||||||||||||||||||||
| 89 | 5 | return $self; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 2 | $self->delete($key)->$set( $key => $value ); | |||||||||||||||||||||||||||
| 93 | 16 | } | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # Returns a clone of the TraceState without the deleted key | ||||||||||||||||||||||||||||
| 96 | 5 | ▶ | method delete ( $key ) { | ||||||||||||||||||||||||||
|
Subroutine
delete: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | ( ref $self )->new->$init( | ||||||||||||||||||||||||||||
| 98 | 10 | ▶ | List::Util::pairgrep { $a ne $key } @members | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 99 | 5 | ); | |||||||||||||||||||||||||||
| 100 | 16 | } | |||||||||||||||||||||||||||
| 101 | 16 | } | |||||||||||||||||||||||||||