"The presented stings come from NGINX so don't really need any validation."
And yet, you have code that identifies the IP type by a regexp, and throws if it is not "valid."
What do you think is "far better, far faster, far lighter" about
sub _slow_is_ipv4 {
shift if ref $_[0];
my $value = shift;
return undef unless defined($value);
my (@octets) = $value =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,
+3})$/;
return undef unless (@octets == 4);
foreach (@octets) {
return undef if $_ < 0 || $_ > 255;
return undef if $_ =~ /^0\d{1,2}$/;
}
return join('.', @octets);
}
in Data::Validate::IP (which has a dependency on NetAddr::IP)
as compared to the code in Regexp::Common::net?
Snarky reply to AnomalousMonk's attempt to offer assistance. Downvoted. (And the reply to bliako.)
The way forward always starts with a minimal test.
|