File Coverage

blib/lib/GDPR/IAB/TCFv2/Publisher.pm
Criterion Covered Total %
statement 43 43 100.0
branch 8 12 66.6
condition 1 3 33.3
subroutine 10 10 100.0
pod 4 5 80.0
total 66 73 90.4


line stmt bran cond sub pod time code
1             package GDPR::IAB::TCFv2::Publisher;
2 5     5   2365 use strict;
  5         9  
  5         267  
3 5     5   118 use warnings;
  5         27  
  5         412  
4              
5 5     5   33 use Carp qw;
  5         18  
  5         365  
6              
7 5     5   2881 use GDPR::IAB::TCFv2::PublisherRestrictions;
  5         19  
  5         206  
8 5     5   3258 use GDPR::IAB::TCFv2::PublisherTC;
  5         20  
  5         2761  
9              
10              
11             sub Parse {
12 27     27 0 160 my ( $klass, %args ) = @_;
13              
14 27 50       124 croak "missing 'core_data'" unless defined $args{core_data};
15 27 50       141 croak "missing 'core_data_size'" unless defined $args{core_data_size};
16              
17 27 50       117 croak "missing 'options'" unless defined $args{options};
18 27 50       80 croak "missing 'options.json'" unless defined $args{options}->{json};
19              
20 27         75 my $core_data = $args{core_data};
21 27         47 my $core_data_size = $args{core_data_size};
22              
23             my $restrictions = GDPR::IAB::TCFv2::PublisherRestrictions->Parse(
24             data => $core_data,
25             data_size => $core_data_size,
26             options => $args{options},
27 27         166 );
28              
29 27         107 my $self = {
30             restrictions => $restrictions,
31             publisher_tc => undef,
32             };
33              
34 27 100       112 if ( defined $args{publisher_tc_data} ) {
35 7         18 my $publisher_tc_data = $args{publisher_tc_data};
36             my $publisher_tc_data_size =
37 7   33     35 $args{publisher_tc_data_size} || length($publisher_tc_data);
38              
39             my $publisher_tc = GDPR::IAB::TCFv2::PublisherTC->Parse(
40             data => $publisher_tc_data,
41             data_size => $publisher_tc_data_size,
42             options => $args{options},
43 7         73 );
44              
45 7         19 $self->{publisher_tc} = $publisher_tc;
46             }
47              
48 27         60 bless $self, $klass;
49              
50 27         91 return $self;
51             }
52              
53             sub check_restriction {
54 19     19 1 86 my ( $self, $purpose_id, $restriction_type, $vendor_id ) = @_;
55              
56             return $self->{restrictions}
57 19         106 ->check_restriction( $purpose_id, $restriction_type, $vendor_id );
58             }
59              
60             sub restrictions {
61 8     8 1 26 my ( $self, $vendor_id ) = @_;
62              
63 8         44 return $self->{restrictions}->restrictions($vendor_id);
64             }
65              
66             sub publisher_tc {
67 4     4 1 12 my ( $self, $callback ) = @_;
68              
69 4         13 return $self->{publisher_tc};
70             }
71              
72             sub TO_JSON {
73 18     18 1 32 my $self = shift;
74              
75             my %tags = (
76             restrictions => $self->{restrictions}->TO_JSON,
77 18         152 );
78              
79 18 100       54 if ( defined $self->{publisher_tc} ) {
80 4         8 %tags = ( %tags, %{ $self->{publisher_tc}->TO_JSON } );
  4         16  
81             }
82              
83 18         282 return \%tags;
84             }
85              
86             1;
87             __END__