X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FTypes%2FCommon%2FString.pm;h=218b8262573488423b6428f98197f1fc94e9e097;hb=edd6ff8072b9de004e253b207f07d85326d83151;hp=e7483cf469dc400afc58f56f4b17a6efe8f0ad43;hpb=559b5d74cde30be92fb26402bf2bc7e69fab16df;p=gitmo%2FMooseX-Types-Common.git diff --git a/lib/MooseX/Types/Common/String.pm b/lib/MooseX/Types/Common/String.pm index e7483cf..218b826 100644 --- a/lib/MooseX/Types/Common/String.pm +++ b/lib/MooseX/Types/Common/String.pm @@ -1,10 +1,9 @@ package MooseX::Types::Common::String; +# ABSTRACT: Commonly used string types use strict; use warnings; -our $VERSION = '0.001004'; - use MooseX::Types -declare => [ qw(SimpleStr NonEmptySimpleStr @@ -94,12 +93,12 @@ subtype NonEmptyStr, subtype LowerCaseStr, as NonEmptyStr, - where { /^[a-z]+$/xms }, - message { "Must only contain lower case letters" }, + where { !/\p{Upper}/ms }, + message { "Must not contain upper case letters" }, ( $Moose::VERSION >= 2.0200 ? inline_as { $_[0]->parent()->_inline_check( $_[1] ) . ' && ' - . qq{ ( $_[1] =~ m/^[a-z]+\$/xms ) }; + . qq{ ( $_[1] !~ /\\p{Upper}/ms ) }; } : () ); @@ -110,12 +109,12 @@ coerce LowerCaseStr, subtype UpperCaseStr, as NonEmptyStr, - where { /^[A-Z]+$/xms }, - message { "Must only contain upper case letters" }, + 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]+\$/xms ) }; + . qq{ ( $_[1] !~ /\\p{Lower}/ms ) }; } : () ); @@ -126,28 +125,28 @@ coerce UpperCaseStr, subtype LowerCaseSimpleStr, as NonEmptySimpleStr, - where { /^[a-z]+$/x }, - message { "Must only contain lower case letters" }, + 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]+\$/x ) }; + . qq{ ( $_[1] !~ /\\p{Upper}/ ) }; } : () ); - + coerce LowerCaseSimpleStr, from NonEmptySimpleStr, via { lc }; subtype UpperCaseSimpleStr, as NonEmptySimpleStr, - where { /^[A-Z]+$/x }, - message { "Must only contain upper case letters" }, + 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]+\$/x ) }; + . qq{ ( $_[1] !~ /\\p{Lower}/ ) }; } : () ); @@ -157,10 +156,9 @@ coerce UpperCaseSimpleStr, via { uc }; 1; +__END__ -=head1 NAME - -MooseX::Types::Common::String - Commonly used string types +=pod =head1 SYNOPSIS @@ -178,51 +176,51 @@ default. =over -=item * SimpleStr +=item * C -A Str with no new-line characters. +A C with no new-line characters. -=item * NonEmptySimpleStr +=item * C -A Str with no new-line characters and length > 0 +A C with no new-line characters and length > 0 -=item * LowerCaseSimpleStr +=item * C -A Str with no new-line characters, length > 0 and all lowercase characters -A coercion exists via C from NonEmptySimpleStr +A C with no new-line characters, length > 0 and no uppercase characters +A coercion exists via C from C -=item * UpperCaseSimpleStr +=item * C -A Str with no new-line characters, length > 0 and all uppercase characters -A coercion exists via C from NonEmptySimpleStr +A C with no new-line characters, length > 0 and no lowercase characters +A coercion exists via C from C -=item * Password +=item * C -=item * StrongPassword +=item * C -=item * NonEmptyStr +=item * C -A Str with length > 0 +A C with length > 0 -=item * LowerCaseStr +=item * C -A Str with length > 0 and all lowercase characters. -A coercion exists via C from NonEmptyStr +A C with length > 0 and no uppercase characters. +A coercion exists via C from C -=item * UpperCaseStr +=item * C -A Str with length > 0 and all uppercase characters. -A coercion exists via C from NonEmptyStr - -=back +A C with length > 0 and no lowercase characters. +A coercion exists via C from C -=item * NumericCode +=item * C -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 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 ). +=back + =head1 SEE ALSO =over @@ -231,8 +229,4 @@ in it ( e.g credit card number 4111-1111-1111-1111 ). =back -=head1 AUTHORS - -Please see:: L - =cut