| 1 | package MooseX::Types::Common::String; | ||||||||||
| 2 | # ABSTRACT: Commonly used string types | ||||||||||
| 3 | |||||||||||
| 4 | 4 | our $VERSION = '0.001015'; | |||||||||
| 5 | |||||||||||
| 6 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 4 | ▶ | use MooseX::Types -declare => [ | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | qw(SimpleStr | ||||||||||
| 11 | NonEmptySimpleStr | ||||||||||
| 12 | NumericCode | ||||||||||
| 13 | LowerCaseSimpleStr | ||||||||||
| 14 | UpperCaseSimpleStr | ||||||||||
| 15 | Password | ||||||||||
| 16 | StrongPassword | ||||||||||
| 17 | NonEmptyStr | ||||||||||
| 18 | LowerCaseStr | ||||||||||
| 19 | UpperCaseStr) | ||||||||||
| 20 | 4 | ]; | |||||||||
| 21 | |||||||||||
| 22 | 4 | ▶ | use Moose (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 4 | ▶ | use MooseX::Types::Moose qw/Str/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 4 | ▶ | use if MooseX::Types->VERSION >= 0.42, 'namespace::autoclean'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | |||||||||||
| 26 | subtype SimpleStr, | ||||||||||
| 27 | as Str, | ||||||||||
| 28 | 0 | ▶ | where { (length($_) <= 255) && ($_ !~ m/\n/) }, | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||
| 29 | 0 | ▶ | message { "Must be a single line of no more than 255 chars" }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 30 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 31 | 28 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 28 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 33 | . qq{ ( (length($_[1]) <= 255) && ($_[1] !~ m/\n/) ) }; | ||||||||||
| 34 | } | ||||||||||
| 35 | : () | ||||||||||
| 36 | 4 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | |||||||||||
| 38 | subtype NonEmptySimpleStr, | ||||||||||
| 39 | as SimpleStr, | ||||||||||
| 40 | 0 | ▶ | where { length($_) > 0 }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 41 | 0 | ▶ | message { "Must be a non-empty single line of no more than 255 chars" }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 42 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 43 | 24 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 44 | 24 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 45 | . qq{ (length($_[1]) > 0) }; | ||||||||||
| 46 | } | ||||||||||
| 47 | : () | ||||||||||
| 48 | 4 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | |||||||||||
| 50 | subtype NumericCode, | ||||||||||
| 51 | as NonEmptySimpleStr, | ||||||||||
| 52 | 0 | ▶ | where { $_ =~ m/^[0-9]+$/ }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 53 | 0 | ▶ | message { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 54 | 0 | 'Must be a non-empty single line of no more than 255 chars that consists ' | |||||||||
| 55 | . 'of numeric characters only' | ||||||||||
| 56 | }, | ||||||||||
| 57 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 58 | 4 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 59 | 4 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 60 | . qq{ $_[1] =~ m/^[0-9]+\$/ }; | ||||||||||
| 61 | } | ||||||||||
| 62 | : () | ||||||||||
| 63 | 4 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | |||||||||||
| 65 | coerce NumericCode, | ||||||||||
| 66 | from NonEmptySimpleStr, | ||||||||||
| 67 | 2 | ▶ | via { my $code = $_; $code =~ s/[[:punct:][:space:]]//g; return $code }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 68 | |||||||||||
| 69 | subtype Password, | ||||||||||
| 70 | as NonEmptySimpleStr, | ||||||||||
| 71 | 0 | ▶ | where { length($_) > 3 }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 72 | 0 | ▶ | message { "Must be between 4 and 255 chars" }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 73 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 74 | 8 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 75 | 8 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 76 | . qq{ (length($_[1]) > 3) }; | ||||||||||
| 77 | } | ||||||||||
| 78 | : () | ||||||||||
| 79 | 4 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | |||||||||||
| 81 | subtype StrongPassword, | ||||||||||
| 82 | as Password, | ||||||||||
| 83 | 0 | ▶ | where { (length($_) > 7) && (m/[^a-zA-Z]/) }, | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||
| 84 | 0 | ▶ | message {"Must be between 8 and 255 chars, and contain a non-alpha char" }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 85 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 86 | 4 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 87 | 4 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 88 | . qq{ ( (length($_[1]) > 7) && ($_[1] =~ m/[^a-zA-Z]/) ) }; | ||||||||||
| 89 | } | ||||||||||
| 90 | : () | ||||||||||
| 91 | 4 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | |||||||||||
| 93 | subtype NonEmptyStr, | ||||||||||
| 94 | as Str, | ||||||||||
| 95 | 0 | ▶ | where { length($_) > 0 }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 96 | 0 | ▶ | message { "Must not be empty" }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 97 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 98 | 12 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 99 | 12 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 100 | . qq{ (length($_[1]) > 0) }; | ||||||||||
| 101 | } | ||||||||||
| 102 | : () | ||||||||||
| 103 | 4 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 104 | |||||||||||
| 105 | subtype LowerCaseStr, | ||||||||||
| 106 | as NonEmptyStr, | ||||||||||
| 107 | 0 | ▶ | where { !/\p{Upper}/ms }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 108 | 0 | ▶ | message { "Must not contain upper case letters" }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 109 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 110 | 4 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 111 | 4 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 112 | . qq{ ( $_[1] !~ /\\p{Upper}/ms ) }; | ||||||||||
| 113 | } | ||||||||||
| 114 | : () | ||||||||||
| 115 | 4 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 116 | |||||||||||
| 117 | coerce LowerCaseStr, | ||||||||||
| 118 | from NonEmptyStr, | ||||||||||
| 119 | 1 | ▶ | via { lc }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 120 | |||||||||||
| 121 | subtype UpperCaseStr, | ||||||||||
| 122 | as NonEmptyStr, | ||||||||||
| 123 | 0 | ▶ | where { !/\p{Lower}/ms }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 124 | 0 | ▶ | message { "Must not contain lower case letters" }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 125 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 126 | 4 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 127 | 4 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 128 | . qq{ ( $_[1] !~ /\\p{Lower}/ms ) }; | ||||||||||
| 129 | } | ||||||||||
| 130 | : () | ||||||||||
| 131 | 4 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 132 | |||||||||||
| 133 | coerce UpperCaseStr, | ||||||||||
| 134 | from NonEmptyStr, | ||||||||||
| 135 | 1 | ▶ | via { uc }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 136 | |||||||||||
| 137 | subtype LowerCaseSimpleStr, | ||||||||||
| 138 | as NonEmptySimpleStr, | ||||||||||
| 139 | 0 | ▶ | where { !/\p{Upper}/ }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 140 | 0 | ▶ | message { "Must not contain upper case letters" }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 141 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 142 | 4 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 143 | 4 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 144 | . qq{ ( $_[1] !~ /\\p{Upper}/ ) }; | ||||||||||
| 145 | } | ||||||||||
| 146 | : () | ||||||||||
| 147 | 4 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 148 | |||||||||||
| 149 | coerce LowerCaseSimpleStr, | ||||||||||
| 150 | from NonEmptySimpleStr, | ||||||||||
| 151 | 1 | ▶ | via { lc }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 152 | |||||||||||
| 153 | subtype UpperCaseSimpleStr, | ||||||||||
| 154 | as NonEmptySimpleStr, | ||||||||||
| 155 | 0 | ▶ | where { !/\p{Lower}/ }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 156 | 0 | ▶ | message { "Must not contain lower case letters" }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 157 | ( $Moose::VERSION >= 2.0200 | ||||||||||
| 158 | 4 | ▶ | ? inline_as { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 159 | 4 | $_[0]->parent()->_inline_check( $_[1] ) . ' && ' | |||||||||
| 160 | . qq{ ( $_[1] !~ /\\p{Lower}/ ) }; | ||||||||||
| 161 | } | ||||||||||
| 162 | : () | ||||||||||
| 163 | 4 | ▶ | ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 164 | |||||||||||
| 165 | coerce UpperCaseSimpleStr, | ||||||||||
| 166 | from NonEmptySimpleStr, | ||||||||||
| 167 | 1 | ▶ | via { uc }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 168 | |||||||||||
| 169 | 4 | 1; | |||||||||
| 170 | |||||||||||
| 171 | __END__ | ||||||||||