add inline_as definitions for each type
Dave Rolsky [Fri, 29 Jul 2011 22:00:42 +0000 (17:00 -0500)]
lib/MooseX/Types/Common/Numeric.pm
lib/MooseX/Types/Common/String.pm

index c702497..7744cfc 100644 (file)
@@ -14,27 +14,62 @@ use MooseX::Types::Moose qw/Num Int/;
 subtype PositiveNum,
   as Num,
   where { $_ >= 0 },
-  message { "Must be a positive number" };
+  message { "Must be a positive number" },
+    ( $Moose::VERSION >= 2.0200
+        ? inline_as {
+            $_[0]->parent()->_inline_check( $_[1] ) . ' && '
+                . qq{ ($_[1] >= 0) };
+        }
+        : ()
+    );
 
 subtype PositiveInt,
   as Int,
   where { $_ >= 0 },
-  message { "Must be a positive integer" };
+  message { "Must be a positive integer" },
+    ( $Moose::VERSION >= 2.0200
+        ? inline_as {
+            $_[0]->parent()->_inline_check( $_[1] ) . ' && '
+                . qq{ ($_[1] >= 0) };
+        }
+        : ()
+    );
 
 subtype NegativeNum,
   as Num,
   where { $_ <= 0 },
-  message { "Must be a negative number" };
+  message { "Must be a negative number" },
+    ( $Moose::VERSION >= 2.0200
+        ? inline_as {
+            $_[0]->parent()->_inline_check( $_[1] ) . ' && '
+                . qq{ ($_[1] <= 0) };
+        }
+        : ()
+    );
 
 subtype NegativeInt,
   as Int,
   where { $_ <= 0 },
-  message { "Must be a negative integer" };
+  message { "Must be a negative integer" },
+    ( $Moose::VERSION >= 2.0200
+        ? inline_as {
+            $_[0]->parent()->_inline_check( $_[1] ) . ' && '
+                . qq{ ($_[1] <= 0) };
+        }
+        : ()
+    );
 
 subtype SingleDigit,
   as PositiveInt,
   where { $_ <= 9 },
-  message { "Must be a single digit" };
+  message { "Must be a single digit" },
+    ( $Moose::VERSION >= 2.0200
+        ? inline_as {
+            $_[0]->parent()->_inline_check( $_[1] ) . ' && '
+                . qq{ ($_[1] <= 9) };
+        }
+        : ()
+    );
 
 1;
 
index 7e6a831..add28aa 100644 (file)
@@ -14,28 +14,63 @@ use MooseX::Types::Moose qw/Str/;
 subtype SimpleStr,
   as Str,
   where { (length($_) <= 255) && ($_ !~ m/\n/) },
-  message { "Must be a single line of no more than 255 chars" };
+  message { "Must be a single line of no more than 255 chars" },
+    ( $Moose::VERSION >= 2.0200
+        ? inline_as {
+            $_[0]->parent()->_inline_check( $_[1] ) . ' && '
+                . qq{ ( (length($_[1]) <= 255) && ($_[1] !~ m/\n/) ) };
+        }
+        : ()
+    );
 
 subtype NonEmptySimpleStr,
   as SimpleStr,
   where { length($_) > 0 },
-  message { "Must be a non-empty single line of no more than 255 chars" };
+  message { "Must be a non-empty single line of no more than 255 chars" },
+    ( $Moose::VERSION >= 2.0200
+        ? inline_as {
+            $_[0]->parent()->_inline_check( $_[1] ) . ' && '
+                . qq{ (length($_[1]) > 0) };
+        }
+        : ()
+    );
 
 # XXX duplicating constraint msges since moose only uses last message
 subtype Password,
   as NonEmptySimpleStr,
   where { length($_) > 3 },
-  message { "Must be between 4 and 255 chars" };
+  message { "Must be between 4 and 255 chars" },
+    ( $Moose::VERSION >= 2.0200
+        ? inline_as {
+            $_[0]->parent()->_inline_check( $_[1] ) . ' && '
+                . qq{ (length($_[1]) > 3) };
+        }
+        : ()
+    );
 
 subtype StrongPassword,
   as Password,
   where { (length($_) > 7) && (m/[^a-zA-Z]/) },
-  message {"Must be between 8 and 255 chars, and contain a non-alpha char" };
+  message {"Must be between 8 and 255 chars, and contain a non-alpha char" },
+    ( $Moose::VERSION >= 2.0200
+        ? inline_as {
+            $_[0]->parent()->_inline_check( $_[1] ) . ' && '
+                . qq{ ( (length($_[1]) > 7) && ($_[1] =~ m/[^a-zA-Z]/) ) };
+        }
+        : ()
+    );
 
 subtype NonEmptyStr,
   as Str,
   where { length($_) > 0 },
-  message { "Must not be empty" };
+  message { "Must not be empty" },
+    ( $Moose::VERSION >= 2.0200
+        ? inline_as {
+            $_[0]->parent()->_inline_check( $_[1] ) . ' && '
+                . qq{ (length($_[1]) > 0) };
+        }
+        : ()
+    );
 
 
 1;