| 1 | package GDPR::IAB::TCFv2::Validator::Failure 0.512; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 25 | ▶ | use v5.12; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 25 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | use overload | ||||||||||||||
| 7 | 597 | ▶ | '""' => sub { $_[0]->{message} }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 25 | ▶ | fallback => 1; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | sub new { | ||||||||||||||
| 11 | 2312 | ▶ | my ($klass, %args) = @_; | ||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | my $self = { | ||||||||||||||
| 14 | code => defined $args{code} ? $args{code} : 0, | ||||||||||||||
| 15 | message => defined $args{message} ? $args{message} : '', | ||||||||||||||
| 16 | purpose_id => $args{purpose_id}, | ||||||||||||||
| 17 | vendor_id => $args{vendor_id}, | ||||||||||||||
| 18 | restriction_type => $args{restriction_type}, | ||||||||||||||
| 19 | cmp_id => $args{cmp_id}, | ||||||||||||||
| 20 | 2312 | ▶ | }; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 21 | |||||||||||||||
| 22 | 2312 | return bless $self, $klass; | |||||||||||||
| 23 | } | ||||||||||||||
| 24 | |||||||||||||||
| 25 | 12 | ▶ | sub code { $_[0]->{code} } | ||||||||||||
|
Subroutine
code: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 26 | 2312 | ▶ | sub message { $_[0]->{message} } | ||||||||||||
|
Subroutine
message: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 27 | 9 | ▶ | sub purpose_id { $_[0]->{purpose_id} } | ||||||||||||
|
Subroutine
purpose_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 28 | 8 | ▶ | sub vendor_id { $_[0]->{vendor_id} } | ||||||||||||
|
Subroutine
vendor_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 29 | 5 | ▶ | sub restriction_type { $_[0]->{restriction_type} } | ||||||||||||
|
Subroutine
restriction_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 30 | 3 | ▶ | sub cmp_id { $_[0]->{cmp_id} } | ||||||||||||
|
Subroutine
cmp_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 31 | |||||||||||||||
| 32 | 25 | 1; | |||||||||||||
| 33 | |||||||||||||||
| 34 | __END__ | ||||||||||||||
| 35 | |||||||||||||||
| 36 | =encoding utf8 | ||||||||||||||
| 37 | |||||||||||||||
| 38 | =head1 NAME | ||||||||||||||
| 39 | |||||||||||||||
| 40 | GDPR::IAB::TCFv2::Validator::Failure - structured failure record from the Validator | ||||||||||||||
| 41 | |||||||||||||||
| 42 | =head1 SYNOPSIS | ||||||||||||||
| 43 | |||||||||||||||
| 44 | use GDPR::IAB::TCFv2::Validator::Reason qw<:all>; | ||||||||||||||
| 45 | |||||||||||||||
| 46 | my ($validator, $tc_string) = ('...', '...'); | ||||||||||||||
| 47 | my $result = $validator->validate($tc_string); | ||||||||||||||
| 48 | |||||||||||||||
| 49 | unless ($result) { | ||||||||||||||
| 50 | for my $f ( $result->failures ) { | ||||||||||||||
| 51 | warn sprintf "code=%d message=%s\n", $f->code, $f->message; | ||||||||||||||
| 52 | |||||||||||||||
| 53 | if ( $f->code == ReasonVendorNotAllowedConsent ) { | ||||||||||||||
| 54 | # machine-readable handling | ||||||||||||||
| 55 | } | ||||||||||||||
| 56 | } | ||||||||||||||
| 57 | } | ||||||||||||||
| 58 | |||||||||||||||
| 59 | =head1 DESCRIPTION | ||||||||||||||
| 60 | |||||||||||||||
| 61 | A lightweight value object describing a single failure detected by | ||||||||||||||
| 62 | L<GDPR::IAB::TCFv2::Validator>. Each failure carries a stable integer | ||||||||||||||
| 63 | C<code> from L<GDPR::IAB::TCFv2::Validator::Reason> plus the | ||||||||||||||
| 64 | human-readable C<message> the validator emitted, and any structured | ||||||||||||||
| 65 | context that is relevant to the failure (purpose ID, vendor ID, | ||||||||||||||
| 66 | publisher restriction type, CMP ID). | ||||||||||||||
| 67 | |||||||||||||||
| 68 | This is the per-failure analogue of the Go C<lib-gdpr/validator> | ||||||||||||||
| 69 | C<Result> struct: code-driven, machine-actionable, but with a | ||||||||||||||
| 70 | ready-to-display string already attached. | ||||||||||||||
| 71 | |||||||||||||||
| 72 | C<Validator::Failure> objects are created by | ||||||||||||||
| 73 | L<GDPR::IAB::TCFv2::Validator> and surfaced via | ||||||||||||||
| 74 | L<GDPR::IAB::TCFv2::Validator::Result/failures>; users normally do not | ||||||||||||||
| 75 | construct them directly. | ||||||||||||||
| 76 | |||||||||||||||
| 77 | =head1 OVERLOADS | ||||||||||||||
| 78 | |||||||||||||||
| 79 | =head2 Stringification | ||||||||||||||
| 80 | |||||||||||||||
| 81 | print "$failure"; | ||||||||||||||
| 82 | |||||||||||||||
| 83 | Returns L</message>, so a Failure object drops into any context that | ||||||||||||||
| 84 | expects a reason string. | ||||||||||||||
| 85 | |||||||||||||||
| 86 | =head1 METHODS | ||||||||||||||
| 87 | |||||||||||||||
| 88 | =head2 code | ||||||||||||||
| 89 | |||||||||||||||
| 90 | my $code = $failure->code; | ||||||||||||||
| 91 | |||||||||||||||
| 92 | Integer reason code from L<GDPR::IAB::TCFv2::Validator::Reason>. Use | ||||||||||||||
| 93 | this to switch on the failure type programmatically. | ||||||||||||||
| 94 | |||||||||||||||
| 95 | =head2 message | ||||||||||||||
| 96 | |||||||||||||||
| 97 | my $msg = $failure->message; | ||||||||||||||
| 98 | |||||||||||||||
| 99 | Human-readable description of the failure (the same string previously | ||||||||||||||
| 100 | returned by L<GDPR::IAB::TCFv2::Validator::Result/reasons>). | ||||||||||||||
| 101 | |||||||||||||||
| 102 | =head2 purpose_id | ||||||||||||||
| 103 | |||||||||||||||
| 104 | my $pid = $failure->purpose_id; | ||||||||||||||
| 105 | |||||||||||||||
| 106 | The TCF purpose ID associated with the failure, or C<undef> when the | ||||||||||||||
| 107 | failure is not purpose-specific (e.g. a missing-disclosed-vendors | ||||||||||||||
| 108 | failure or a CMP failure). | ||||||||||||||
| 109 | |||||||||||||||
| 110 | =head2 vendor_id | ||||||||||||||
| 111 | |||||||||||||||
| 112 | my $vid = $failure->vendor_id; | ||||||||||||||
| 113 | |||||||||||||||
| 114 | The vendor ID under validation when the failure occurred, or | ||||||||||||||
| 115 | C<undef> when the failure is not vendor-specific. | ||||||||||||||
| 116 | |||||||||||||||
| 117 | =head2 restriction_type | ||||||||||||||
| 118 | |||||||||||||||
| 119 | my $rt = $failure->restriction_type; | ||||||||||||||
| 120 | |||||||||||||||
| 121 | The publisher restriction type (0 = NotAllowed, 1 = RequireConsent, | ||||||||||||||
| 122 | 2 = RequireLegitimateInterest) when the failure was caused by a | ||||||||||||||
| 123 | publisher restriction, or C<undef> otherwise. | ||||||||||||||
| 124 | |||||||||||||||
| 125 | =head2 cmp_id | ||||||||||||||
| 126 | |||||||||||||||
| 127 | my $cmp = $failure->cmp_id; | ||||||||||||||
| 128 | |||||||||||||||
| 129 | The CMP ID from the consent string when the failure was caused by the | ||||||||||||||
| 130 | CMP-validator rule, or C<undef> otherwise. | ||||||||||||||
| 131 | |||||||||||||||
| 132 | =head1 CONSTRUCTOR | ||||||||||||||
| 133 | |||||||||||||||
| 134 | =head2 new | ||||||||||||||
| 135 | |||||||||||||||
| 136 | Internal -- C<Validator::Failure> objects are constructed by | ||||||||||||||
| 137 | L<GDPR::IAB::TCFv2::Validator> as it walks its rules, then surfaced | ||||||||||||||
| 138 | via L<GDPR::IAB::TCFv2::Validator::Result/failures>. | ||||||||||||||
| 139 | |||||||||||||||
| 140 | =head1 SEE ALSO | ||||||||||||||
| 141 | |||||||||||||||
| 142 | L<GDPR::IAB::TCFv2::Validator::Reason> for the reason-code vocabulary, | ||||||||||||||
| 143 | L<GDPR::IAB::TCFv2::Validator::Result> for the container type returned | ||||||||||||||
| 144 | by L<GDPR::IAB::TCFv2::Validator/validate>. | ||||||||||||||
| 145 | |||||||||||||||
| 146 | =cut | ||||||||||||||