| 1 | package GDPR::IAB::TCFv2::Validator::Reason 0.512; | ||||||||||
| 2 | 26 | ▶ | use v5.12; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 26 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 26 | require Exporter; | |||||||||
| 6 | 26 | ▶ | use parent qw<Exporter>; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | |||||||||||
| 9 | use constant { | ||||||||||
| 10 | |||||||||||
| 11 | # Successful validation: no failure to report. | ||||||||||
| 12 | 26 | ReasonNone => 0, | |||||||||
| 13 | |||||||||||
| 14 | # The TCF string is missing the mandatory disclosed vendors segment | ||||||||||
| 15 | # (TCF v2.2+ requirement). | ||||||||||
| 16 | ReasonMissingDisclosedVendors => 1, | ||||||||||
| 17 | |||||||||||
| 18 | # The configured vendor ID is not present in the disclosed vendors | ||||||||||
| 19 | # segment. | ||||||||||
| 20 | ReasonVendorNotDisclosed => 2, | ||||||||||
| 21 | |||||||||||
| 22 | # The vendor is not allowed globally (neither consent nor legitimate | ||||||||||
| 23 | # interest is granted for any purpose). | ||||||||||
| 24 | ReasonVendorNotAllowed => 3, | ||||||||||
| 25 | |||||||||||
| 26 | # A required purpose is not allowed for the vendor. | ||||||||||
| 27 | ReasonPurposeNotAllowed => 4, | ||||||||||
| 28 | |||||||||||
| 29 | # A publisher restriction of type 0 (Not Allowed) is present for a | ||||||||||
| 30 | # required purpose. | ||||||||||
| 31 | ReasonPublisherRestrictionNotAllowed => 5, | ||||||||||
| 32 | |||||||||||
| 33 | # A publisher restriction of type 1 (Requires Consent) is present | ||||||||||
| 34 | # for a purpose configured under the legitimate-interest legal basis. | ||||||||||
| 35 | ReasonPublisherRestrictionRequireConsent => 6, | ||||||||||
| 36 | |||||||||||
| 37 | # A publisher restriction of type 2 (Requires Legitimate Interest) is | ||||||||||
| 38 | # present for a purpose configured under the consent legal basis. | ||||||||||
| 39 | ReasonPublisherRestrictionRequireLegitimateInterest => 7, | ||||||||||
| 40 | |||||||||||
| 41 | # The vendor is not allowed for a specific purpose under the consent | ||||||||||
| 42 | # legal basis (vendor consent flag and/or purpose consent flag missing). | ||||||||||
| 43 | ReasonVendorNotAllowedConsent => 8, | ||||||||||
| 44 | |||||||||||
| 45 | # The vendor is not allowed for a specific purpose under the legitimate | ||||||||||
| 46 | # interest legal basis (vendor LI flag and/or purpose LI flag missing). | ||||||||||
| 47 | ReasonVendorNotAllowedLegitimateInterest => 9, | ||||||||||
| 48 | |||||||||||
| 49 | # The TCF spec forbids the legitimate-interest legal basis for this | ||||||||||
| 50 | # purpose: Purpose 1 always; Purposes 3-6 on TcfPolicyVersion >= 4. | ||||||||||
| 51 | ReasonLegitimateInterestNotPermittedForPurpose => 10, | ||||||||||
| 52 | |||||||||||
| 53 | # The consent string's TcfPolicyVersion is below the validator's | ||||||||||
| 54 | # configured minimum. | ||||||||||
| 55 | ReasonPolicyVersionTooLow => 11, | ||||||||||
| 56 | |||||||||||
| 57 | # The consent string could not be decoded (malformed, empty, or | ||||||||||
| 58 | # unsupported version). Only emitted when explicitly requested. | ||||||||||
| 59 | ReasonDecodeError => 12, | ||||||||||
| 60 | |||||||||||
| 61 | # The consent string's CMP ID is not recognized as a valid (active, | ||||||||||
| 62 | # non-deleted) entry in the configured CMP registry. The CMPValidator | ||||||||||
| 63 | # rule today returns a single boolean; a future refinement may | ||||||||||
| 64 | # introduce ReasonCMPDeleted / ReasonCMPUnknown to distinguish the | ||||||||||
| 65 | # lifecycle states (codes reserved for that work). | ||||||||||
| 66 | ReasonInvalidCMP => 13, | ||||||||||
| 67 | 26 | ▶ | }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 68 | |||||||||||
| 69 | 26 | use constant ReasonDescription => { | |||||||||
| 70 | ReasonNone => "no failure", | ||||||||||
| 71 | ReasonMissingDisclosedVendors => "missing disclosed vendors", | ||||||||||
| 72 | ReasonVendorNotDisclosed => "vendor not disclosed", | ||||||||||
| 73 | ReasonVendorNotAllowed => "vendor not allowed", | ||||||||||
| 74 | ReasonPurposeNotAllowed => "purpose not allowed", | ||||||||||
| 75 | ReasonPublisherRestrictionNotAllowed => "publisher restriction: not allowed", | ||||||||||
| 76 | ReasonPublisherRestrictionRequireConsent => "publisher restriction: requires consent", | ||||||||||
| 77 | ReasonPublisherRestrictionRequireLegitimateInterest => "publisher restriction: requires legitimate interest", | ||||||||||
| 78 | ReasonVendorNotAllowedConsent => "vendor not allowed for purpose (consent)", | ||||||||||
| 79 | ReasonVendorNotAllowedLegitimateInterest => "vendor not allowed for purpose (legitimate interest)", | ||||||||||
| 80 | ReasonLegitimateInterestNotPermittedForPurpose => "legitimate interest not permitted for purpose", | ||||||||||
| 81 | ReasonPolicyVersionTooLow => "tcf policy version too low", | ||||||||||
| 82 | ReasonDecodeError => "decode error", | ||||||||||
| 83 | ReasonInvalidCMP => "invalid cmp id", | ||||||||||
| 84 | 26 | ▶ | }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 85 | |||||||||||
| 86 | # Lazily built reverse map: integer code -> human-readable string. | ||||||||||
| 87 | 26 | my %_CODE_TO_STRING; | |||||||||
| 88 | |||||||||||
| 89 | sub reason_string { | ||||||||||
| 90 | 17 | ▶ | my ($code) = @_; | ||||||||
|
Subroutine
reason_string: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 91 | |||||||||||
| 92 | 17 | ▶ | return "unknown validation failure" unless defined $code; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | |||||||||||
| 94 | 16 | ▶ | unless (%_CODE_TO_STRING) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | 1 | my $desc = ReasonDescription; | |||||||||
| 96 | 1 | for my $name (keys %{$desc}) { | |||||||||
| 97 | 14 | my $value = __PACKAGE__->can($name)->(); | |||||||||
| 98 | 14 | $_CODE_TO_STRING{$value} = $desc->{$name}; | |||||||||
| 99 | } | ||||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | 16 | my $string = $_CODE_TO_STRING{$code}; | |||||||||
| 103 | 16 | ▶ | return defined($string) ? $string : "unknown validation failure"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | 26 | our @EXPORT_OK = qw< | |||||||||
| 107 | ReasonNone | ||||||||||
| 108 | ReasonMissingDisclosedVendors | ||||||||||
| 109 | ReasonVendorNotDisclosed | ||||||||||
| 110 | ReasonVendorNotAllowed | ||||||||||
| 111 | ReasonPurposeNotAllowed | ||||||||||
| 112 | ReasonPublisherRestrictionNotAllowed | ||||||||||
| 113 | ReasonPublisherRestrictionRequireConsent | ||||||||||
| 114 | ReasonPublisherRestrictionRequireLegitimateInterest | ||||||||||
| 115 | ReasonVendorNotAllowedConsent | ||||||||||
| 116 | ReasonVendorNotAllowedLegitimateInterest | ||||||||||
| 117 | ReasonLegitimateInterestNotPermittedForPurpose | ||||||||||
| 118 | ReasonPolicyVersionTooLow | ||||||||||
| 119 | ReasonDecodeError | ||||||||||
| 120 | ReasonInvalidCMP | ||||||||||
| 121 | ReasonDescription | ||||||||||
| 122 | reason_string | ||||||||||
| 123 | >; | ||||||||||
| 124 | |||||||||||
| 125 | 26 | our %EXPORT_TAGS = (all => \@EXPORT_OK); | |||||||||
| 126 | |||||||||||
| 127 | 26 | 1; | |||||||||
| 128 | |||||||||||
| 129 | __END__ | ||||||||||
| 130 | |||||||||||
| 131 | =encoding utf8 | ||||||||||
| 132 | |||||||||||
| 133 | =head1 NAME | ||||||||||
| 134 | |||||||||||
| 135 | GDPR::IAB::TCFv2::Validator::Reason - machine-readable validation-failure codes | ||||||||||
| 136 | |||||||||||
| 137 | =head1 SYNOPSIS | ||||||||||
| 138 | |||||||||||
| 139 | use warnings; | ||||||||||
| 140 | |||||||||||
| 141 | use GDPR::IAB::TCFv2::Validator::Reason qw<:all>; | ||||||||||
| 142 | |||||||||||
| 143 | use feature 'say'; | ||||||||||
| 144 | |||||||||||
| 145 | say "Code is ", ReasonVendorNotDisclosed, | ||||||||||
| 146 | ", and it means ", reason_string(ReasonVendorNotDisclosed); | ||||||||||
| 147 | # Output: | ||||||||||
| 148 | # Code is 2, and it means vendor not disclosed | ||||||||||
| 149 | |||||||||||
| 150 | # Lookup by name via the description hashref (auto-quoted bareword). | ||||||||||
| 151 | say ReasonDescription->{ReasonPublisherRestrictionNotAllowed}; | ||||||||||
| 152 | # Output: | ||||||||||
| 153 | # publisher restriction: not allowed | ||||||||||
| 154 | |||||||||||
| 155 | =head1 DESCRIPTION | ||||||||||
| 156 | |||||||||||
| 157 | Stable, integer-valued reason codes that describe why | ||||||||||
| 158 | L<GDPR::IAB::TCFv2::Validator/validate> or | ||||||||||
| 159 | L<GDPR::IAB::TCFv2::Validator/validate_all> rejected a | ||||||||||
| 160 | TCF consent string. | ||||||||||
| 161 | The set mirrors the C<Reason> enum from the Go | ||||||||||
| 162 | C<lib-gdpr/validator> package so cross-language tooling can share a | ||||||||||
| 163 | single vocabulary. | ||||||||||
| 164 | |||||||||||
| 165 | Each code is also accompanied by a short human-readable string available | ||||||||||
| 166 | via L</reason_string> (lookup by integer) or L</ReasonDescription> | ||||||||||
| 167 | (lookup by constant name). | ||||||||||
| 168 | |||||||||||
| 169 | =head1 CONSTANTS | ||||||||||
| 170 | |||||||||||
| 171 | All constants are non-negative integers. The values are stable: new codes | ||||||||||
| 172 | are appended; existing codes never change. | ||||||||||
| 173 | |||||||||||
| 174 | =head2 ReasonNone | ||||||||||
| 175 | |||||||||||
| 176 | Code 0. Successful validation; no failure to report. | ||||||||||
| 177 | |||||||||||
| 178 | =head2 ReasonMissingDisclosedVendors | ||||||||||
| 179 | |||||||||||
| 180 | Code 1. The TC string is missing the mandatory disclosed vendors segment | ||||||||||
| 181 | (TCF v2.2+ requirement under policy version >= 5). | ||||||||||
| 182 | |||||||||||
| 183 | =head2 ReasonVendorNotDisclosed | ||||||||||
| 184 | |||||||||||
| 185 | Code 2. The configured vendor ID is not present in the disclosed vendors | ||||||||||
| 186 | segment. | ||||||||||
| 187 | |||||||||||
| 188 | =head2 ReasonVendorNotAllowed | ||||||||||
| 189 | |||||||||||
| 190 | Code 3. The vendor is not allowed globally: neither vendor consent nor | ||||||||||
| 191 | vendor legitimate interest is granted for any purpose. | ||||||||||
| 192 | |||||||||||
| 193 | =head2 ReasonPurposeNotAllowed | ||||||||||
| 194 | |||||||||||
| 195 | Code 4. A required purpose has neither its consent flag nor its | ||||||||||
| 196 | legitimate-interest flag set. | ||||||||||
| 197 | |||||||||||
| 198 | =head2 ReasonPublisherRestrictionNotAllowed | ||||||||||
| 199 | |||||||||||
| 200 | Code 5. A publisher restriction of type 0 (Not Allowed) is present for | ||||||||||
| 201 | a required purpose. Always rejects. | ||||||||||
| 202 | |||||||||||
| 203 | =head2 ReasonPublisherRestrictionRequireConsent | ||||||||||
| 204 | |||||||||||
| 205 | Code 6. A publisher restriction of type 1 (Requires Consent) is present | ||||||||||
| 206 | for a purpose configured under the legitimate-interest legal basis. | ||||||||||
| 207 | |||||||||||
| 208 | =head2 ReasonPublisherRestrictionRequireLegitimateInterest | ||||||||||
| 209 | |||||||||||
| 210 | Code 7. A publisher restriction of type 2 (Requires Legitimate Interest) | ||||||||||
| 211 | is present for a purpose configured under the consent legal basis. | ||||||||||
| 212 | |||||||||||
| 213 | =head2 ReasonVendorNotAllowedConsent | ||||||||||
| 214 | |||||||||||
| 215 | Code 8. The vendor is not allowed for a specific purpose under the | ||||||||||
| 216 | consent legal basis (vendor consent flag and/or purpose consent flag is | ||||||||||
| 217 | missing). | ||||||||||
| 218 | |||||||||||
| 219 | =head2 ReasonVendorNotAllowedLegitimateInterest | ||||||||||
| 220 | |||||||||||
| 221 | Code 9. The vendor is not allowed for a specific purpose under the | ||||||||||
| 222 | legitimate-interest legal basis (vendor LI flag and/or purpose LI flag | ||||||||||
| 223 | is missing). | ||||||||||
| 224 | |||||||||||
| 225 | =head2 ReasonLegitimateInterestNotPermittedForPurpose | ||||||||||
| 226 | |||||||||||
| 227 | Code 10. The TCF spec forbids the legitimate-interest legal basis for | ||||||||||
| 228 | this purpose, regardless of the vendor's signal: Purpose 1 always, and | ||||||||||
| 229 | Purposes 3-6 on TcfPolicyVersion >= 4 (TCF v2.2+). | ||||||||||
| 230 | |||||||||||
| 231 | =head2 ReasonPolicyVersionTooLow | ||||||||||
| 232 | |||||||||||
| 233 | Code 11. The consent string's TcfPolicyVersion is below the validator's | ||||||||||
| 234 | configured C<min_tcf_policy_version>. | ||||||||||
| 235 | |||||||||||
| 236 | =head2 ReasonDecodeError | ||||||||||
| 237 | |||||||||||
| 238 | Code 12. The consent string could not be decoded (malformed, empty, or | ||||||||||
| 239 | unsupported version). Only emitted when the validator is configured to | ||||||||||
| 240 | report decode errors as structured failures rather than via C<croak>. | ||||||||||
| 241 | |||||||||||
| 242 | =head2 ReasonInvalidCMP | ||||||||||
| 243 | |||||||||||
| 244 | Code 13. The consent string's CMP ID is not recognized as a valid | ||||||||||
| 245 | (active, non-deleted) entry in the configured CMP registry. The | ||||||||||
| 246 | C<CMPValidator> rule today returns a single boolean; a future | ||||||||||
| 247 | refinement may add C<ReasonCMPDeleted> / C<ReasonCMPUnknown> to | ||||||||||
| 248 | distinguish lifecycle states (the codes are reserved for that work). | ||||||||||
| 249 | |||||||||||
| 250 | =head2 ReasonDescription | ||||||||||
| 251 | |||||||||||
| 252 | Hashref mapping each constant name (C<"ReasonNone">, C<"ReasonVendorNotAllowed">, | ||||||||||
| 253 | ...) to its human-readable string. Useful with auto-quoted bareword | ||||||||||
| 254 | subscripts: | ||||||||||
| 255 | |||||||||||
| 256 | my $msg = ReasonDescription->{ReasonVendorNotAllowed}; | ||||||||||
| 257 | |||||||||||
| 258 | =head1 FUNCTIONS | ||||||||||
| 259 | |||||||||||
| 260 | =head2 reason_string | ||||||||||
| 261 | |||||||||||
| 262 | my $msg = reason_string($code); | ||||||||||
| 263 | |||||||||||
| 264 | Returns the human-readable description for an integer reason code. | ||||||||||
| 265 | Returns C<"unknown validation failure"> for unknown or undefined codes. | ||||||||||
| 266 | |||||||||||
| 267 | =head1 SEE ALSO | ||||||||||
| 268 | |||||||||||
| 269 | L<GDPR::IAB::TCFv2::Validator>, L<GDPR::IAB::TCFv2::Validator::Result>. | ||||||||||
| 270 | |||||||||||
| 271 | =cut | ||||||||||