| 1 | package HTML::FormHandler::Types; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Moose type constraints | ||||||||||||||||||||||||||||
| 3 | 4 | $HTML::FormHandler::Types::VERSION = '0.410002'; | |||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use MooseX::Types -declare => [ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 'PositiveNum', 'PositiveInt', 'NegativeNum', 'NegativeInt', | ||||||||||||||||||||||||||||
| 9 | 'SingleDigit', 'SimpleStr', 'NonEmptySimpleStr', 'Password', | ||||||||||||||||||||||||||||
| 10 | 'StrongPassword', 'NonEmptyStr', 'Email', 'State', | ||||||||||||||||||||||||||||
| 11 | 'Zip', 'IPAddress', 'NoSpaces', 'WordChars', | ||||||||||||||||||||||||||||
| 12 | 'NotAllDigits', 'Printable', 'PrintableAndNewline', 'SingleWord', | ||||||||||||||||||||||||||||
| 13 | 'Collapse', 'Upper', 'Lower', 'Trim', | ||||||||||||||||||||||||||||
| 14 | 4 | ]; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 4 | our $class_messages = { | |||||||||||||||||||||||||||
| 17 | PositiveNum => "Must be a positive number", | ||||||||||||||||||||||||||||
| 18 | PositiveInt => "Must be a positive integer", | ||||||||||||||||||||||||||||
| 19 | NegativeNum => "Must be a negative number", | ||||||||||||||||||||||||||||
| 20 | NegativeInt => "Must be a negative integer", | ||||||||||||||||||||||||||||
| 21 | SingleDigit => "Must be a single digit", | ||||||||||||||||||||||||||||
| 22 | SimpleStr => 'Must be a single line of no more than 255 chars', | ||||||||||||||||||||||||||||
| 23 | NonEmptySimpleStr => "Must be a non-empty single line of no more than 255 chars", | ||||||||||||||||||||||||||||
| 24 | Password => "Must be between 4 and 255 chars", | ||||||||||||||||||||||||||||
| 25 | StrongPassword =>"Must be between 8 and 255 chars, and contain a non-alpha char", | ||||||||||||||||||||||||||||
| 26 | NonEmptyStr => "Must not be empty", | ||||||||||||||||||||||||||||
| 27 | State => "Not a valid state", | ||||||||||||||||||||||||||||
| 28 | Email => "Email is not valid", | ||||||||||||||||||||||||||||
| 29 | Zip => "Zip is not valid", | ||||||||||||||||||||||||||||
| 30 | IPAddress => "Not a valid IP address", | ||||||||||||||||||||||||||||
| 31 | NoSpaces =>'Must not contain spaces', | ||||||||||||||||||||||||||||
| 32 | WordChars => 'Must be made up of letters, digits, and underscores', | ||||||||||||||||||||||||||||
| 33 | NotAllDigits => 'Must not be all digits', | ||||||||||||||||||||||||||||
| 34 | Printable => 'Field contains non-printable characters', | ||||||||||||||||||||||||||||
| 35 | PrintableAndNewline => 'Field contains non-printable characters', | ||||||||||||||||||||||||||||
| 36 | SingleWord => 'Field must contain a single word', | ||||||||||||||||||||||||||||
| 37 | }; | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 4 | ▶ | use MooseX::Types::Moose ( 'Str', 'Num', 'Int' ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | subtype PositiveNum, as Num, where { $_ >= 0 }, message { "Must be a positive number" }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 8 | ▶ | subtype PositiveInt, as Int, where { $_ >= 0 }, message { "Must be a positive integer" }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | subtype NegativeNum, as Num, where { $_ <= 0 }, message { "Must be a negative number" }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | subtype NegativeInt, as Int, where { $_ <= 0 }, message { "Must be a negative integer" }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | subtype SingleDigit, as PositiveInt, where { $_ <= 9 }, message { "Must be a single digit" }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | subtype SimpleStr, | ||||||||||||||||||||||||||||
| 53 | as Str, | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | where { ( length($_) <= 255 ) && ( $_ !~ m/\n/ ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | message { $class_messages->{SimpleStr} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | subtype NonEmptySimpleStr, | ||||||||||||||||||||||||||||
| 58 | as SimpleStr, | ||||||||||||||||||||||||||||
| 59 | 0 | ▶ | where { length($_) > 0 }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | message { $class_messages->{NonEmptySimpleStr} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | subtype Password, | ||||||||||||||||||||||||||||
| 63 | as NonEmptySimpleStr, | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | where { length($_) >= 4 && length($_) <= 255 }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | message { $class_messages->{Password} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | subtype StrongPassword, | ||||||||||||||||||||||||||||
| 68 | as Password, | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | where { ( length($_) >= 8 ) && length($_) <= 255 && (m/[^a-zA-Z]/) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
Condition0%0/3
length $_ >= 8 and length $_ <= 255
MC/DC0%0/2
length $_ >= 8 and length $_ <= 255
length $_ >= 8
length $_ <= 255
Truth table0%0/3
A and B
A= length $_ >= 8B= length $_ <= 255
| |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | message { $class_messages->{StrongPassword} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | subtype NonEmptyStr, as Str, where { length($_) > 0 }, message { $class_messages->{NonEmptyStr} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 4 | ▶ | subtype State, as Str, where { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 75 | 4 | my $value = $_; | |||||||||||||||||||||||||||
| 76 | 4 | my $state = <<EOF; | |||||||||||||||||||||||||||
| 77 | AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD | ||||||||||||||||||||||||||||
| 78 | MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA PR RI | ||||||||||||||||||||||||||||
| 79 | SC SD TN TX UT VT VA WA WV WI WY DC AP FP FPO APO GU VI | ||||||||||||||||||||||||||||
| 80 | EOF | ||||||||||||||||||||||||||||
| 81 | 4 | return ( $state =~ /\b($value)\b/i ); | |||||||||||||||||||||||||||
| 82 | 3 | ▶ | }, message { $class_messages->{State} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 2 | ▶ | subtype Email, as Str, where { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 85 | 2 | my $value = shift; | |||||||||||||||||||||||||||
| 86 | 2 | require Email::Valid; | |||||||||||||||||||||||||||
| 87 | 2 | my $valid; | |||||||||||||||||||||||||||
| 88 | 2 | ▶ | return ( $valid = Email::Valid->address($value) ) && | ||||||||||||||||||||||||||
|
Condition66%2/3
($valid = 'Email::Valid'->address($value)) && $valid eq $value
MC/DC50%1/2
($valid = 'Email::Valid'->address($value)) && $valid eq $value
($valid = 'Email::Valid'->address($value))
$valid eq $value
Truth table66%2/3
A && B
A= ($valid = 'Email::Valid'->address($value))B= $valid eq $value
| |||||||||||||||||||||||||||||
| 89 | ( $valid eq $value ); | ||||||||||||||||||||||||||||
| 90 | 1 | ▶ | }, message { $class_messages->{Email} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | subtype Zip, | ||||||||||||||||||||||||||||
| 93 | as Str, | ||||||||||||||||||||||||||||
| 94 | 0 | ▶ | where { /^(\s*\d{5}(?:[-]\d{4})?\s*)$/ }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | message { $class_messages->{Zip} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 9 | ▶ | subtype IPAddress, as Str, where { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 98 | 9 | /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ | |||||||||||||||||||||||||||
| 99 | 5 | ▶ | }, message { $class_messages->{IPAddress} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | subtype NoSpaces, | ||||||||||||||||||||||||||||
| 102 | as Str, | ||||||||||||||||||||||||||||
| 103 | 8 | ▶ | where { ! /\s/ }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 104 | 3 | ▶ | message { $class_messages->{NoSpaces} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | subtype WordChars, | ||||||||||||||||||||||||||||
| 107 | as Str, | ||||||||||||||||||||||||||||
| 108 | 11 | ▶ | where { ! /\W/ }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 109 | 6 | ▶ | message { $class_messages->{WordChars} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | subtype NotAllDigits, | ||||||||||||||||||||||||||||
| 112 | as Str, | ||||||||||||||||||||||||||||
| 113 | 11 | ▶ | where { ! /^\d+$/ }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 114 | 5 | ▶ | message { $class_messages->{NotAllDigits} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | subtype Printable, | ||||||||||||||||||||||||||||
| 117 | as Str, | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | where { /^\p{IsPrint}*\z/ }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | message { $class_messages->{Printable} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | subtype PrintableAndNewline, | ||||||||||||||||||||||||||||
| 122 | as Str, | ||||||||||||||||||||||||||||
| 123 | 0 | ▶ | where { /^[\p{IsPrint}\n]*\z/ }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | message { $class_messages->{PrintableAndNewline} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | subtype SingleWord, | ||||||||||||||||||||||||||||
| 127 | as Str, | ||||||||||||||||||||||||||||
| 128 | 8 | ▶ | where { /^\w*\z/ }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 129 | 3 | ▶ | message { $class_messages->{SingleWord} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | subtype Collapse, | ||||||||||||||||||||||||||||
| 132 | as Str, | ||||||||||||||||||||||||||||
| 133 | 3 | ▶ | where{ ! /\s{2,}/ }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | coerce Collapse, | ||||||||||||||||||||||||||||
| 136 | from Str, | ||||||||||||||||||||||||||||
| 137 | 1 | ▶ | via { s/\s+/ /g; return $_; }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | subtype Lower, | ||||||||||||||||||||||||||||
| 140 | as Str, | ||||||||||||||||||||||||||||
| 141 | 20 | ▶ | where { ! /[[:upper:]]/ }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | coerce Lower, | ||||||||||||||||||||||||||||
| 144 | from Str, | ||||||||||||||||||||||||||||
| 145 | 6 | ▶ | via { lc }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | subtype Upper, | ||||||||||||||||||||||||||||
| 148 | as Str, | ||||||||||||||||||||||||||||
| 149 | 20 | ▶ | where { ! /[[:lower:]]/ }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | coerce Upper, | ||||||||||||||||||||||||||||
| 152 | from Str, | ||||||||||||||||||||||||||||
| 153 | 6 | ▶ | via { uc }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | subtype Trim, | ||||||||||||||||||||||||||||
| 156 | as Str, | ||||||||||||||||||||||||||||
| 157 | 3 | ▶ | where { ! /^\s+/ && | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Condition66%2/3
/^\s+/ || /\s+$/
MC/DC50%1/2
/^\s+/ || /\s+$/
/^\s+/
/\s+$/
Truth table66%2/3
A || B
A= /^\s+/B= /\s+$/
| |||||||||||||||||||||||||||||
| 158 | 4 | ! /\s+$/ }; | |||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | coerce Trim, | ||||||||||||||||||||||||||||
| 161 | from Str, | ||||||||||||||||||||||||||||
| 162 | 1 | ▶ | via { s/^\s+// && | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | s/\s+$//; | ||||||||||||||||||||||||||||
| 164 | 1 | return $_; }; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 4 | 1; | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | __END__ | ||||||||||||||||||||||||||||