| 1 | package Sisimai::RFC791; | ||||||||||||||||||||||||||||
| 2 | 100 | ▶ | use v5.26; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 100 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 100 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 199750 | ▶ | sub is_ipv4address { | ||||||||||||||||||||||||||
|
Subroutine
is_ipv4address: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 7 | # Returns 1 if the argument is an IPv4 address | ||||||||||||||||||||||||||||
| 8 | # @param [String] argv1 IPv4 address like "192.0.2.25" | ||||||||||||||||||||||||||||
| 9 | # @return [Bool] 1: is an IPv4 address | ||||||||||||||||||||||||||||
| 10 | # @since v5.2.0 | ||||||||||||||||||||||||||||
| 11 | 199750 | my $class = shift; | |||||||||||||||||||||||||||
| 12 | 199750 | ▶ | my $argv0 = shift || return 0; return 0 if length $argv0 < 7; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
shift() || (return 0)
MC/DC100%1/1
shift() || (return 0)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 13 | 75332 | ▶ | my @octet = split(/[.]/, $argv0); return 0 if scalar @octet != 4; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 5678 | for my $e ( @octet ) { | |||||||||||||||||||||||||||
| 16 | # Check each octet is between 0 and 255 | ||||||||||||||||||||||||||||
| 17 | 16923 | ▶ | return 0 unless $e =~ /\A[0-9]{1,3}\z/; my $v = int $e; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 14806 | ▶ | return 0 if $v < 0 || $v > 255; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$v < 0 or $v > 255
MC/DC50%1/2
$v < 0 or $v > 255
$v < 0
$v > 255
Truth table66%2/3
A or B
A= $v < 0B= $v > 255
| |||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | 3559 | return 1; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 10472 | ▶ | sub find { | ||||||||||||||||||||||||||
|
Subroutine
find: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | # Find an IPv4 address from the given string | ||||||||||||||||||||||||||||
| 25 | # @param [String] argv1 String including an IPv4 address | ||||||||||||||||||||||||||||
| 26 | # @return [Array] List of IPv4 addresses | ||||||||||||||||||||||||||||
| 27 | # @since v5.0.0 | ||||||||||||||||||||||||||||
| 28 | 10472 | my $class = shift; | |||||||||||||||||||||||||||
| 29 | 10472 | ▶ | my $argv0 = shift || return undef; return [] if length $argv0 < 7; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
shift() || (return undef)
MC/DC100%1/1
shift() || (return undef)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 10470 | $argv0 =~ tr/()[],/ /; | |||||||||||||||||||||||||||
| 32 | 10470 | return [grep { $class->is_ipv4address($_) } split(' ', $argv0)]; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 100 | 1; | |||||||||||||||||||||||||||
| 36 | __END__ | ||||||||||||||||||||||||||||