| 1 | package Data::Sah::Type::hash; | ||
| 2 | |||
| 3 | 6 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 6 | ▶ | use Data::Sah::Util::Role 'has_clause', 'has_clause_alias'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 6 | ▶ | use Role::Tiny; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 6 | ▶ | use Role::Tiny::With; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 6 | with 'Data::Sah::Type::BaseType'; | |
| 10 | 6 | with 'Data::Sah::Type::Comparable'; | |
| 11 | 6 | with 'Data::Sah::Type::HasElems'; | |
| 12 | |||
| 13 | 6 | has_clause_alias each_elem => 'of'; | |
| 14 | |||
| 15 | 6 | has_clause_alias each_index => 'each_key'; | |
| 16 | 6 | has_clause_alias each_elem => 'each_value'; | |
| 17 | 6 | has_clause_alias check_each_index => 'check_each_key'; | |
| 18 | 6 | has_clause_alias check_each_elem => 'check_each_value'; | |
| 19 | |||
| 20 | has_clause "keys", | ||
| 21 | v => 2, | ||
| 22 | tags => ['constraint'], | ||
| 23 | schema => ['hash' => {req=>1, values => ['sah::schema', {req=>1}]}], | ||
| 24 | inspect_elem => 1, | ||
| 25 | 0 | ▶ | subschema => sub { values %{ $_[0] } }, |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 26 | 6 | allow_expr => 0, | |
| 27 | attrs => { | ||
| 28 | restrict => { | ||
| 29 | schema => [bool => default=>1], | ||
| 30 | allow_expr => 0, # TODO | ||
| 31 | }, | ||
| 32 | create_default => { | ||
| 33 | schema => [bool => default=>1], | ||
| 34 | allow_expr => 0, # TODO | ||
| 35 | }, | ||
| 36 | }, | ||
| 37 | ; | ||
| 38 | |||
| 39 | has_clause "re_keys", | ||
| 40 | v => 2, | ||
| 41 | prio => 51, | ||
| 42 | tags => ['constraint'], | ||
| 43 | schema => ['hash' => { | ||
| 44 | req=>1, | ||
| 45 | keys => ['re', {req=>1}], | ||
| 46 | values => ['sah::schema', {req=>1}], | ||
| 47 | }], | ||
| 48 | inspect_elem => 1, | ||
| 49 | 0 | ▶ | subschema => sub { values %{ $_[0] } }, |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 50 | 6 | allow_expr => 0, | |
| 51 | attrs => { | ||
| 52 | restrict => { | ||
| 53 | schema => [bool => default=>1], | ||
| 54 | allow_expr => 0, # TODO | ||
| 55 | }, | ||
| 56 | }, | ||
| 57 | ; | ||
| 58 | |||
| 59 | 6 | has_clause "req_keys", | |
| 60 | v => 2, | ||
| 61 | tags => ['constraint'], | ||
| 62 | schema => ['array', {req=>1, of=>['str', {req=>1}]}], | ||
| 63 | allow_expr => 1, | ||
| 64 | ; | ||
| 65 | 6 | has_clause_alias req_keys => 'req_all_keys'; | |
| 66 | 6 | has_clause_alias req_keys => 'req_all'; | |
| 67 | |||
| 68 | 6 | has_clause "allowed_keys", | |
| 69 | v => 2, | ||
| 70 | tags => ['constraint'], | ||
| 71 | schema => ['array', {req=>1, of=>['str', {req=>1}]}], | ||
| 72 | allow_expr => 1, | ||
| 73 | ; | ||
| 74 | |||
| 75 | 6 | has_clause "allowed_keys_re", | |
| 76 | v => 2, | ||
| 77 | prio => 51, | ||
| 78 | tags => ['constraint'], | ||
| 79 | schema => ['re', {req=>1}], | ||
| 80 | allow_expr => 1, | ||
| 81 | ; | ||
| 82 | |||
| 83 | 6 | has_clause "forbidden_keys", | |
| 84 | v => 2, | ||
| 85 | tags => ['constraint'], | ||
| 86 | schema => ['array', {req=>1, of=>['str', {req=>1}]}], | ||
| 87 | allow_expr => 1, | ||
| 88 | ; | ||
| 89 | |||
| 90 | 6 | has_clause "forbidden_keys_re", | |
| 91 | v => 2, | ||
| 92 | prio => 51, | ||
| 93 | tags => ['constraint'], | ||
| 94 | schema => ['re', {req=>1}], | ||
| 95 | allow_expr => 1, | ||
| 96 | ; | ||
| 97 | |||
| 98 | 6 | has_clause "choose_one_key", | |
| 99 | v => 2, | ||
| 100 | prio => 50, | ||
| 101 | tags => ['constraint'], | ||
| 102 | schema => ['array', {req=>1, of=>['str', {req=>1}], min_len=>1}], | ||
| 103 | allow_expr => 0, # for now | ||
| 104 | ; | ||
| 105 | 6 | has_clause_alias choose_one_key => 'choose_one'; | |
| 106 | |||
| 107 | 6 | has_clause "choose_all_keys", | |
| 108 | v => 2, | ||
| 109 | prio => 50, | ||
| 110 | tags => ['constraint'], | ||
| 111 | schema => ['array', {req=>1, of=>['str', {req=>1}], min_len=>1}], | ||
| 112 | allow_expr => 0, # for now | ||
| 113 | ; | ||
| 114 | 6 | has_clause_alias choose_all_keys => 'choose_all'; | |
| 115 | |||
| 116 | 6 | has_clause "req_one_key", | |
| 117 | v => 2, | ||
| 118 | prio => 50, | ||
| 119 | tags => ['constraint'], | ||
| 120 | schema => ['array', {req=>1, of=>['str', {req=>1}], min_len=>1}], | ||
| 121 | allow_expr => 0, # for now | ||
| 122 | ; | ||
| 123 | 6 | has_clause_alias req_one_key => 'req_one'; | |
| 124 | |||
| 125 | 6 | has_clause "req_some_keys", | |
| 126 | v => 2, | ||
| 127 | prio => 50, | ||
| 128 | tags => ['constraint'], | ||
| 129 | schema => ['array', { | ||
| 130 | req => 1, | ||
| 131 | len => 3, | ||
| 132 | elems => [ | ||
| 133 | [int => {req=>1, min=>0}], # min | ||
| 134 | [int => {req=>1, min=>0}], # max | ||
| 135 | [array => {req=>1, of=>['str', {req=>1}], min_len=>1}], # keys | ||
| 136 | ], | ||
| 137 | }], | ||
| 138 | allow_expr => 0, # for now | ||
| 139 | ; | ||
| 140 | 6 | has_clause_alias req_some_keys => 'req_some'; | |
| 141 | |||
| 142 | # for now we only support the first argument as str, not array[str] | ||
| 143 | 6 | my $sch_dep = ['array', { | |
| 144 | req => 1, | ||
| 145 | elems => [ | ||
| 146 | ['str', {req=>1}], | ||
| 147 | ['array', {of=>['str', {req=>1}]}], | ||
| 148 | ], | ||
| 149 | }]; | ||
| 150 | |||
| 151 | 6 | has_clause "dep_any", | |
| 152 | v => 2, | ||
| 153 | prio => 50, | ||
| 154 | tags => ['constraint'], | ||
| 155 | schema => $sch_dep, | ||
| 156 | allow_expr => 0, # for now | ||
| 157 | ; | ||
| 158 | |||
| 159 | 6 | has_clause "dep_all", | |
| 160 | v => 2, | ||
| 161 | prio => 50, | ||
| 162 | tags => ['constraint'], | ||
| 163 | schema => $sch_dep, | ||
| 164 | allow_expr => 0, # for now | ||
| 165 | ; | ||
| 166 | |||
| 167 | 6 | has_clause "req_dep_any", | |
| 168 | v => 2, | ||
| 169 | prio => 50, | ||
| 170 | tags => ['constraint'], | ||
| 171 | schema => $sch_dep, | ||
| 172 | allow_expr => 0, # for now | ||
| 173 | ; | ||
| 174 | |||
| 175 | 6 | has_clause "req_dep_all", | |
| 176 | v => 2, | ||
| 177 | prio => 50, | ||
| 178 | tags => ['constraint'], | ||
| 179 | schema => $sch_dep, | ||
| 180 | allow_expr => 0, # for now | ||
| 181 | ; | ||
| 182 | |||
| 183 | # prop_alias indices => 'keys' | ||
| 184 | |||
| 185 | # prop_alias elems => 'values' | ||
| 186 | |||
| 187 | 6 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |
| 188 | 6 | our $DATE = '2024-02-16'; # DATE | |
| 189 | 6 | our $DIST = 'Data-Sah'; # DIST | |
| 190 | 6 | our $VERSION = '0.917'; # VERSION | |
| 191 | |||
| 192 | 6 | 1; | |
| 193 | # ABSTRACT: hash type | ||
| 194 | |||
| 195 | __END__ | ||