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

filter: Statementstmt 100% 51 / 51 Branchbran 59.0% 13 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 66.6% 4 / 6 totaltotal 87.7% 79 / 90 CC 12 SCAR 12.6
CC
12
Cov
88%
Parse
7.2
TO_JSON
3.0
has_restrictions
2.1
CRAP 3.5
« blib/lib/GDPR/IAB/TCFv2/PublisherTC.pm ↑ Summary blib/lib/GDPR/IAB/TCFv2/Validator/Reason.pm »
1 package GDPR::IAB::TCFv2::Publisher 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::PublisherRestrictions;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 73 ▶use GDPR::IAB::TCFv2::PublisherTC;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 11418 ▶sub Parse {
Subroutine Parse: called CC=7 SCAR=19.8
Pod undocumented
11 11418 my ($klass, %args) = @_;
12  
13 11418 ▶ croak "missing 'core_data'" unless defined $args{core_data};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"core_data"} 0 11418 11418
14 11418 ▶ croak "missing 'core_data_size'" unless defined $args{core_data_size};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"core_data_size"} 0 11418 11418
15 11418 ▶ croak "missing 'offset'" unless defined $args{offset};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"offset"} 0 11418 11418
16  
17 11418 ▶ croak "missing 'options'" unless defined $args{options};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"options"} 0 11418 11418
18 11418 ▶ croak "missing 'options.json'" unless defined $args{options}->{json};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"options"}{"json"} 0 11418 11418
19  
20 11418 my $core_data = $args{core_data};
21 11418 my $core_data_size = $args{core_data_size}; # size in bytes
22 11418 my $offset = $args{offset};
23  
24 my $restrictions = GDPR::IAB::TCFv2::PublisherRestrictions->Parse(
25 data => $core_data,
26 data_size => $core_data_size << 3, # convert to bits
27 offset => $offset,
28 options => $args{options},
29 11418 );
30  
31 11418 my $self = {restrictions => $restrictions, publisher_tc => undef,};
32  
33 11418 ▶ if (defined $args{publisher_tc_data}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"publisher_tc_data"}) 9679 1739 11418
34 9679 my $publisher_tc_data = $args{publisher_tc_data};
35 9679 my $publisher_tc_data_bits = length($publisher_tc_data) << 3;
36  
37 my $publisher_tc = GDPR::IAB::TCFv2::PublisherTC->Parse(
38 data => $publisher_tc_data,
39 data_size => $publisher_tc_data_bits,
40 options => $args{options},
41 9679 );
42  
43 9679 $self->{publisher_tc} = $publisher_tc;
44 }
45  
46 11418 bless $self, $klass;
47  
48 11418 return $self;
49 }
50  
51 19319 ▶sub check_restriction {
Subroutine check_restriction: called CC=2 SCAR=7.1
Pod documented
52 19319 my ($self, $purpose_id, $restriction_type, $vendor_id) = @_;
53  
54 19319 ▶ return 0 unless defined $self->{restrictions};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"restrictions"} 0 19319 19319
55  
56 19319 return $self->{restrictions}->check_restriction($purpose_id, $restriction_type, $vendor_id);
57 }
58  
59 8 ▶sub restrictions {
Subroutine restrictions: called CC=2 SCAR=7.1
Pod documented
60 8 my ($self, $vendor_id) = @_;
61  
62 8 ▶ return {} unless defined $self->{restrictions};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"restrictions"} 0 8 8
63  
64 8 return $self->{restrictions}->restrictions($vendor_id);
65 }
66  
67 2 ▶sub has_restrictions {
Subroutine has_restrictions: called CC=2 SCAR=7.2
Pod undocumented
68 2 my $self = shift;
69  
70 2 ▶ return defined $self->{restrictions} ? $self->{restrictions}->has_restrictions : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'restrictions'} ? : 2 0 2
71 }
72  
73 4 ▶sub publisher_tc {
Subroutine publisher_tc: called CC=1 SCAR=0.0
Pod documented
74 4 my ($self) = @_;
75  
76 4 return $self->{publisher_tc};
77 }
78  
79 1064 ▶sub TO_JSON {
Subroutine TO_JSON: called CC=3 SCAR=11.0
Pod documented
80 1064 my ($self, $filter_id) = @_;
81  
82 1064 my %tags;
83  
84 1064 ▶ if (defined $self->{restrictions}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"restrictions"}) 1064 0 1064
85 1064 $tags{restrictions} = $self->{restrictions}->TO_JSON($filter_id);
86 }
87  
88 1064 ▶ if (defined $self->{publisher_tc}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"publisher_tc"}) 882 182 1064
89 882 %tags = (%tags, %{$self->{publisher_tc}->TO_JSON});
90 }
91  
92 1064 return \%tags;
93 }
94  
95  
96 73 1;
97 __END__
« blib/lib/GDPR/IAB/TCFv2/PublisherTC.pm ↑ Summary blib/lib/GDPR/IAB/TCFv2/Validator/Reason.pm »