diff --git a/lib/GDPR/IAB/TCFv2.pm b/lib/GDPR/IAB/TCFv2.pm index b7f0511..5e73989 100644 --- a/lib/GDPR/IAB/TCFv2.pm +++ b/lib/GDPR/IAB/TCFv2.pm @@ -333,10 +333,22 @@ sub vendor_legitimate_interest { } sub check_publisher_restriction { - my ( $self, $purpose_id, $restrict_type, $vendor ) = @_; + my $self = shift; + + my ( $purpose_id, $restriction_type, $vendor_id ); + + if ( scalar(@_) == 6 ) { + my (%opts) = @_; + + $purpose_id = $opts{purpose_id}; + $restriction_type = $opts{restriction_type}; + $vendor_id = $opts{vendor_id}; + } + + ( $purpose_id, $restriction_type, $vendor_id ) = @_; return $self->{publisher} - ->check_restriction( $purpose_id, $restrict_type, $vendor ); + ->check_restriction( $purpose_id, $restriction_type, $vendor_id ); } sub publisher_tc { @@ -501,10 +513,10 @@ sub _parse_vendor_section { # parse vendor legitimate interest - my $pub_restrict_offset = + my $pub_restriction_offset = $self->_parse_vendor_legitimate_interests($legitimate_interest_offset); - return $pub_restrict_offset; + return $pub_restriction_offset; } sub _parse_vendor_consents { @@ -523,22 +535,22 @@ sub _parse_vendor_consents { sub _parse_vendor_legitimate_interests { my ( $self, $legitimate_interest_offset ) = @_; - my ( $vendor_legitimate_interests, $pub_restrict_offset ) = + my ( $vendor_legitimate_interests, $pub_restriction_offset ) = $self->_parse_bitfield_or_range( $legitimate_interest_offset, ); $self->{vendor_legitimate_interests} = $vendor_legitimate_interests; - return $pub_restrict_offset; + return $pub_restriction_offset; } sub _parse_publisher_section { - my ( $self, $pub_restrict_offset ) = @_; + my ( $self, $pub_restriction_offset ) = @_; # parse public restrictions - my $core_data = substr( $self->{core_data}, $pub_restrict_offset ); + my $core_data = substr( $self->{core_data}, $pub_restriction_offset ); my $core_data_size = length( $self->{core_data} ); my $publisher = GDPR::IAB::TCFv2::Publisher->Parse( @@ -959,6 +971,13 @@ It true, there is a publisher restriction of certain type, for a given purpose i # with restriction type 0 'Purpose Flatly Not Allowed by Publisher' my $ok = $instance->check_publisher_restriction(1, 0, 284); +or + + my $ok = $instance->check_publisher_restriction( + purpose_id => 1, + restriction_type => 0, + vendor_id => 284); + Version 2.0 of the Framework introduced the ability for publishers to signal restrictions on how vendors may process personal data. Restrictions can be of two types: =over diff --git a/lib/GDPR/IAB/TCFv2/PublisherRestrictions.pm b/lib/GDPR/IAB/TCFv2/PublisherRestrictions.pm index f77826f..bdfd888 100644 --- a/lib/GDPR/IAB/TCFv2/PublisherRestrictions.pm +++ b/lib/GDPR/IAB/TCFv2/PublisherRestrictions.pm @@ -67,13 +67,22 @@ sub Parse { } sub check_restriction { - my ( $self, $purpose_id, $restrict_type, $vendor ) = @_; + my $self = shift; + + my $nargs = scalar(@_); + + croak "missing arguments: purpose id, restriction type and vendor id" + if $nargs == 0; + croak "missing arguments: restriction type and vendor id" if $nargs == 1; + croak "missing argument: vendor id" if $nargs == 2; + + my ( $purpose_id, $restriction_type, $vendor_id ) = @_; return 0 - unless exists $self->{restrictions}->{$purpose_id}->{$restrict_type}; + unless exists $self->{restrictions}->{$purpose_id}->{$restriction_type}; - return $self->{restrictions}->{$purpose_id}->{$restrict_type} - ->contains($vendor); + return $self->{restrictions}->{$purpose_id}->{$restriction_type} + ->contains($vendor_id); } sub TO_JSON { @@ -86,11 +95,11 @@ sub TO_JSON { my %purpose_restrictions; - foreach my $restrict_type ( keys %{$restriction_map} ) { - my $vendors = $restriction_map->{$restrict_type}->all; + foreach my $restriction_type ( keys %{$restriction_map} ) { + my $vendors = $restriction_map->{$restriction_type}->all; foreach my $vendor ( @{$vendors} ) { - $purpose_restrictions{$vendor} = int($restrict_type); + $purpose_restrictions{$vendor} = int($restriction_type); } } @@ -147,7 +156,7 @@ Return true for a given combination of purpose id, restriction type and vendor my $purpose_id = 1; my $restriction_type = 0; my $vendor = 284; - $ok = $range->check_restriction($purpose_id, $restriction_type, $vendor); + my $ok = $range->check_restriction($purpose_id, $restriction_type, $vendor); =head2 TO_JSON diff --git a/t/01-parse.t b/t/01-parse.t index f938ee6..47dd4e3 100644 --- a/t/01-parse.t +++ b/t/01-parse.t @@ -154,7 +154,11 @@ subtest "bitfield" => sub { }; ok !$consent->check_publisher_restriction( 1, 0, 284 ), - "should have no publisher restriction to vendor 284 regarding purpose id 1 of type 0 'Purpose Flatly Not Allowed by Publisher'"; + "should have no publisher restriction to vendor 284 regarding purpose id 1 of type 0 'Purpose Flatly Not Allowed by Publisher' when called with positional parameters"; + + ok !$consent->check_publisher_restriction( purpose_id => 1, + restriction_type => 0, vendor_id => 284 ), + "should have no publisher restriction to vendor 284 regarding purpose id 1 of type 0 'Purpose Flatly Not Allowed by Publisher' when called with named parameters"; my $publisher_tc = $consent->publisher_tc;