properly handle unicode in upper/lowercase types
[gitmo/MooseX-Types-Common.git] / lib / MooseX / Types / Common / String.pm
index 6d34354..218b826 100644 (file)
@@ -93,12 +93,12 @@ subtype NonEmptyStr,
 
 subtype LowerCaseStr,
   as NonEmptyStr,
-  where { !/[A-Z]/ms },
+  where { !/\p{Upper}/ms },
   message { "Must not contain upper case letters" },
     ( $Moose::VERSION >= 2.0200
         ? inline_as {
             $_[0]->parent()->_inline_check( $_[1] ) . ' && '
-                . qq{ ( $_[1] !~ /[A-Z]/ms ) };
+                . qq{ ( $_[1] !~ /\\p{Upper}/ms ) };
         }
         : ()
     );
@@ -109,12 +109,12 @@ coerce LowerCaseStr,
 
 subtype UpperCaseStr,
   as NonEmptyStr,
-  where { !/[a-z]/ms },
+  where { !/\p{Lower}/ms },
   message { "Must not contain lower case letters" },
     ( $Moose::VERSION >= 2.0200
         ? inline_as {
             $_[0]->parent()->_inline_check( $_[1] ) . ' && '
-                . qq{ ( $_[1] !~ m/[a-z]/ms ) };
+                . qq{ ( $_[1] !~ /\\p{Lower}/ms ) };
         }
         : ()
     );
@@ -125,28 +125,28 @@ coerce UpperCaseStr,
 
 subtype LowerCaseSimpleStr,
   as NonEmptySimpleStr,
-  where { !/[A-Z]/ },
+  where { !/\p{Upper}/ },
   message { "Must not contain upper case letters" },
     ( $Moose::VERSION >= 2.0200
         ? inline_as {
             $_[0]->parent()->_inline_check( $_[1] ) . ' && '
-                . qq{ ( $_[1] !~ m/[A-Z]/ ) };
+                . qq{ ( $_[1] !~ /\\p{Upper}/ ) };
         }
         : ()
     );
-  
+
 coerce LowerCaseSimpleStr,
   from NonEmptySimpleStr,
   via { lc };
 
 subtype UpperCaseSimpleStr,
   as NonEmptySimpleStr,
-  where { !/[a-z]/ },
+  where { !/\p{Lower}/ },
   message { "Must not contain lower case letters" },
     ( $Moose::VERSION >= 2.0200
         ? inline_as {
             $_[0]->parent()->_inline_check( $_[1] ) . ' && '
-                . qq{ ( $_[1] !~ m/[a-z]/ ) };
+                . qq{ ( $_[1] !~ /\\p{Lower}/ ) };
         }
         : ()
     );
@@ -176,46 +176,46 @@ default.
 
 =over
 
-=item * SimpleStr
+=item * C<SimpleStr>
 
-A Str with no new-line characters.
+A C<Str> with no new-line characters.
 
-=item * NonEmptySimpleStr
+=item * C<NonEmptySimpleStr>
 
-A Str with no new-line characters and length > 0
+A C<Str> with no new-line characters and length > 0
 
-=item * LowerCaseSimpleStr
+=item * C<LowerCaseSimpleStr>
 
-A Str with no new-line characters, length > 0 and no uppercase characters
-A coercion exists via C<lc> from NonEmptySimpleStr
+A C<Str> with no new-line characters, length > 0 and no uppercase characters
+A coercion exists via C<lc> from C<NonEmptySimpleStr>
 
-=item * UpperCaseSimpleStr
+=item * C<UpperCaseSimpleStr>
 
-A Str with no new-line characters, length > 0 and no lowercase characters
-A coercion exists via C<uc> from NonEmptySimpleStr
+A C<Str> with no new-line characters, length > 0 and no lowercase characters
+A coercion exists via C<uc> from C<NonEmptySimpleStr>
 
-=item * Password
+=item * C<Password>
 
-=item * StrongPassword
+=item * C<StrongPassword>
 
-=item * NonEmptyStr
+=item * C<NonEmptyStr>
 
-A Str with length > 0
+A C<Str> with length > 0
 
-=item * LowerCaseStr
+=item * C<LowerCaseStr>
 
-A Str with length > 0 and no uppercase characters.
-A coercion exists via C<lc> from NonEmptyStr
+A C<Str> with length > 0 and no uppercase characters.
+A coercion exists via C<lc> from C<NonEmptyStr>
 
-=item * UpperCaseStr
+=item * C<UpperCaseStr>
 
-A Str with length > 0 and no lowercase characters.
-A coercion exists via C<uc> from NonEmptyStr
+A C<Str> with length > 0 and no lowercase characters.
+A coercion exists via C<uc> from C<NonEmptyStr>
 
-=item * NumericCode
+=item * C<NumericCode>
 
-A Str with no new-line characters that consists of only Numeric characters.
-Examples include, Social Security Numbers, PINs, Postal Codes, HTTP Status
+A C<Str> with no new-line characters that consists of only Numeric characters.
+Examples include, Social Security Numbers, Personal Identification Numbers, Postal Codes, HTTP Status
 Codes, etc. Supports attempting to coerce from a string that has punctuation
 in it ( e.g credit card number 4111-1111-1111-1111 ).