| 1 | #ABSTRACT: IPv4/IPv6 addresses validator | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | package Net::IP::Checker; | ||||||||||||||||||||||||||||
| 5 | 1 | $Net::IP::Checker::VERSION = '0.02'; | |||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Regexp::IPv6 qw($IPv6_re); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Regexp::IPv4 qw($IPv4_re); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | require Exporter; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 14 | 1 | our @EXPORT_OK = qw(ip_get_version ip_is_ipv4 ip_is_ipv6); | |||||||||||||||||||||||||||
| 15 | 1 | our %EXPORT_TAGS = ( 'ALL' => [@EXPORT_OK] ); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub ip_get_version { | ||||||||||||||||||||||||||||
| 19 | 2 | ▶ | my $ip = shift; | ||||||||||||||||||||||||||
|
Subroutine
ip_get_version: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | $ip !~ /:/ and ip_is_ipv4($ip) and return '4'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $ip =~ /:/ and ip_is_ipv4($ip)
MC/DC50%1/2
not $ip =~ /:/ and ip_is_ipv4($ip)
not $ip =~ /:/
ip_is_ipv4($ip)
Truth table66%2/3
not(A) and B
A= not $ip =~ /:/B= ip_is_ipv4($ip)
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | ip_is_ipv6($ip) and return '6'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 0 | return; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | sub ip_is_ipv4 { | ||||||||||||||||||||||||||||
| 27 | 16 | ▶ | my $ip = shift; | ||||||||||||||||||||||||||
|
Subroutine
ip_is_ipv4: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 16 | ▶ | return $ip =~ /^$IPv4_re$/ ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub ip_is_ipv6 { | ||||||||||||||||||||||||||||
| 33 | 24 | ▶ | my $ip = shift; | ||||||||||||||||||||||||||
|
Subroutine
ip_is_ipv6: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 24 | ▶ | return $ip =~ /^$IPv6_re$/ ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | __END__ | ||||||||||||||||||||||||||||