NAME

GDPR::IAB::TCFv2::Validator::Result - outcome object returned by GDPR::IAB::TCFv2::Validator

SYNOPSIS

my ($validator, $tc_string) = ('...', '...');
my $result = $validator->validate($tc_string);

if ($result) {
    # Validation passed.
}
else {
    warn "$result\n";                 # one reason per line by default
    for my $reason ( $result->reasons ) {
         warn $reason;
    }
}

# Use Perl's output record separator to control how reasons join:
{
    local $\ = " | ";
    print "$result";                  # "reason1 | reason2"
}

DESCRIPTION

A small immutable carrier for the outcome of a "validate" in GDPR::IAB::TCFv2::Validator or "validate_all" in GDPR::IAB::TCFv2::Validator run. It overloads boolean and string contexts so it drops into typical error-handling idioms without an explicit accessor call.

OVERLOADS

Boolean

if ($result) { ... }
if (!$result) { ... }

True when validation passed (no rules failed); false otherwise.

Stringification

print "$result\n";

Returns the empty string for a passing result. For a failing result, returns the failure reasons joined by Perl's output record separator ($\); if $\ is undefined, reasons are joined by "\n".

This means:

print "$result\n";              # one reason per line
local $\ = " | ";
print "$result\n";              # "reason1 | reason2"

aligns naturally with the way print would have laid out the reasons if you had iterated and printed them yourself.

METHODS

is_valid

my $ok = $result->is_valid;

Returns truthy for a passing result, falsy otherwise. Equivalent to the boolean overload but available as an explicit method for callers that prefer it.

reasons

my @reasons = $result->reasons;

Returns the list of human-readable failure reason strings. Empty for a passing result. Equivalent to map { $_->message } $result->failures.

failures

my @failures = $result->failures;

Returns the list of structured GDPR::IAB::TCFv2::Validator::Failure objects. Each failure carries a stable integer code, the human-readable message, and any structured context (purpose, vendor, restriction type, CMP). Use this when you need to react programmatically to specific failure types.

use GDPR::IAB::TCFv2::Validator::Reason qw<:all>;

for my $f ( $result->failures ) {
    if ( $f->code == ReasonVendorNotAllowedConsent ) {
        handle_consent_gap( $f->purpose_id );
    }
}

reason_codes

my @codes = $result->reason_codes;

Returns the list of integer reason codes. Equivalent to map { $_->code } $result->failures; useful when only the codes are needed (e.g. for assertions or counters).

CONSTRUCTOR

new

Internal — construct via "validate" in GDPR::IAB::TCFv2::Validator rather than directly.

SEE ALSO

GDPR::IAB::TCFv2::Validator, GDPR::IAB::TCFv2::Validator::Failure, GDPR::IAB::TCFv2::Validator::Reason.