| 1 | package GDPR::IAB::TCFv2::PublisherTC 0.530; | ||||||||||||||||||||||||||||
| 2 | 73 | ▶ | use v5.12; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 73 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 73 | ▶ | use Carp qw<croak>; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 73 | ▶ | use GDPR::IAB::TCFv2::BitUtils qw<is_set | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | get_uint3 | ||||||||||||||||||||||||||||
| 9 | get_uint6 | ||||||||||||||||||||||||||||
| 10 | 73 | >; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 73 | ▶ | use constant { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 73 | SEGMENT_TYPE_PUBLISHER_TC => 3, | |||||||||||||||||||||||||||
| 14 | MAX_PURPOSE_ID => 24, | ||||||||||||||||||||||||||||
| 15 | OFFSETS => { | ||||||||||||||||||||||||||||
| 16 | SEGMENT_TYPE => 0, | ||||||||||||||||||||||||||||
| 17 | PURPOSE_CONSENT_ALLOWED => 3, | ||||||||||||||||||||||||||||
| 18 | PURPOSE_LIT_ALLOWED => 27, | ||||||||||||||||||||||||||||
| 19 | NUM_CUSTOM_PURPOSES => 51, | ||||||||||||||||||||||||||||
| 20 | CUSTOM_PURPOSES_CONSENT => 57, | ||||||||||||||||||||||||||||
| 21 | }, | ||||||||||||||||||||||||||||
| 22 | 73 | }; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 9679 | ▶ | sub Parse { | ||||||||||||||||||||||||||
|
Subroutine
Parse: called CC=8 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 9679 | my ($klass, %args) = @_; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 9679 | ▶ | croak "missing 'data'" unless defined $args{data}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 9679 | ▶ | croak "missing 'data_size'" unless defined $args{data_size}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 9679 | ▶ | croak "missing 'options'" unless defined $args{options}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 9679 | ▶ | croak "missing 'options.json'" unless defined $args{options}->{json}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 9679 | my $data = $args{data}; | |||||||||||||||||||||||||||
| 34 | 9679 | my $data_size = $args{data_size}; # size in bits | |||||||||||||||||||||||||||
| 35 | 9679 | my $options = $args{options}; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 9679 | ▶ | croak "invalid min size" if $data_size < 57; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 9679 | my $segment_type = get_uint3($data, OFFSETS->{SEGMENT_TYPE}); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | croak "invalid segment type ${segment_type}: expected @{[ SEGMENT_TYPE_PUBLISHER_TC ]}" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | if $segment_type != SEGMENT_TYPE_PUBLISHER_TC; | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 9679 | my $num_custom_purposes = get_uint6($data, OFFSETS->{NUM_CUSTOM_PURPOSES}); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 9679 | my $total_expected_size = 2 * $num_custom_purposes + 57; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 9679 | ▶ | croak "invalid size" if $data_size < $total_expected_size; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | my $self = { | ||||||||||||||||||||||||||||
| 51 | data => $data, | ||||||||||||||||||||||||||||
| 52 | options => $options, | ||||||||||||||||||||||||||||
| 53 | num_custom_purposes => $num_custom_purposes, | ||||||||||||||||||||||||||||
| 54 | 9679 | custom_purpose_lit_offset => OFFSETS->{CUSTOM_PURPOSES_CONSENT} + $num_custom_purposes, | |||||||||||||||||||||||||||
| 55 | }; | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 9679 | bless $self, $klass; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 9679 | return $self; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 2 | ▶ | sub num_custom_purposes { | ||||||||||||||||||||||||||
|
Subroutine
num_custom_purposes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | return $self->{num_custom_purposes}; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 48 | ▶ | sub is_purpose_consent_allowed { | ||||||||||||||||||||||||||
|
Subroutine
is_purpose_consent_allowed: called CC=3 SCAR=13.3
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 48 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | croak "invalid purpose id $id: must be between 1 and @{[ MAX_PURPOSE_ID ]}" if $id < 1 || $id > MAX_PURPOSE_ID; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$id < 1 or $id > 24
MC/DC0%0/2
$id < 1 or $id > 24
$id < 1
$id > 24
Truth table33%1/3
A or B
A= $id < 1B= $id > 24
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 48 | return $self->_safe_is_purpose_consent_allowed($id); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 48 | ▶ | sub is_purpose_legitimate_interest_allowed { | ||||||||||||||||||||||||||
|
Subroutine
is_purpose_legitimate_interest_allowed: called CC=3 SCAR=13.3
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 48 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | croak "invalid purpose id $id: must be between 1 and @{[ MAX_PURPOSE_ID ]}" if $id < 1 || $id > MAX_PURPOSE_ID; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$id < 1 or $id > 24
MC/DC0%0/2
$id < 1 or $id > 24
$id < 1
$id > 24
Truth table33%1/3
A or B
A= $id < 1B= $id > 24
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 48 | return $self->_safe_is_purpose_legitimate_interest_allowed($id); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 2 | ▶ | sub is_custom_purpose_consent_allowed { | ||||||||||||||||||||||||||
|
Subroutine
is_custom_purpose_consent_allowed: called CC=3 SCAR=13.3
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 2 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | croak "invalid custom purpose id $id: must be between 1 and @{[ $self->{num_custom_purposes} ]}" | |||||||||||||||||||||||||||
| 88 | 2 | ▶ | if $id < 1 || $id > $self->{num_custom_purposes}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$id < 1 or $id > $self->{"num_custom_purposes"}
MC/DC0%0/2
$id < 1 or $id > $self->{"num_custom_purposes"}
$id < 1
$id > $self->{"num_custom_purposes"}
Truth table33%1/3
A or B
A= $id < 1B= $id > $self->{"num_custom_purposes"}
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 2 | return $self->_safe_is_custom_purpose_consent_allowed($id); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 2 | ▶ | sub is_custom_purpose_legitimate_interest_allowed { | ||||||||||||||||||||||||||
|
Subroutine
is_custom_purpose_legitimate_interest_allowed: called CC=3 SCAR=13.3
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 2 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | croak "invalid custom purpose id $id: must be between 1 and @{[ $self->{num_custom_purposes} ]}" | |||||||||||||||||||||||||||
| 97 | 2 | ▶ | if $id < 1 || $id > $self->{num_custom_purposes}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$id < 1 or $id > $self->{"num_custom_purposes"}
MC/DC0%0/2
$id < 1 or $id > $self->{"num_custom_purposes"}
$id < 1
$id > $self->{"num_custom_purposes"}
Truth table33%1/3
A or B
A= $id < 1B= $id > $self->{"num_custom_purposes"}
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 2 | return $self->_safe_is_custom_purpose_legitimate_interest_allowed($id); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 882 | ▶ | sub TO_JSON { | ||||||||||||||||||||||||||
|
Subroutine
TO_JSON: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 882 | my $self = shift; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 882 | my %consents = map { $_ => $self->_safe_is_purpose_consent_allowed($_) } 1 .. MAX_PURPOSE_ID; | |||||||||||||||||||||||||||
| 106 | 882 | my %legitimate_interests = map { $_ => $self->_safe_is_purpose_legitimate_interest_allowed($_) } 1 .. MAX_PURPOSE_ID; | |||||||||||||||||||||||||||
| 107 | my %custom_purpose_consents | ||||||||||||||||||||||||||||
| 108 | 882 | = map { $_ => $self->_safe_is_custom_purpose_consent_allowed($_) } 1 .. $self->{num_custom_purposes}; | |||||||||||||||||||||||||||
| 109 | my %custom_purpose_legitimate_interests | ||||||||||||||||||||||||||||
| 110 | 882 | = map { $_ => $self->_safe_is_custom_purpose_legitimate_interest_allowed($_) } 1 .. $self->{num_custom_purposes}; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | return { | ||||||||||||||||||||||||||||
| 113 | consents => $self->_format_json_subsection(\%consents, MAX_PURPOSE_ID), | ||||||||||||||||||||||||||||
| 114 | legitimate_interests => $self->_format_json_subsection(\%legitimate_interests, MAX_PURPOSE_ID), | ||||||||||||||||||||||||||||
| 115 | custom_purposes => { | ||||||||||||||||||||||||||||
| 116 | consents => $self->_format_json_subsection(\%custom_purpose_consents, $self->{num_custom_purposes}), | ||||||||||||||||||||||||||||
| 117 | legitimate_interests => | ||||||||||||||||||||||||||||
| 118 | 882 | $self->_format_json_subsection(\%custom_purpose_legitimate_interests, $self->{num_custom_purposes}), | |||||||||||||||||||||||||||
| 119 | }, | ||||||||||||||||||||||||||||
| 120 | }; | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 3528 | ▶ | sub _format_json_subsection { | ||||||||||||||||||||||||||
|
Subroutine
_format_json_subsection: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 124 | 3528 | my ($self, $data, $max) = @_; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 3528 | my ($false, $true) = @{$self->{options}->{json}->{boolean_values}}; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 3528 | ▶ | if (!!$self->{options}->{json}->{compact}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 16 | return [grep { $data->{$_} } 1 .. $max,]; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 3512 | my $verbose = !!$self->{options}->{json}->{verbose}; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 3512 | ▶ | return $data if $verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 3512 | return {map { $_ => $true } grep { $data->{$_} } keys %{$data}}; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 21216 | ▶ | sub _safe_is_purpose_consent_allowed { | ||||||||||||||||||||||||||
|
Subroutine
_safe_is_purpose_consent_allowed: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 140 | 21216 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 141 | 21216 | return scalar(is_set($self->{data}, OFFSETS->{PURPOSE_CONSENT_ALLOWED} + $id - 1)); | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 21216 | ▶ | sub _safe_is_purpose_legitimate_interest_allowed { | ||||||||||||||||||||||||||
|
Subroutine
_safe_is_purpose_legitimate_interest_allowed: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 145 | 21216 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 21216 | return scalar(is_set($self->{data}, OFFSETS->{PURPOSE_LIT_ALLOWED} + $id - 1)); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 46 | ▶ | sub _safe_is_custom_purpose_consent_allowed { | ||||||||||||||||||||||||||
|
Subroutine
_safe_is_custom_purpose_consent_allowed: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 151 | 46 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 152 | 46 | return scalar(is_set($self->{data}, OFFSETS->{CUSTOM_PURPOSES_CONSENT} + $id - 1)); | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 46 | ▶ | sub _safe_is_custom_purpose_legitimate_interest_allowed { | ||||||||||||||||||||||||||
|
Subroutine
_safe_is_custom_purpose_legitimate_interest_allowed: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 156 | 46 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 46 | return scalar(is_set($self->{data}, $self->{custom_purpose_lit_offset} + $id - 1)); | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 73 | 1; | |||||||||||||||||||||||||||
| 162 | __END__ | ||||||||||||||||||||||||||||