Skip to content

Commit

Permalink
fix issue #25
Browse files Browse the repository at this point in the history
  • Loading branch information
peczenyj committed Dec 17, 2023
1 parent 42c39e2 commit 6565601
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 36 deletions.
5 changes: 4 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
- refactor constants, stop use dualvars
- validate parameters on method check_publisher_restriction
- add method publisher_restrictions by vendor id
- add prefetch option to cache vendor ids when the consent string is range based
- add prefetch option to cache vendor ids when the consent string is range based.
It is 2x faster check consent on a prefetched vendor than a regular one if the consent is range based.
Without increase the Parsing time.

0.100
- parse publisher tc section if available
Expand Down
55 changes: 34 additions & 21 deletions lib/GDPR/IAB/TCFv2/Constants/Purpose.pm
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
package GDPR::IAB::TCFv2::Constants::Purpose;
use strict;
use warnings;
use Scalar::Util qw<dualvar>;

require Exporter;
use base qw<Exporter>;

use constant {
InfoStorageAccess =>
dualvar( 1, "Store and/or access information on a device" ),
BasicAdserving => dualvar( 2, "Use limited data to select advertising" ),
PersonalizationProfile =>
dualvar( 3, "Create profiles for personalised advertising" ),
InfoStorageAccess => 1,
BasicAdserving => 2,
PersonalizationProfile => 3,
PersonalizationSelection => 4,
ContentProfile => 5,
ContentSelection => 6,
AdPerformance => 7,
ContentPerformance => 8,
MarketResearch => 9,
DevelopImprove => 10,
SelectContent => 11,
};

use constant PurposeDescription => {
InfoStorageAccess => "Store and/or access information on a device",
BasicAdserving => "Use limited data to select advertising",
PersonalizationProfile => "Create profiles for personalised advertising",
PersonalizationSelection =>
dualvar( 4, "Use profiles to select personalised advertising" ),
ContentProfile => dualvar( 5, "Create profiles to personalise content" ),
ContentSelection =>
dualvar( 6, "Use profiles to select personalised content" ),
AdPerformance => dualvar( 7, "Measure advertising performance" ),
ContentPerformance => dualvar( 8, "Measure content performance" ),
MarketResearch => dualvar(
9,
"Understand audiences through statistics or combinations of data from different sources"
),
DevelopImprove => dualvar( 10, "Develop and improve services" ),
SelectContent => dualvar( 11, "Use limited data to select content" ),
"Use profiles to select personalised advertising",
ContentProfile => "Create profiles to personalise content",
ContentSelection => "Use profiles to select personalised content",
AdPerformance => "Measure advertising performance",
ContentPerformance => "Measure content performance",
MarketResearch =>
"Understand audiences through statistics or combinations of data from different sources",
DevelopImprove => "Develop and improve services",
SelectContent => "Use limited data to select content",
};

our @EXPORT_OK = qw<
Expand All @@ -39,6 +47,7 @@ our @EXPORT_OK = qw<
MarketResearch
DevelopImprove
SelectContent
PurposeDescription
>;
our %EXPORT_TAGS = ( all => \@EXPORT_OK );

Expand All @@ -58,15 +67,15 @@ GDPR::IAB::TCFv2::Constants::Purpose - TCF v2.2 purposes
use feature 'say';
say "Purpose id is ". (0+InfoStorageAccess), ", and it means " . InfoStorageAccess;
say "Purpose id is ", InfoStorageAccess , ", and it means " . PurposeDescription->{InfoStorageAccess};
# Output:
# Purpose id is 1, and it means Store and/or access information on a device
=head1 CONSTANTS
All constants are C<dualvar> (see L<Scalar::Util>).
All constants are integers.
Returns a scalar that has the C<id> in a numeric context and the C<description> in a string context.
To find the description of a given id you can use the hashref L</PurposeDescription>
=head2 InfoStorageAccess
Expand Down Expand Up @@ -289,3 +298,7 @@ A travel magazine has published an article on its website about the new online c
A sports news mobile app has started a new section of articles covering the most recent football games. Each article includes videos hosted by a separate streaming platform showcasing the highlights of each match. If you fast-forward a video, this information may be used to select a shorter video to play next.
=back
=head2 PurposeDescription
Returns a hashref with a mapping between all purpose ids and their description.
24 changes: 17 additions & 7 deletions lib/GDPR/IAB/TCFv2/Constants/RestrictionType.pm
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package GDPR::IAB::TCFv2::Constants::RestrictionType;
use strict;
use warnings;
use Scalar::Util qw<dualvar>;

require Exporter;
use base qw<Exporter>;

use constant {
NotAllowed => dualvar( 0, "Purpose Flatly Not Allowed by Publisher" ),
RequireConsent => dualvar( 1, "Require Consent" ),
RequireLegitimateInterest => dualvar( 2, "Require Legitimate Interest" ),
NotAllowed => 0,
RequireConsent => 1,
RequireLegitimateInterest => 2,
};

use constant RestrictionTypeDescription => {
NotAllowed => "Purpose Flatly Not Allowed by Publisher",
RequireConsent =>, "Require Consent",
RequireLegitimateInterest => "Require Legitimate Interest",
};

our @EXPORT_OK = qw<
NotAllowed
RequireConsent
RequireLegitimateInterest
RestrictionTypeDescription
>;

our %EXPORT_TAGS = ( all => \@EXPORT_OK );
Expand All @@ -37,15 +43,15 @@ GDPR::IAB::TCFv2::Constants::RestrictionType - TCF v2.2 publisher restriction ty
use feature 'say';
say "Restriction type id is ". (0+NotAllowed), ", and it means " . NotAllowed;
say "Restriction type id is ", NotAllowed, ", and it means " , RestrictionTypeDescription->{NotAllowed};
# Output:
# Restriction type id is 0, and it means Purpose Flatly Not Allowed by Publisher
=head1 CONSTANTS
All constants are C<dualvar> (see L<Scalar::Util>).
All constants are integers.
Returns a scalar that has the C<id> in a numeric context and the C<description> in a string context.
To find the description of a given id you can use the hashref L</RestrictionTypeDescription>
=head2 NotAllowed
Expand All @@ -59,6 +65,10 @@ Restriction type id 1: Require Consent (if Vendor has declared the Purpose IDs l
Restriction type id 2: Require Legitimate Interest (if Vendor has declared the Purpose IDs legal basis as Consent and flexible)
=head2 RestrictionTypeDescription
Returns a hashref with a mapping between all restriction types and their description.
=head1 NOTE
Vendors must always respect a 0 (Not Allowed) regardless of whether or not they have not declared that Purpose to be "flexible". Values 1 and 2 are in accordance with a vendor's declared flexibility. Eg. if a vendor has Purpose 2 declared as Legitimate Interest but also declares that Purpose as flexible and this field is set to 1, they must then check for the "consent" signal in the VendorConsents section to make a determination on whether they have the legal basis for processing user personal data under that Purpose.
Expand Down
22 changes: 15 additions & 7 deletions lib/GDPR/IAB/TCFv2/Constants/SpecialFeature.pm
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package GDPR::IAB::TCFv2::Constants::SpecialFeature;
use strict;
use warnings;
use Scalar::Util qw<dualvar>;

require Exporter;
use base qw<Exporter>;

use constant {
Geolocation => dualvar( 1, "Use precise geolocation data" ),
DeviceScan =>
dualvar( 2, "Actively scan device characteristics for identification" )
Geolocation => 1,
DeviceScan => 2
};

use constant SpecialFeatureDescription => {
Geolocation => "Use precise geolocation data",
DeviceScan => "Actively scan device characteristics for identification"
};

our @EXPORT_OK = qw<
Geolocation
DeviceScan
SpecialFeatureDescription
>;

our %EXPORT_TAGS = ( all => \@EXPORT_OK );
Expand All @@ -36,15 +40,15 @@ GDPR::IAB::TCFv2::Constants::SpecialFeature - TCF v2.2 special features
use feature 'say';
say "Special feature id is ". (0+Geolocation), ", and it means " . Geolocation;
say "Special feature id is ", Geolocation, ", and it means " , SpecialFeatureDescription->{Geolocation};
# Output:
# Special feature id is 1, and it means Use precise geolocation data
=head1 CONSTANTS
All constants are C<dualvar> (see L<Scalar::Util>).
All constants are integers.
Returns a scalar that has the C<id> in a numeric context and the C<description> in a string context.
To find the description of a given id you can use the hashref L</SpecialFeatureDescription>.
=head2 Geolocation
Expand All @@ -58,3 +62,7 @@ Special feature id 2: Actively scan device characteristics for identification
With your acceptance, certain characteristics specific to your device might be requested and used to distinguish it from other devices (such as the installed fonts or plugins, the resolution of your screen) in support of the purposes explained in this notice.
"description":
=head2 SpecialFeatureDescription
Returns a hashref with a mapping between all restriction types and their description.

0 comments on commit 6565601

Please sign in to comment.