X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FGitalist.git;a=blobdiff_plain;f=local-lib5%2Flib%2Fperl5%2FMooseX%2FTypes%2FCommon%2FString.pm;fp=local-lib5%2Flib%2Fperl5%2FMooseX%2FTypes%2FCommon%2FString.pm;h=708f66647dcacdda222099e78b1d50623646ee58;hp=0000000000000000000000000000000000000000;hb=3fea05b9fbf95091f4522528b9980a33e0235603;hpb=af746827daa7a8feccee889e1d12ebc74cc9201e diff --git a/local-lib5/lib/perl5/MooseX/Types/Common/String.pm b/local-lib5/lib/perl5/MooseX/Types/Common/String.pm new file mode 100644 index 0000000..708f666 --- /dev/null +++ b/local-lib5/lib/perl5/MooseX/Types/Common/String.pm @@ -0,0 +1,91 @@ +package MooseX::Types::Common::String; + +use strict; +use warnings; + +our $VERSION = '0.001000'; + +use MooseX::Types -declare => [ + qw(SimpleStr NonEmptySimpleStr Password StrongPassword NonEmptyStr) +]; + +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" }; + +subtype NonEmptySimpleStr, + as SimpleStr, + where { length($_) > 0 }, + message { "Must be a non-empty single line of no more than 255 chars" }; + +# 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" }; + +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" }; + +subtype NonEmptyStr, + as Str, + where { length($_) > 0 }, + message { "Must not be empty" }; + + +1; + +=head1 NAME + +MooseX::Types::Common::String + +=head1 SYNOPSIS + + use MooseX::Types::Common::String qw/SimpleStr/; + has short_str => (is => 'rw', isa => SimpleStr); + + ... + #this will fail + $object->short_str("string\nwith\nbreaks"); + +=head1 DESCRIPTION + +A set of commonly-used string type constraints that do not ship with Moose by +default. + +=over + +=item * SimpleStr + +A Str with no new-line characters. + +=item * NonEmptySimpleStr + +Does what it says on the tin. + +=item * Password + +=item * StrongPassword + +=item * NonEmptyStr + +=back + +=head1 SEE ALSO + +=over + +=item * L + +=back + +=head1 AUTHORS + +Please see:: L + +=cut