| 1 | # | ||||||||||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Rex::Helper::IP; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use v5.14.4; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | our $VERSION = '1.16.1'; # VERSION | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Data::Validate::IP 'is_ipv4', 'is_ipv6'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | ▶ | sub is_ip { | ||||||||||||||||||||||||||
|
Subroutine
is_ip: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 3 | my ($ip) = @_; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 3 | ▶ | if ( is_ipv4($ip) || is_ipv6($ip) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
is_ipv4($ip) or is_ipv6($ip)
MC/DC100%2/2
is_ipv4($ip) or is_ipv6($ip)
is_ipv4($ip)
is_ipv6($ip)
Truth table100%3/3
A or B
A= is_ipv4($ip)B= is_ipv6($ip)
| |||||||||||||||||||||||||||||
| 18 | 2 | return 1; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | 1 | return 0; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 8 | ▶ | sub get_server_and_port { | ||||||||||||||||||||||||||
|
Subroutine
get_server_and_port: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 8 | my ( $server, $default_port ) = @_; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 8 | my ( $rs, $rp ); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 8 | ▶ | if ( $server =~ m/:(\d+)$/ && !is_ipv6($server) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$server =~ /:(\d+)$/u and not is_ipv6($server)
MC/DC100%2/2
$server =~ /:(\d+)$/u and not is_ipv6($server)
$server =~ /:(\d+)$/u
not is_ipv6($server)
Truth table100%3/3
A and not(B)
A= $server =~ /:(\d+)$/uB= not is_ipv6($server)
| |||||||||||||||||||||||||||||
| 29 | 2 | return split( /:/, $server ); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 6 | ▶ | if ( $server =~ m/\/(\d+)$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 3 | return split( /\/(\d+)$/, $server ); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 3 | ▶ | if ( is_ip($server) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 2 | ▶ | if ( is_ipv6($server) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 1 | ( $rs, $rp ) = split( /\//, $server ); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | else { | ||||||||||||||||||||||||||||
| 41 | 1 | ( $rs, $rp ) = split( /[:\/]/, $server ); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | else { | ||||||||||||||||||||||||||||
| 45 | 1 | ( $rs, $rp ) = split( /[:\/]/, $server ); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 3 | ▶ | $rp ||= $default_port; | ||||||||||||||||||||||||||
|
Condition33%1/3
$rp ||= $default_port
MC/DC0%0/2
$rp ||= $default_port
$rp
$default_port
Truth table33%1/3
A ||= B
A= $rpB= $default_port
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 3 | return ( $rs, $rp ); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 3 | 1; | |||||||||||||||||||||||||||