| 1 | package Net::NATS2::URI; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 7 | 6 | my $class = shift; | |||||||||||||||||||||||||||
| 8 | 6 | return $class->parse(@_); | |||||||||||||||||||||||||||
| 9 | } | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 8 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=10 SCAR=23.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 8 | my ($class, $value) = @_; | |||||||||||||||||||||||||||
| 13 | 8 | ▶ | return unless defined $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 8 | my ($scheme, $authority) = $value =~ /\A(nats):\/\/([^\/?#]*)\z/i; | |||||||||||||||||||||||||||
| 16 | 8 | ▶ | return unless defined $scheme && length $authority; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $scheme and length $authority
MC/DC50%1/2
defined $scheme and length $authority
defined $scheme
length $authority
Truth table66%2/3
A and B
A= defined $schemeB= length $authority
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 7 | my ($userinfo, $host_port); | |||||||||||||||||||||||||||
| 19 | 7 | $host_port = $authority; | |||||||||||||||||||||||||||
| 20 | 7 | my $at = rindex($host_port, '@'); | |||||||||||||||||||||||||||
| 21 | 7 | ▶ | if ($at >= 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 2 | $userinfo = substr($host_port, 0, $at); | |||||||||||||||||||||||||||
| 23 | 2 | $host_port = substr($host_port, $at + 1); | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 7 | my ($host, $port); | |||||||||||||||||||||||||||
| 27 | 7 | ▶ | if ($host_port =~ /\A\[([^\]]+)\](?::(\d+))?\z/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 28 | 1 | ($host, $port) = ($1, $2); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | elsif ($host_port =~ /\A([^:]+)(?::(\d+))?\z/) { | ||||||||||||||||||||||||||||
| 31 | 6 | ($host, $port) = ($1, $2); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | else { | ||||||||||||||||||||||||||||
| 34 | 0 | return; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 7 | my ($user, $password); | |||||||||||||||||||||||||||
| 38 | 7 | ▶ | if (defined $userinfo) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 2 | ($user, $password) = split /:/, $userinfo, 2; | |||||||||||||||||||||||||||
| 40 | 2 | ▶ | $user = _percent_decode($user) if defined $user; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 2 | ▶ | $password = _percent_decode($password) if defined $password; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 7 | return bless { | |||||||||||||||||||||||||||
| 45 | as_string => $value, | ||||||||||||||||||||||||||||
| 46 | host => $host, | ||||||||||||||||||||||||||||
| 47 | password => $password, | ||||||||||||||||||||||||||||
| 48 | port => $port, | ||||||||||||||||||||||||||||
| 49 | scheme => lc $scheme, | ||||||||||||||||||||||||||||
| 50 | user => $user, | ||||||||||||||||||||||||||||
| 51 | }, $class; | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 4 | ▶ | sub _percent_decode { | ||||||||||||||||||||||||||
|
Subroutine
_percent_decode: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 4 | my ($value) = @_; | |||||||||||||||||||||||||||
| 56 | 4 | $value =~ s/%([0-9A-Fa-f]{2})/chr hex $1/ge; | |||||||||||||||||||||||||||
| 57 | 4 | return $value; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 1 | ▶ | sub as_string { return $_[0]->{as_string}; } | ||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 6 | ▶ | sub host { return $_[0]->{host}; } | ||||||||||||||||||||||||||
|
Subroutine
host: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 62 | 2 | ▶ | sub password { return $_[0]->{password}; } | ||||||||||||||||||||||||||
|
Subroutine
password: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 6 | ▶ | sub port { return $_[0]->{port}; } | ||||||||||||||||||||||||||
|
Subroutine
port: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | 1 | ▶ | sub scheme { return $_[0]->{scheme}; } | ||||||||||||||||||||||||||
|
Subroutine
scheme: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | 2 | ▶ | sub user { return $_[0]->{user}; } | ||||||||||||||||||||||||||
|
Subroutine
user: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 5 | 1; | |||||||||||||||||||||||||||