blib/lib/GDPR/IAB/TCFv2.pm

filter: Statementstmt 100% 14 / 14 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 100% 23 / 23 CC 2 SCAR 2.9
CC
2
Cov
100%
looksLikeIsConsentVersion2
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« blib/lib/GDPR/IAB/TCFv2/Validator/Failure.pm ↑ Summary blib/lib/GDPR/IAB/TCFv2/Constants/Purpose.pm »
1 package GDPR::IAB::TCFv2 0.520;
2  
3 72 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 72 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 72 ▶use GDPR::IAB::TCFv2::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 sub Parse {
9 11435 ▶ shift; # discard $klass — force GDPR::IAB::TCFv2::Parser as leaf class
Subroutine Parse: called CC=1 SCAR=0.0
Pod documented
10 11435 return GDPR::IAB::TCFv2::Parser->Parse(@_);
11 }
12  
13 sub looksLikeIsConsentVersion2 {
14 5 ▶ my $s = shift;
Subroutine looksLikeIsConsentVersion2: called CC=2 SCAR=6.9
Pod documented
15 5 ▶ return unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 1 4 5
16 4 return rindex($s, 'C', 0) == 0;
17 }
18  
19 72 1;
20 __END__
21  
22 =for html <a href="https://cpants.cpanauthors.org/dist/GDPR-IAB-TCFv2"><img src="https://cpants.cpanauthors.org/dist/GDPR-IAB-TCFv2.svg" alt='Kwalitee'/></a>
23  
24 =for html <a href="https://github.com/peczenyj/GDPR-IAB-TCFv2/actions/workflows/linux.yml"><img src="https://github.com/peczenyj/GDPR-IAB-TCFv2/actions/workflows/linux.yml/badge.svg" alt='tests'/></a>
25  
26 =for html <a href="https://github.com/peczenyj/GDPR-IAB-TCFv2/actions/workflows/windows.yml"><img src="https://github.com/peczenyj/GDPR-IAB-TCFv2/actions/workflows/windows.yml/badge.svg" alt='tests'/></a>
27  
28 =for html <a href="https://github.com/peczenyj/GDPR-IAB-TCFv2/actions/workflows/macos.yml"><img src="https://github.com/peczenyj/GDPR-IAB-TCFv2/actions/workflows/macos.yml/badge.svg" alt='tests'/></a>
29  
30 =for html <a href="https://coveralls.io/github/peczenyj/GDPR-IAB-TCFv2?branch=main"><img src="https://coveralls.io/repos/github/peczenyj/GDPR-IAB-TCFv2/badge.svg?branch=main" alt='Coverage Status' /></a>
31  
32 =for html <a href="https://github.com/peczenyj/GDPR-IAB-TCFv2/blob/master/LICENSE"><img src="https://img.shields.io/cpan/l/GDPR-IAB-TCFv2.svg" alt='license'/></a>
33  
34 =for html <a href="https://metacpan.org/dist/GDPR-IAB-TCFv2"><img src="https://img.shields.io/cpan/v/GDPR-IAB-TCFv2.svg" alt='cpan'/></a>
35  
36 =pod
37  
38 =encoding utf8
39  
40 =head1 NAME
41  
42 GDPR::IAB::TCFv2 - TCF v2.3 distribution: parser, validator, CMP-validator, and CLI
43  
44 =head1 PROJECT STATUS
45  
46 C<GDPR::IAB::TCFv2> entered B<maintenance mode> on 2026-05-15 with the
47 v0.512 release. The core parser, validator, and CMP-validator surfaces
48 are considered feature-complete for the IAB TCF v2.3 specification.
49  
50 In maintenance mode the maintainer commits to bug fixes, security
51 fixes, CPAN-tester regression triage, and tracking IAB-spec updates
52 (TCF v2.4 / v3 if and when they ship). Larger feature work -- the
53 remaining roadmap phases (GVL-aware validator, Special Features /
54 Special Purposes, CLI configuration loading), the distribution items
55 (DockerHub automation, Debian package), and the sister-distribution
56 ideas in L</ECOSYSTEM> -- is now tracked as C<help-wanted> issues on
57 GitHub.
58  
59 Patches and PRs from the community are welcome and will continue to be
60 reviewed. See F<TODO> at the repository root for the full
61 help-wanted list and F<CONTRIBUTING> for the patching workflow.
62  
63 =head1 SYNOPSIS
64  
65 This module is the documentation hub for the C<GDPR-IAB-TCFv2>
66 distribution. It exposes a thin C<Parse> delegate that returns an
67 instance of L<GDPR::IAB::TCFv2::Parser>:
68  
69 use feature qw<say>;
70 use GDPR::IAB::TCFv2;
71  
72 my $consent = GDPR::IAB::TCFv2->Parse(
73 'CLcVDxRMWfGmWAVAHCENAXCkAKDAADnAABRgA5mdfCKZuYJez-NQm0TBMYA4oCAAGQYIAAAAAAEAIAEgAA.argAC0gAAAAAAAAAAAA'
74 );
75  
76 say $consent->cmp_id; # 21
77 say $consent->consent_language; # 'EN'
78 say $consent->is_v23 ? 'v2.3' : 'older';
79  
80 For declarative compliance checks, see L<GDPR::IAB::TCFv2::Validator>.
81 For one-liner / shell-use shortcuts, see L</ONE-LINER USAGE> below.
82  
83 =head1 COMPONENTS
84  
85 The distribution ships several pieces. Each link below jumps to the
86 relevant module or section.
87  
88 =head2 L<GDPR::IAB::TCFv2::Parser>
89  
90 The bit-stream parser. C<Parse> returns an instance whose accessors,
91 predicates, and JSON serializer answer every question about a TC
92 string.
93  
94 =head2 L<GDPR::IAB::TCFv2::Validator>
95  
96 Declarative compliance checks. C<< $validator->validate($tc_string) >>
97 asserts a vendor's presence in the string for a given purpose set on a
98 given legal basis.
99  
100 =head2 L<GDPR::IAB::TCFv2::CMPValidator>
101  
102 Validates that a TC string's C<cmp_id> is registered in the IAB's
103 public CMP list (file, JSON, or URL-loaded snapshot).
104  
105 =head2 L<iabtcfv2> (Perl module)
106  
107 A pure-exporter short alias for one-liner and shell use. Provides
108 C<tcf($s)> and C<validator(%opts)> as importable functions. See
109 L</ONE-LINER USAGE>.
110  
111 =head2 C<bin/iabtcfv2> (CLI)
112  
113 Subcommand-style command-line utility. C<iabtcfv2 dump> emits parsed
114 JSON; C<iabtcfv2 validate> runs declarative compliance checks against
115 a vendor identity and a purpose set. See L</COMMAND LINE TOOLS>.
116  
117 =head2 Docker image
118  
119 Pre-built Docker Hub image C<peczenyj/gdpr-iab-tcfv2> wraps the CLI
120 for portable use. See L</DOCKER USAGE>.
121  
122 =head1 INCOMPATIBLE CHANGES
123  
124 =head2 v0.500
125  
126 The parser implementation moved from C<GDPR::IAB::TCFv2> to a new
127 subpackage L<GDPR::IAB::TCFv2::Parser>. The class-method delegate
128 remains: C<< GDPR::IAB::TCFv2->Parse(...) >> still works and is the
129 recommended entry point. However, the returned object is now blessed
130 into C<GDPR::IAB::TCFv2::Parser> rather than C<GDPR::IAB::TCFv2>:
131  
132 my $c = GDPR::IAB::TCFv2->Parse($s);
133  
134 # Before v0.500:
135 ref($c) eq 'GDPR::IAB::TCFv2' # true
136 $c->isa('GDPR::IAB::TCFv2') # true
137  
138 # v0.500 and later:
139 ref($c) eq 'GDPR::IAB::TCFv2::Parser' # true
140 $c->isa('GDPR::IAB::TCFv2::Parser') # true
141 $c->isa('GDPR::IAB::TCFv2') # false
142  
143 Every method call, every JSON output byte, and every CLI behavior is
144 unchanged. The break only affects code that asserts the exact class
145 name via C<ref>, C<isa>, C<blessed>, C<Storable::thaw>, or similar.
146  
147 =head1 CONSTRUCTOR
148  
149 =head2 Parse
150  
151 C<< GDPR::IAB::TCFv2->Parse($tc_string, %opts) >> is the entry point
152 for parsing TCF v2.3 consent strings. It delegates to
153 L<< GDPR::IAB::TCFv2::Parser->Parse|GDPR::IAB::TCFv2::Parser/Parse >>
154 and returns a C<GDPR::IAB::TCFv2::Parser> object; see that page for
155 the full constructor contract (C<strict>, C<prefetch>, C<json>
156 options).
157  
158 =head1 COMMAND LINE TOOLS
159  
160 This distribution includes a unified command line tool to work with TC strings.
161  
162 =head2 iabtcfv2
163  
164 The C<iabtcfv2> utility provides several subcommands for TCF v2.3 strings.
165  
166 =head3 dump
167  
168 Parses TC strings and output them as JSON.
169  
170 # Basic usage
171 iabtcfv2 dump "CLcVDxRMWfGmWAVAHCENAXCkAKDAADnAABRgA5mdfCKZuYJez-NQm0TBMYA4oCAAGQYIAAAAAAEAIAEgAA"
172  
173 # Pretty printed JSON
174 iabtcfv2 dump --pretty "CLcVDxRMWfGmWAVAHCENAXCkAKDAADnAABRgA5mdfCKZuYJez-NQm0TBMYA4oCAAGQYIAAAAAAEAIAEgAA"
175  
176 # Stream multiple strings from STDIN as JSON Lines
177 cat strings.txt | iabtcfv2 dump
178  
179 # Pipe through `jq -s` if you need a single JSON array
180 cat strings.txt | iabtcfv2 dump | jq -s .
181  
182 # Short flags can be bundled (the last bundled short may take a value)
183 iabtcfv2 dump -pi "CLcVDxRMWfGmWAVAHCENAXCkAKDAADnAABRgA5mdfCKZuYJez-NQm0TBMYA4oCAAGQYIAAAAAAEAIAEgAA"
184 iabtcfv2 dump -pv 284 "CLcVDxRMWfGmWAVAHCENAXCkAKDAADnAABRgA5mdfCKZuYJez-NQm0TBMYA4oCAAGQYIAAAAAAEAIAEgAA"
185  
186 # Long options accept the GNU `--opt=value` form
187 iabtcfv2 dump --vendor-id=284 "CLcVDxRMWfGmWAVAHCENAXCkAKDAADnAABRgA5mdfCKZuYJez-NQm0TBMYA4oCAAGQYIAAAAAAEAIAEgAA"
188  
189 =head3 validate
190  
191 Validates TC strings against a vendor identity and a set of declared purpose
192 lists, emitting one JSON record per string (or text lines with C<--text>).
193 The vendor must be allowed for every purpose in C<--consent-purposes> on a
194 consent basis, and for every purpose in C<--legitimate-interest-purposes>
195 on a legitimate-interest basis. Exit code is C<0> when every string is
196 valid, C<1> on any parse or validation failure, C<2> on bad CLI usage.
197  
198 # Basic usage: vendor must appear in the TC string
199 iabtcfv2 validate -v 284 "CLcVDxRMWfGmWAVAHCENAXCkAKDAADnAABRgA5mdfCKZuYJez-NQm0TBMYA4oCAAGQYIAAAAAAEAIAEgAA"
200  
201 # Require vendor 284 to be allowed for purposes 1 and 3 on consent basis
202 iabtcfv2 validate -v 284 -C 1,3 "CLcVDxRMWfGmWAVAHCENAXCkAKDAADnAABRgA5mdfCKZuYJez-NQm0TBMYA4oCAAGQYIAAAAAAEAIAEgAA"
203  
204 # Require both consent (purposes 1, 3) and legitimate interest (purpose 7)
205 iabtcfv2 validate -v 284 -C 1,3 -L 7 "CLcVDxRMWfGmWAVAHCENAXCkAKDAADnAABRgA5mdfCKZuYJez-NQm0TBMYA4oCAAGQYIAAAAAAEAIAEgAA"
206  
207 # Accumulate every failing rule (validate_all) instead of fail-fast
208 iabtcfv2 validate -av 284 -C 1,3 -L 7 "CLcVDxRMWfGmWAVAHCENAXCkAKDAADnAABRgA5mdfCKZuYJez-NQm0TBMYA4oCAAGQYIAAAAAAEAIAEgAA"
209  
210 # Human-readable text output instead of JSON
211 iabtcfv2 validate -tv 284 -C 1,3 "CLcVDxRMWfGmWAVAHCENAXCkAKDAADnAABRgA5mdfCKZuYJez-NQm0TBMYA4oCAAGQYIAAAAAAEAIAEgAA"
212  
213 # Reject TC strings whose policy version is below 5 (TCF v2.3)
214 iabtcfv2 validate -v 284 -m 5 "CLcVDxRMWfGmWAVAHCENAXCkAKDAADnAABRgA5mdfCKZuYJez-NQm0TBMYA4oCAAGQYIAAAAAAEAIAEgAA"
215  
216 # Pipeline-friendly: -q suppresses output, only the exit code is meaningful
217 if iabtcfv2 validate -qv 284 -C 1,3 "$tc_string"; then
218 echo "ok"
219 fi
220  
221 # Stream multiple strings from STDIN as JSON Lines (pipe through
222 # `jq -s` if you need a single JSON array)
223 cat strings.txt | iabtcfv2 validate -v 284 -C 1,3
224  
225 See C<iabtcfv2 --help> or C<perldoc iabtcfv2> for more details.
226  
227 For script-free invocation without C<bin/iabtcfv2>, see
228 L</ONE-LINER USAGE>.
229  
230 =head1 ONE-LINER USAGE
231  
232 The distribution supports C<perl -M...> one-liners directly. The
233 L<iabtcfv2> module exports C<tcf($s)> (which returns a
234 C<GDPR::IAB::TCFv2::Parser>) and C<validator(%opts)> (which returns a
235 C<GDPR::IAB::TCFv2::Validator>), making short scripts even shorter.
236  
237 =head2 Print one field
238  
239 perl -Miabtcfv2 -E 'say tcf(shift)->cmp_id' "$tc"
240  
241 Equivalent long form (no shortcut module):
242  
243 perl -MGDPR::IAB::TCFv2 -E 'say GDPR::IAB::TCFv2->Parse(shift)->cmp_id' "$tc"
244  
245 =head2 Multi-field TSV
246  
247 perl -Miabtcfv2 -E '
248 my $c = tcf(shift);
249 say join("\t", $c->cmp_id, $c->cmp_version, $c->consent_language,
250 $c->vendor_list_version, $c->policy_version)
251 ' "$tc"
252  
253 =head2 Emulate `iabtcfv2 dump --pretty` via core JSON::PP
254  
255 perl -Miabtcfv2 -MJSON::PP -E '
256 say JSON::PP->new->convert_blessed->canonical->pretty
257 ->encode(tcf(shift))
258 ' "$tc"
259  
260 =head2 Stream multiple strings on STDIN
261  
262 perl -Miabtcfv2 -nE '
263 chomp;
264 my $c = eval { tcf($_) } or next;
265 say join("\t", $_, $c->cmp_id)
266 ' < strings.txt
267  
268 =head2 Validate
269  
270 perl -Miabtcfv2 -E '
271 my $r = validator(vendor_id => 284, consent_purpose_ids => [1,3])
272 ->validate(shift);
273 say $r ? "ok" : "fail: $r"
274 ' "$tc"
275  
276 =head1 DOCKER USAGE
277  
278 This tool is also available as a Docker image on Docker Hub.
279  
280 =head2 Basic Usage
281  
282 docker run --rm peczenyj/gdpr-iab-tcfv2 dump "CLcVDxRMWfGmWAVAHCENAXCkAKDAADnAABRgA5mdfCKZuYJez-NQm0TBMYA4oCAAGQYIAAAAAAEAIAEgAA"
283  
284 =head2 Processing Streams (STDIN)
285  
286 To process a stream of strings via pipe:
287  
288 cat strings.txt | docker run -i --rm peczenyj/gdpr-iab-tcfv2 dump
289  
290 To type strings manually:
291  
292 docker run -it --rm peczenyj/gdpr-iab-tcfv2 dump
293  
294 =head1 ACRONYMS
295  
296 L<GDPR|https://gdpr-info.eu/>: General Data Protection Regulation
297  
298 L<IAB|https://iabeurope.eu/about-us/>: Interactive Advertising Bureau
299  
300 L<TCF|https://iabeurope.eu/transparency-consent-framework/>: The Transparency & Consent Framework
301  
302 =head1 FUNCTIONS
303  
304 =head2 looksLikeIsConsentVersion2
305  
306 Will check if a given tc string starts with a literal C<C>.
307  
308 =head1 ECOSYSTEM
309  
310 The following B<sister distributions> are intentionally left as
311 C<help-wanted> ideas rather than shipped from this module. Each one is
312 companion glue for a popular Perl framework and would add a runtime
313 dependency on its host framework, so they belong as separate CPAN
314 distributions rather than features of C<GDPR::IAB::TCFv2> itself.
315  
316 =over 4
317  
318 =item *
319  
320 L<GDPR::IAB::TCFv2::Validator::LIVR>
321  
322 LIVR rule-engine binding for JSON-shaped TC string payloads.
323  
324 =item *
325  
326 L<GDPR::IAB::TCFv2::Validator::TypeTiny>
327  
328 Reusable Type::Tiny constraints (parameterized by purpose / vendor
329 sets) for Moo, Moose, or pure-Perl callers that prefer type-level
330 enforcement.
331  
332 =item *
333  
334 L<Plack::Middleware::GDPR::TCFv2>
335  
336 Plack middleware that decodes a TC string from a request header or
337 cookie, attaches a parsed C<GDPR::IAB::TCFv2> object to C<< $env >>,
338 and short-circuits the response when consent is missing or invalid.
339  
340 =item *
341  
342 L<GDPR::IAB::TCFv2::Validator::Moose>
343  
344 Moose attribute traits and role-based validation for Moose-end-to-end
345 projects.
346  
347 =item *
348  
349 L<GDPR::IAB::TCFv2::Validator::FormValidator>
350  
351 C<Data::FormValidator> profile glue for legacy applications that drive
352 business validation through DFV.
353  
354 =back
355  
356 The C<help-wanted> issues on GitHub track each of these ideas; see
357 L<https://github.com/peczenyj/GDPR-IAB-TCFv2/issues?q=label%3Aecosystem>
358 and F<TODO> for context.
359  
360 =head1 SEE ALSO
361  
362 L<GDPR::IAB::TCFv2::Parser> for the parser API.
363  
364 L<GDPR::IAB::TCFv2::Validator> for declarative compliance checks.
365  
366 L<GDPR::IAB::TCFv2::CMPValidator> for CMP-list validation.
367  
368 L<iabtcfv2> for one-liner / shell-use shortcuts.
369  
370 The original IAB documentation of L<TCF v2|https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md>.
371  
372 =head1 AUTHOR
373  
374 Tiago Peczenyj L<mailto:tiago.peczenyj+cpan@gmail.com>
375  
376 =head1 THANKS
377  
378 Special thanks to L<ikegami|https://metacpan.org/author/IKEGAMI> for the patience on several question about Perl on L<Stack Overflow|https://stackoverflow.com>.
379  
380 =head1 BUGS
381  
382 Please report any bugs or feature requests to L<https://github.com/peczenyj/GDPR-IAB-TCFv2/issues>.
383  
384 =head1 LICENSE AND COPYRIGHT
385  
386 Copyright 2023-2026 Tiago Peczenyj
387  
388 This program is free software; you can redistribute it and/or modify it
389 under the terms of either: the GNU General Public License as published
390 by the Free Software Foundation; or the Artistic License.
391  
392 See L<http://dev.perl.org/licenses/> for more information.
393  
394 =head1 DISCLAIMER
395  
396 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
397 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
398 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
399 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
400 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
401 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
402 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
403 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
404 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
405 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
406  
407 =cut
« blib/lib/GDPR/IAB/TCFv2/Validator/Failure.pm ↑ Summary blib/lib/GDPR/IAB/TCFv2/Constants/Purpose.pm »