X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FTypes%2FCommon%2FString.pm;h=0cee6f93ffb4dfae4499fd12813d24a5410b18cc;hb=bf8650d89cb21d78cc6d3576e315367acd854fb4;hp=be5d706fd4b00e5e223feed01fc1f44a73b09113;hpb=a40ef11aad38121a0e17c5ea693e10b72d9218f7;p=gitmo%2FMooseX-Types-Common.git diff --git a/lib/MooseX/Types/Common/String.pm b/lib/MooseX/Types/Common/String.pm index be5d706..0cee6f9 100644 --- a/lib/MooseX/Types/Common/String.pm +++ b/lib/MooseX/Types/Common/String.pm @@ -3,11 +3,12 @@ package MooseX::Types::Common::String; use strict; use warnings; -our $VERSION = '0.001004'; +our $VERSION = '0.001008'; use MooseX::Types -declare => [ qw(SimpleStr NonEmptySimpleStr + NumericCode LowerCaseSimpleStr UpperCaseSimpleStr Password @@ -43,6 +44,18 @@ subtype NonEmptySimpleStr, : () ); +subtype NumericCode, + as NonEmptySimpleStr, + where { $_ =~ m/^[0-9]+$/ }, + message { + 'Must be a non-empty single line of no more than 255 chars that consists ' + . 'of numeric characters only' + }; + +coerce NumericCode, + from NonEmptySimpleStr, + via { my $code = $_; $code =~ s/[[:punct:]]//g; return $code }; + subtype Password, as NonEmptySimpleStr, where { length($_) > 3 }, @@ -81,12 +94,12 @@ subtype NonEmptyStr, subtype LowerCaseStr, as NonEmptyStr, - where { /^[a-z]+$/xms }, - message { "Must only contain lower case letters" }, + where { !/[A-Z]/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] !~ /[A-Z]/ms ) }; } : () ); @@ -97,12 +110,12 @@ coerce LowerCaseStr, subtype UpperCaseStr, as NonEmptyStr, - where { /^[A-Z]+$/xms }, - message { "Must only contain upper case letters" }, + where { !/[a-z]/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] !~ m/[a-z]/ms ) }; } : () ); @@ -113,12 +126,12 @@ coerce UpperCaseStr, subtype LowerCaseSimpleStr, as NonEmptySimpleStr, - where { /^[a-z]+$/x }, - message { "Must only contain lower case letters" }, + where { !/[A-Z]/ }, + 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] !~ m/[A-Z]/ ) }; } : () ); @@ -129,12 +142,12 @@ coerce LowerCaseSimpleStr, subtype UpperCaseSimpleStr, as NonEmptySimpleStr, - where { /^[A-Z]+$/x }, - message { "Must only contain upper case letters" }, + where { !/[a-z]/ }, + 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] !~ m/[a-z]/ ) }; } : () ); @@ -175,12 +188,12 @@ A Str with no new-line characters and length > 0 =item * LowerCaseSimpleStr -A Str with no new-line characters, length > 0 and all lowercase characters +A Str with no new-line characters, length > 0 and no uppercase characters A coercion exists via C from NonEmptySimpleStr =item * UpperCaseSimpleStr -A Str with no new-line characters, length > 0 and all uppercase characters +A Str with no new-line characters, length > 0 and no lowercase characters A coercion exists via C from NonEmptySimpleStr =item * Password @@ -193,14 +206,21 @@ A Str with length > 0 =item * LowerCaseStr -A Str with length > 0 and all lowercase characters. +A Str with length > 0 and no uppercase characters. A coercion exists via C from NonEmptyStr =item * UpperCaseStr -A Str with length > 0 and all uppercase characters. +A Str with length > 0 and no lowercase characters. A coercion exists via C from NonEmptyStr +=item * NumericCode + +A Str with no new-line characters that consists of only Numeric characters. +Examples include, Social Security Numbers, PINs, 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