blib/lib/GDPR/IAB/TCFv2/PublisherRestrictions.pm

filter: Statementstmt 100% 79 / 79 Branchbran 70.0% 21 / 30 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 10 / 10 Podpod 60.0% 3 / 5 totaltotal 91.7% 122 / 133 CC 25 SCAR 18.1
CC
25
Cov
92%
Parse
9.3
TO_JSON
8.0
check_restriction
5.2
CRAP 6.1
« blib/lib/GDPR/IAB/TCFv2/BitField.pm ↑ Summary blib/lib/GDPR/IAB/TCFv2/Parser.pm »
1 package GDPR::IAB::TCFv2::PublisherRestrictions 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<
Subroutine BEGIN: called CC=1 SCAR=0.0
8 get_uint2
9 get_uint6
10 get_uint12
11 73 >;
12  
13 73 ▶use constant ASSUMED_MAX_VENDOR_ID => 0x7FFF; # 32767 or (1 << 15) -1
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 11418 ▶sub Parse {
Subroutine Parse: called CC=9 SCAR=22.3
Pod undocumented
17 11418 my ($klass, %args) = @_;
18  
19 11418 ▶ croak "missing 'data'" unless defined $args{data};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"data"} 0 11418 11418
20 11418 ▶ croak "missing 'data_size'" unless defined $args{data_size};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"data_size"} 0 11418 11418
21 11418 ▶ croak "missing 'offset'" unless defined $args{offset};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"offset"} 0 11418 11418
22  
23 11418 ▶ croak "missing 'options'" unless defined $args{options};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"options"} 0 11418 11418
24 11418 ▶ croak "missing 'options.json'" unless defined $args{options}->{json};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"options"}{"json"} 0 11418 11418
25  
26 11418 my $data = $args{data};
27 11418 my $data_size = $args{data_size};
28 11418 my $offset = $args{offset};
29 11418 my $max_id = ASSUMED_MAX_VENDOR_ID;
30 11418 my $options = $args{options};
31  
32 11418 ▶ return if $offset + 12 > $data_size;
Branch: 1 branch
BranchTrueFalseTotal
if $offset + 12 > $data_size 0 11418 11418
33  
34 11418 my ($num_restrictions, $next_offset) = get_uint12($data, $offset);
35  
36 11418 my %restrictions;
37  
38 11418 for (1 .. $num_restrictions) {
39 23994 my ($purpose_id, $restriction_type, $vendor_restrictions);
40  
41 23994 ($purpose_id, $next_offset) = get_uint6($data, $next_offset);
42  
43 23994 ($restriction_type, $next_offset) = get_uint2($data, $next_offset);
44  
45 23994 ($vendor_restrictions, $next_offset) = GDPR::IAB::TCFv2::RangeSection->Parse(
46 data => $data,
47 data_size => $data_size,
48 offset => $next_offset,
49 max_id => ASSUMED_MAX_VENDOR_ID,
50 options => $options,
51 );
52  
53 23994 ▶ $restrictions{$purpose_id} ||= {};
Condition100%2/2
$restrictions{$purpose_id} ||= {}
l!l
173022264
MC/DC100%1/1
$restrictions{$purpose_id} ||= {}
$restrictions{$purpose_id}
Truth table100%2/2
A
A= $restrictions{$purpose_id}
Aresult
11
00
54  
55 23994 $restrictions{$purpose_id}->{$restriction_type} = $vendor_restrictions;
56 }
57  
58 11418 my $self = {restrictions => \%restrictions,};
59  
60 11418 bless $self, $klass;
61  
62 11418 return $self;
63 }
64  
65 2 ▶sub has_restrictions {
Subroutine has_restrictions: called CC=2 SCAR=6.9
Pod undocumented
66 2 my $self = shift;
67 2 ▶ return scalar keys %{$self->{restrictions}} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %{$$self{'restrictions'};} ? : 1 1 2
68 }
69  
70 8 ▶sub restrictions {
Subroutine restrictions: called CC=5 SCAR=16.1
Pod documented
71 8 my ($self, $vendor_id) = @_;
72  
73 8 my %restrictions;
74  
75 8 foreach my $purpose_id (keys %{$self->{restrictions}}) {
76 18 foreach my $restriction_type (keys %{$self->{restrictions}->{$purpose_id}}) {
77 16 ▶ if ($self->{restrictions}->{$purpose_id}->{$restriction_type}->contains($vendor_id)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"restrictions"}{$purpose_id}{$restriction_type}->contains($vendor_id)) 8 8 16
78 8 ▶ $restrictions{$purpose_id} ||= {};
Condition100%2/2
$restrictions{$purpose_id} ||= {}
l!l
35
MC/DC100%1/1
$restrictions{$purpose_id} ||= {}
$restrictions{$purpose_id}
Truth table100%2/2
A
A= $restrictions{$purpose_id}
Aresult
11
00
79 8 $restrictions{$purpose_id}->{$restriction_type} = 1;
80 }
81 }
82 }
83  
84 8 return \%restrictions;
85 }
86  
87 19319 ▶sub check_restriction {
Subroutine check_restriction: called CC=5 SCAR=16.4
Pod documented
88 19319 my $self = shift;
89  
90 19319 my $nargs = scalar(@_);
91  
92 19319 ▶ croak "missing arguments: purpose id, restriction type and vendor id" if $nargs == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $nargs == 0 0 19319 19319
93 19319 ▶ croak "missing arguments: restriction type and vendor id" if $nargs == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $nargs == 1 0 19319 19319
94 19319 ▶ croak "missing argument: vendor id" if $nargs == 2;
Branch: 1 branch
BranchTrueFalseTotal
if $nargs == 2 0 19319 19319
95  
96 19319 my ($purpose_id, $restriction_type, $vendor_id) = @_;
97  
98 19319 ▶ return 0 unless exists $self->{restrictions}->{$purpose_id}->{$restriction_type};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"restrictions"}{$purpose_id}{$restriction_type} 18126 1193 19319
99  
100 1193 return $self->{restrictions}->{$purpose_id}->{$restriction_type}->contains($vendor_id);
101 }
102  
103 1064 ▶sub TO_JSON {
Subroutine TO_JSON: called CC=8 SCAR=20.8
Pod documented
104 1064 my ($self, $filter_id) = @_;
105  
106 1064 my %publisher_restrictions;
107  
108 1064 foreach my $purpose_id (sort { $a <=> $b } keys %{$self->{restrictions}}) {
109 2209 my $restriction_map = $self->{restrictions}->{$purpose_id};
110  
111 2209 my %purpose_restrictions;
112  
113 2209 foreach my $restriction_type (keys %{$restriction_map}) {
114 2182 ▶ if (defined $filter_id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $filter_id) { } 4 2178 2182
115 4 ▶ if ($restriction_map->{$restriction_type}->contains($filter_id)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($restriction_map->{$restriction_type}->contains($filter_id)) 1 3 4
116 1 $purpose_restrictions{$filter_id} = int($restriction_type);
117 }
118 }
119 else {
120 2178 my $vendors = $restriction_map->{$restriction_type}->all;
121  
122 2178 foreach my $vendor (@{$vendors}) {
123 2239882 $purpose_restrictions{$vendor} = int($restriction_type);
124 }
125 }
126 }
127  
128 # If not filtering, or if we found the filtered vendor, add the purpose
129 2209 ▶ if (!defined $filter_id || scalar keys %purpose_restrictions) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $filter_id or scalar keys %purpose_restrictions) 2022 187 2209
Condition100%2/2
not defined $filter_id or scalar keys %purpose_restrictions
l!l
2021188
MC/DC100%1/1
not defined $filter_id or scalar keys %purpose_restrictions
not defined $filter_id
Truth table100%2/2
not(A)
A= not defined $filter_id
Aresult
11
00
130 2022 $publisher_restrictions{$purpose_id} = \%purpose_restrictions;
131 }
132 }
133  
134 1064 return \%publisher_restrictions;
135 }
136  
137  
138 73 1;
139 __END__
« blib/lib/GDPR/IAB/TCFv2/BitField.pm ↑ Summary blib/lib/GDPR/IAB/TCFv2/Parser.pm »