X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FTypes%2FCommon%2FString.pm;h=a9ccd6fefc65561f50ea7ef547728666f2438905;hb=31633b2663f3f18784c3356360339b919e64846c;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..a9ccd6f 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.001005'; 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 }, @@ -203,6 +216,13 @@ A coercion exists via C from NonEmptyStr =back +=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 ). + =head1 SEE ALSO =over