Subject: | Pre-compiled regex for MooseX-Types-IPv4 |
If this module is used to verify *a lot* of address it would greatly
speed-up the validation if the regex were pre-compiled instead of
created every time.
I supplied a patch to do this for most of them, unless you had a reason
for not specifically doing this that I missed.
Subject: | IPv4.pm.patch |
--- IPv4.pm Wed Dec 02 14:05:20 2009
+++ IPv4.pm.new Wed Jan 27 16:17:46 2010
@@ -12,20 +12,59 @@
our $VERSION = '0.03';
- my $ip2valr .= '';
- my $ip3valr .= '';
+ my $ip2valr = qr{};
+ my $ip3valr = qr{};
- my $ip4valr .= '^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}';
- $ip4valr .= '(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$';
-
-
- my $nmvalr .= '^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}';
- $nmvalr .= '(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$';
+ my $ip4valr = qr{
+ ^
+ (?:
+ (?:
+ 25 [0-5]
+ | 2 [0-4] [0-9]
+ | [01]? [0-9] [0-9]?
+ )
+ \.
+ ){3}
+ (?:
+ 25 [0-5]
+ | 2 [0-4] [0-9]
+ | [01]? [0-9] [0-9]?
+ )
+ $
+ }xo;
+
+
+ my $nmvalr = qr{
+ ^
+ (?:
+ (?:
+ 25 [0-5]
+ | 2 [0-4] [0-9]
+ | [01]? [0-9] [0-9]?
+ )
+ \.
+ ){3}
+ (?:
+ 25 [0-5]
+ | 2 [0-4] [0-9]
+ | [01]? [0-9] [0-9]?
+ )
+ $
+ }xo;
+
+ my $cidrvalr = qr{
+ ^
+ (?:
+ [0-2]? [0-9]
+ | 3 [0-2]
+ )
+ $
+ }xo;
subtype cidr,
as Int,
- where { /^(?:[0-2]?[0-9]||3[0-2])/ },
+ where { $_ =~ $cidrvalr },
message { "$_ is not a valid CIDR " };
@@ -33,7 +72,7 @@
## I don't use it, but prototyped it in anyway.
subtype ip2,
as Str,
- where { /$ip2valr/ },
+ where { $_ =~ $ip2valr },
message { "$_ is not a valid ip address " };
@@ -41,7 +80,7 @@
## I don't use it, but prototyped it in anyway.
subtype ip3,
as Str,
- where { /$ip3valr/ },
+ where { $_ =~ $ip3valr },
message { "$_ is not a valid ip address " };
@@ -50,7 +89,7 @@
## which is how I do all of my ip address manipulations.
subtype ip4,
as Str,
- where { /$ip4valr/ },
+ where { $_ =~ $ip4valr },
message { "$_ is not a valid ip address " };