bin/iabtcfv2

filter: Statementstmt 91.9% 264 / 287 Branchbran 69.4% 107 / 154 Conditioncond 46.6% 7 / 15 MC/DCmcdc 10.0% 1 / 10 Subroutinesub 96.0% 24 / 25 Podpod n/a totaltotal 82.0% 403 / 491 CC 80 SCAR 25.9
CC
80
Cov
83%
run_validate
33.1
_validate_string
19.5
run_dump
10.1
CRAP 13.3
« blib/lib/GDPR/IAB/TCFv2/RangeSection.pm ↑ Summary blib/lib/GDPR/IAB/TCFv2/Validator.pm »
1 #!/usr/bin/env perl
2  
3 55 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 55 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 55 ▶use Getopt::Long qw(GetOptionsFromArray :config pass_through require_order bundling);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 55 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 55 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 55 ▶eval { require JSON; 1 } or require JSON::PP;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require JSON; 1 } } or require JSON::PP 0 55 55
10 55 ▶use GDPR::IAB::TCFv2;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 55 ▶use constant {EXIT_SUCCESS => 0, EXIT_PARSE_ERROR => 1,};
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 55 my $script_path = File::Spec->rel2abs($0);
15  
16 sub _json_false {
17 13 ▶ return JSON->can('false') ? JSON->false() : JSON::PP::false();
Subroutine _json_false: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
'JSON'->can('false') ? : 13 0 13
18 }
19  
20 sub _json_true {
21 8 ▶ return JSON->can('true') ? JSON->true() : JSON::PP::true();
Subroutine _json_true: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
'JSON'->can('true') ? : 8 0 8
22 }
23  
24 sub _clean_error {
25 9 ▶ my $err = shift;
Subroutine _clean_error: called CC=3 SCAR=11.2
26 9 ▶ return "" unless defined $err;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $err 0 9 9
27  
28 # If it's a reference (e.g. an exception object), return it as-is
29 9 ▶ return $err if ref $err;
Branch: 1 branch
BranchTrueFalseTotal
if ref $err 0 9 9
30  
31 # Strip Perl/Carp's automatic " at ... line ..." location suffix
32 9 $err =~ s/ at \S+ line \d+\.?\n?\z//;
33 9 chomp $err;
34 9 return $err;
35 }
36  
37 # Subcommand registry: drives dispatch, the short-help summaries, and
38 # the unknown-subcommand error message. New subcommands plug in here
39 # with no other code edits.
40 #
41 # Each `common` row is [short, long, value-placeholder, description].
42 # Rows appear in the short help in the order listed. Niche flags (e.g.
43 # --cmp-validator-timeout) are intentionally omitted from `common` and
44 # documented only in the full POD.
45 55 my %SUBCOMMANDS = (
46 dump => {
47 summary => 'Parse TC strings and emit JSON.',
48 synopsis => 'iabtcfv2 dump [options] [tc_strings...]',
49 runner => \&run_dump,
50 common => [
51 ['-p', '--pretty', '', 'Indent JSON output'],
52 ['-c', '--compact', '', 'Compact JSON (lists of IDs instead of boolean maps)'],
53 ['-v', '--vendor-id', '<ID>', 'Filter output to a single vendor ID'],
54 ['-s', '--strict-legal-basis', '', 'Strict spec validation in the underlying parser'],
55 ['-i', '--ignore-errors', '', 'Skip parse-error JSON output (still bumps exit code)'],
56 ['-f', '--fail-fast', '', 'Exit immediately on the first parse error'],
57 ['-e', '--errors-to-stderr', '', 'Send error JSON objects to STDERR'],
58 ['-w', '--enable-warnings', '', 'Emit human-readable warnings on STDERR'],
59 ['-q', '--quiet', '', 'Suppress STDOUT (exit code only)'],
60 ],
61 },
62 validate => {
63 summary => 'Validate TC strings against a vendor identity and a purpose policy.',
64 synopsis => 'iabtcfv2 validate -v <id> [options] [tc_strings...]',
65 runner => \&run_validate,
66 common => [
67 ['-v', '--vendor-id', '<ID>', 'REQUIRED: vendor ID to validate'],
68 ['-C', '--consent-purposes', '<LIST>', 'Purpose IDs that must be allowed on consent (e.g. 1,3)'],
69 ['-L', '--legitimate-interest-purposes', '<LIST>', 'Purpose IDs that must be allowed on legitimate interest'],
70 ['-F', '--flexible-purposes', '<LIST>', 'Purpose IDs declared flexible by the vendor'],
71 ['-d', '--verify-disclosed-vendors', '', 'Require vendor in the Disclosed Vendors segment'],
72 ['-s', '--strict-legal-basis', '', 'Strict spec validation in the underlying parser'],
73 ['-m', '--min-tcf-policy-version', '<N>', 'Reject TC strings whose policy version is below N'],
74 ['', '--cmp-validator', '<PATH-OR-URL>', 'Validate cmp_id against an IAB CMP registry snapshot'],
75 ['-a', '--all', '', 'Accumulate every failing rule (reasons array)'],
76 ['-p', '--pretty', '', 'Indent JSON output'],
77 ['-t', '--text', '', 'Human-readable text output instead of JSON'],
78 ['-i', '--ignore-errors', '', 'Skip parse-error JSON output'],
79 ['-f', '--fail-fast', '', 'Exit on first parse error or invalid TC string'],
80 ['-e', '--errors-to-stderr', '', 'Send error JSON objects to STDERR'],
81 ['-w', '--enable-warnings', '', 'Emit human-readable warnings on STDERR'],
82 ['-q', '--quiet', '', 'Suppress STDOUT (exit code only)'],
83 ],
84 },
85 );
86  
87 55 my %global_opts;
88 GetOptions(
89 'help' => \$global_opts{full_help},
90 'h' => \$global_opts{short_help},
91 'man' => \$global_opts{man},
92 'version|V' => \$global_opts{version},
93 55 ▶) or pod2usage(-input => $script_path, -exitval => 2, -verbose => 0);
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("help", \$global_opts{"full_help"}, "h", \$global_opts{"short_help"}, "man", \$global_opts{"man"}, "version|V", \$global_opts{"version"}) or pod2usage("-input", $script_path, "-exitval", 2, "-verbose", 0) 0 55 55
94  
95 55 ▶if ($global_opts{version}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($global_opts{"version"}) 2 53 55
96 2 print "iabtcfv2 version $GDPR::IAB::TCFv2::VERSION\n";
97 2 exit EXIT_SUCCESS;
98 }
99  
100 53 ▶if ($global_opts{short_help}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($global_opts{"short_help"}) 1 52 53
101 1 _show_short_help($ARGV[0]);
102 }
103 52 ▶if ($global_opts{full_help}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($global_opts{"full_help"}) 1 51 52
104 1 _show_help($ARGV[0]);
105 }
106 51 ▶pod2usage(-input => $script_path, -exitval => 1, -verbose => 2) if $global_opts{man};
Branch: 1 branch
BranchTrueFalseTotal
if $global_opts{"man"} 0 51 51
107  
108 51 my $subcommand = shift @ARGV;
109  
110 # Bare invocation: brief overview, exit 1 (mirrors `--help` behavior).
111 51 ▶_show_short_help() unless defined $subcommand;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $subcommand 1 50 51
112  
113 # `iabtcfv2 help [<sub>]` keeps showing the full POD, same as before.
114 50 ▶if ($subcommand eq 'help') {
Branch: 1 branch
BranchTrueFalseTotal
if ($subcommand eq "help") 1 49 50
115 1 _show_help(shift @ARGV);
116 }
117  
118 49 my $entry = $SUBCOMMANDS{$subcommand};
119 49 ▶_unknown_subcommand($subcommand) unless $entry;
Branch: 1 branch
BranchTrueFalseTotal
unless $entry 1 48 49
120 48 $entry->{runner}->(@ARGV);
121  
122 sub run_dump {
123 27 ▶ my @args = @_;
Subroutine run_dump: called CC=10 SCAR=23.2
124 27 my %opts = (
125 pretty => 0,
126 compact => 0,
127 'ignore-errors' => 0,
128 'fail-fast' => 0,
129 'errors-to-stderr' => 0,
130 'quiet' => 0,
131 'enable-warnings' => 0,
132 'vendor-id' => undef,
133 'strict-legal-basis' => 0,
134 );
135  
136 27 require Getopt::Long;
137 27 my $parser = Getopt::Long::Parser->new(config => [qw(no_pass_through require_order bundling)]);
138  
139 27 my $getopt_ok;
140 {
141 27 local @ARGV = @args;
142 $getopt_ok = $parser->getoptions(
143 'pretty|p' => \$opts{pretty},
144 'compact|c' => \$opts{compact},
145 'ignore-errors|i' => \$opts{'ignore-errors'},
146 'fail-fast|f' => \$opts{'fail-fast'},
147 'errors-to-stderr|e' => \$opts{'errors-to-stderr'},
148 'quiet|q' => \$opts{'quiet'},
149 'enable-warnings|w' => \$opts{'enable-warnings'},
150 'vendor-id|v=i' => \$opts{'vendor-id'},
151 'strict-legal-basis|s' => \$opts{'strict-legal-basis'},
152 'help' => sub {
153 1 ▶ pod2usage(-input => $script_path, -exitval => 1, -verbose => 99, -sections => "DUMP|BUGS");
Subroutine __ANON__: called CC=1 SCAR=0.0
154 },
155 1 ▶ 'h' => sub { _show_subcommand_short_help('dump'); exit 1; },
Subroutine __ANON__: called CC=1 SCAR=0.0
156 27 );
157 25 @args = @ARGV;
158 }
159 25 ▶ $getopt_ok or pod2usage(-input => $script_path, -exitval => 2, -verbose => 99, -sections => "DUMP/Usage");
Branch: 1 branch
BranchTrueFalseTotal
$getopt_ok or pod2usage("-input", $script_path, "-exitval", 2, "-verbose", 99, "-sections", "DUMP/Usage") 0 25 25
160  
161 25 ▶ my $json_pkg = JSON->can('new') ? 'JSON' : 'JSON::PP';
Branch: 1 branch
BranchTrueFalseTotal
'JSON'->can('new') ? : 25 0 25
162 25 my $json = $json_pkg->new->utf8;
163 25 ▶ if ($opts{pretty}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"pretty"}) 7 18 25
164 7 $json->pretty(1);
165 7 ▶ $json->indent_length(4) if $json->isa('JSON::PP');
Branch: 1 branch
BranchTrueFalseTotal
if $json->isa("JSON::PP") 0 7 7
166 }
167  
168 25 my $state = {count => 0, line_num => 0,};
169  
170 25 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 24 1 25
171 24 foreach my $str (@args) {
172 25 $state->{line_num}++;
173 25 _process_string($str, $state, \%opts, $json);
174 }
175 }
176 else {
177 1 ▶ binmode(STDIN, ':encoding(UTF-8)') if -t STDIN; ## no critic (InputOutput::ProhibitInteractiveTest, InputOutput::RequireEncodingWithUTF8Layer)
Branch: 1 branch
BranchTrueFalseTotal
if -t STDIN 0 1 1
178 1 ▶ while (my $line = <STDIN>) { ## no critic (InputOutput::ProhibitExplicitStdin)
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline STDIN)) 1 1 2
179 1 $state->{line_num}++;
180 1 chomp $line;
181 1 ▶ next unless $line =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\S/u 0 1 1
182 1 _process_string($line, $state, \%opts, $json);
183 }
184 }
185  
186 24 exit EXIT_SUCCESS;
187 }
188  
189 sub _process_string {
190 26 ▶ my ($str, $state, $o, $j) = @_;
Subroutine _process_string: called CC=8 SCAR=20.9
191 26 my $output_data;
192  
193 26 eval {
194 my $tcf = GDPR::IAB::TCFv2->Parse(
195 $str,
196 json => {compact => $o->{compact}, vendor_id => $o->{'vendor-id'},},
197 26 strict => $o->{'strict-legal-basis'},
198 );
199 19 $output_data = $tcf->TO_JSON;
200 };
201 26 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 7 19 26
202 7 ▶ if ($o->{'fail-fast'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"fail-fast"}) 1 6 7
203 1 ▶ warn "Fatal: Failed to parse TC string '$str' at line $state->{line_num}: $err\n" if $o->{'enable-warnings'};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"enable-warnings"} 0 1 1
204 1 exit EXIT_PARSE_ERROR;
205 }
206  
207 6 ▶ warn "Warning: Failed to parse TC string '$str' at line $state->{line_num}: $err\n" if $o->{'enable-warnings'};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"enable-warnings"} 0 6 6
208  
209 6 ▶ return if $o->{'ignore-errors'};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"ignore-errors"} 1 5 6
210  
211 5 $err = _clean_error($err);
212 5 $output_data = {tc_string => $str, error => $err, success => _json_false(),};
213  
214 5 ▶ if ($o->{'errors-to-stderr'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"errors-to-stderr"}) 1 4 5
215 1 warn $j->encode($output_data) . "\n";
216 1 return;
217 }
218 }
219  
220 23 ▶ return if $o->{'quiet'};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"quiet"} 0 23 23
221  
222 23 print $j->encode($output_data) . "\n";
223  
224 23 $state->{count}++;
225 }
226  
227 sub _show_help {
228 2 ▶ my $topic = shift;
Subroutine _show_help: called CC=5 SCAR=17.5
229  
230 2 ▶ if ($topic && $topic eq 'dump') {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic and $topic eq "dump") 1 1 2
Condition66%2/3
$topic and $topic eq "dump"
!ll&&!rl&&r
101
MC/DC50%1/2
$topic and $topic eq "dump"
$topic $topic eq "dump"
Truth table66%2/3
A and B
A= $topicB= $topic eq "dump"
ABresult
0X0
100
111
231 1 pod2usage(-input => $script_path, -exitval => 1, -verbose => 99, -sections => "DUMP|BUGS");
232 }
233 1 ▶ if ($topic && $topic eq 'validate') {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic and $topic eq "validate") 0 1 1
Condition33%1/3
$topic and $topic eq "validate"
!ll&&!rl&&r
100
MC/DC0%0/2
$topic and $topic eq "validate"
$topic $topic eq "validate"
Truth table33%1/3
A and B
A= $topicB= $topic eq "validate"
ABresult
0X0
100
111
234 0 pod2usage(-input => $script_path, -exitval => 1, -verbose => 99, -sections => "VALIDATE|BUGS");
235 }
236 1 pod2usage(-input => $script_path, -exitval => 1, -verbose => 99, -sections => "SYNOPSIS|OPTIONS|SUBCOMMANDS|BUGS");
237 }
238  
239 # Brief overview shown by `iabtcfv2 -h`, by `iabtcfv2 -h <subcommand>`,
240 # by a bare `iabtcfv2`, or as a fallback path. Always exits 1 so the
241 # caller's shell sees "no command actually ran".
242 sub _show_short_help {
243 2 ▶ my $topic = shift;
Subroutine _show_short_help: called CC=4 SCAR=14.2
244  
245 2 ▶ if (defined $topic && $SUBCOMMANDS{$topic}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $topic and $SUBCOMMANDS{$topic}) 0 2 2
Condition33%1/3
defined $topic and $SUBCOMMANDS{$topic}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $topic and $SUBCOMMANDS{$topic}
defined $topic $SUBCOMMANDS{$topic}
Truth table33%1/3
A and B
A= defined $topicB= $SUBCOMMANDS{$topic}
ABresult
0X0
100
111
246 0 _show_subcommand_short_help($topic);
247 0 exit 1;
248 }
249  
250 2 print {*STDERR} "iabtcfv2 - CLI tool for GDPR IAB TCF v2 strings\n\n";
251 2 print {*STDERR} "Usage:\n iabtcfv2 <subcommand> [options] [tc_strings...]\n\n";
252 2 print {*STDERR} "Subcommands:\n";
253 2 for my $name (sort keys %SUBCOMMANDS) {
254 4 printf {*STDERR} " %-10s %s\n", $name, $SUBCOMMANDS{$name}{summary};
255 }
256 2 print {*STDERR} "\n";
257 2 print {*STDERR} "Run 'iabtcfv2 <subcommand> -h' for a short summary of that subcommand.\n";
258 2 print {*STDERR} "Run 'iabtcfv2 --help' for the full manual.\n";
259 2 exit 1;
260 }
261  
262 sub _show_subcommand_short_help {
263 2 ▶ my $name = shift;
Subroutine _show_subcommand_short_help: called CC=7 SCAR=19.5
264 2 my $sub_entry = $SUBCOMMANDS{$name};
265  
266 2 print {*STDERR} "iabtcfv2 $name - $sub_entry->{summary}\n\n";
267 2 print {*STDERR} "Usage:\n $sub_entry->{synopsis}\n\n";
268 2 print {*STDERR} "Options:\n";
269  
270 # `-h` / `--help` are appended as if they were registry rows so they
271 # share the two-pass alignment below and do not require hardcoded
272 # column widths.
273 my @rows
274 2 = (@{$sub_entry->{common}}, ['-h', '', '', 'Show this short help'], ['', '--help', '', 'Show full documentation'],);
275  
276 # Two-pass formatting so the description column is left-aligned across
277 # rows regardless of long-option / value-placeholder width.
278 2 my @lines;
279 2 my $left_width = 0;
280 2 for my $row (@rows) {
281 29 my ($s, $l, $v, $desc) = @{$row};
282 29 my $left_col;
283 29 ▶ if (length $l) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $l) { } 27 2 29
284  
285 # `-x, --long-name [<VAL>]` — comma only when both forms exist.
286 27 ▶ my $short_col = length($s) ? "$s," : ' ';
Branch: 1 branch
BranchTrueFalseTotal
length $s ? : 24 3 27
287 27 ▶ $left_col = sprintf " %-3s %s%s", $short_col, $l, length($v) ? " $v" : '';
Branch: 1 branch
BranchTrueFalseTotal
length $v ? : 7 20 27
288 }
289 else {
290 # Short-only row (e.g. the `-h` line in the appended help block).
291 2 $left_col = sprintf " %s", $s;
292 }
293 29 ▶ $left_width = length($left_col) if length($left_col) > $left_width;
Branch: 1 branch
BranchTrueFalseTotal
if length $left_col > $left_width 7 22 29
294 29 push @lines, [$left_col, $desc];
295 }
296  
297 2 for my $r (@lines) {
298 29 printf {*STDERR} "%-${left_width}s %s\n", $r->[0], $r->[1];
299 }
300  
301 2 print {*STDERR} "\nReads TC strings from positional args, or one per line from STDIN.\n";
302 2 print {*STDERR} "\nRun 'iabtcfv2 $name --help' for the full documentation.\n";
303 }
304  
305 sub _unknown_subcommand {
306 1 ▶ my $name = shift;
Subroutine _unknown_subcommand: called CC=2 SCAR=6.9
307  
308 1 print {*STDERR} "iabtcfv2: unknown subcommand '$name'\n\n";
309 1 print {*STDERR} "Available subcommands:\n";
310 1 for my $sc (sort keys %SUBCOMMANDS) {
311 2 printf {*STDERR} " %-10s %s\n", $sc, $SUBCOMMANDS{$sc}{summary};
312 }
313 1 print {*STDERR} "\n";
314 1 print {*STDERR} "Run 'iabtcfv2 -h' for a short overview, or 'iabtcfv2 --help' for the full manual.\n";
315 1 exit 2;
316 }
317  
318 sub _parse_id_list {
319 6 ▶ my $s = shift;
Subroutine _parse_id_list: called CC=3 SCAR=11.8
320 6 ▶ return [] unless defined $s && length $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and length $s 0 6 6
Condition33%1/3
defined $s and length $s
!ll&&!rl&&r
006
MC/DC0%0/2
defined $s and length $s
defined $s length $s
Truth table33%1/3
A and B
A= defined $sB= length $s
ABresult
0X0
100
111
321 6 return [map { 0 + $_ } grep { length $_ } split /\s*,\s*/, $s];
322 }
323  
324 sub run_validate { ## no critic (Subroutines::ProhibitExcessComplexity)
325 21 ▶ my @args = @_;
Subroutine run_validate: called CC=22 SCAR=35.0
326 21 my %opts = (
327 pretty => 0,
328 'ignore-errors' => 0,
329 'fail-fast' => 0,
330 'errors-to-stderr' => 0,
331 quiet => 0,
332 'enable-warnings' => 0,
333 'vendor-id' => undef,
334 'consent-purposes' => undef,
335 'legitimate-interest-purposes' => undef,
336 'flexible-purposes' => undef,
337 'verify-disclosed-vendors' => 0,
338 'strict-legal-basis' => 0,
339 'min-tcf-policy-version' => undef,
340 'cmp-validator' => undef,
341 'cmp-validator-network-ok' => 0,
342 'cmp-validator-verify-ssl' => 1,
343 'cmp-validator-timeout' => 30,
344 all => 0,
345 text => 0,
346 );
347  
348 21 require Getopt::Long;
349 21 my $parser = Getopt::Long::Parser->new(config => [qw(no_pass_through require_order bundling)]);
350  
351 21 my $getopt_ok;
352 {
353 21 local @ARGV = @args;
354 $getopt_ok = $parser->getoptions(
355 'pretty|p' => \$opts{pretty},
356 'ignore-errors|i' => \$opts{'ignore-errors'},
357 'fail-fast|f' => \$opts{'fail-fast'},
358 'errors-to-stderr|e' => \$opts{'errors-to-stderr'},
359 'quiet|q' => \$opts{quiet},
360 'enable-warnings|w' => \$opts{'enable-warnings'},
361 'vendor-id|v=i' => \$opts{'vendor-id'},
362 'consent-purposes|C=s' => \$opts{'consent-purposes'},
363 'legitimate-interest-purposes|L=s' => \$opts{'legitimate-interest-purposes'},
364 'flexible-purposes|F=s' => \$opts{'flexible-purposes'},
365 'verify-disclosed-vendors|d' => \$opts{'verify-disclosed-vendors'},
366 'strict-legal-basis|s' => \$opts{'strict-legal-basis'},
367 'min-tcf-policy-version|m=i' => \$opts{'min-tcf-policy-version'},
368 'cmp-validator=s' => \$opts{'cmp-validator'},
369 'cmp-validator-network-ok' => \$opts{'cmp-validator-network-ok'},
370 'cmp-validator-verify-ssl!' => \$opts{'cmp-validator-verify-ssl'},
371 'cmp-validator-timeout=i' => \$opts{'cmp-validator-timeout'},
372 'all|a' => \$opts{all},
373 'text|t' => \$opts{text},
374 'help' => sub {
375 0 ▶ pod2usage(-input => $script_path, -exitval => 1, -verbose => 99, -sections => "VALIDATE|BUGS");
Subroutine __ANON__: not called CC=1 SCAR=6.9
376 },
377 1 ▶ 'h' => sub { _show_subcommand_short_help('validate'); exit 1; },
Subroutine __ANON__: called CC=1 SCAR=0.0
378 21 );
379 20 @args = @ARGV;
380 }
381 20 ▶ $getopt_ok or pod2usage(-input => $script_path, -exitval => 2, -verbose => 99, -sections => "VALIDATE/Usage");
Branch: 1 branch
BranchTrueFalseTotal
$getopt_ok or pod2usage("-input", $script_path, "-exitval", 2, "-verbose", 99, "-sections", "VALIDATE/Usage") 0 20 20
382  
383 20 ▶ unless (defined $opts{'vendor-id'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts{"vendor-id"}) 1 19 20
384 1 pod2usage(
385 -input => $script_path,
386 -exitval => 2,
387 -message => "validate: --vendor-id|-v is required",
388 -verbose => 99,
389 -sections => "VALIDATE/Usage"
390 );
391 }
392  
393 19 require GDPR::IAB::TCFv2::Validator;
394  
395 my %vargs = (
396 vendor_id => $opts{'vendor-id'},
397 verify_disclosed_vendors => $opts{'verify-disclosed-vendors'},
398 19 strict_legal_basis => $opts{'strict-legal-basis'},
399 );
400 19 ▶ $vargs{consent_purpose_ids} = _parse_id_list($opts{'consent-purposes'}) if defined $opts{'consent-purposes'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"consent-purposes"} 5 14 19
401 $vargs{legitimate_interest_purpose_ids} = _parse_id_list($opts{'legitimate-interest-purposes'})
402 19 ▶ if defined $opts{'legitimate-interest-purposes'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"legitimate-interest-purposes"} 1 18 19
403 19 ▶ $vargs{flexible_purpose_ids} = _parse_id_list($opts{'flexible-purposes'}) if defined $opts{'flexible-purposes'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"flexible-purposes"} 0 19 19
404 19 ▶ $vargs{min_tcf_policy_version} = $opts{'min-tcf-policy-version'} if defined $opts{'min-tcf-policy-version'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"min-tcf-policy-version"} 0 19 19
405  
406 19 ▶ if (defined $opts{'cmp-validator'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"cmp-validator"}) 8 11 19
407 8 require GDPR::IAB::TCFv2::CMPValidator;
408  
409 8 my $src = $opts{'cmp-validator'};
410 8 my %cmp_args = (verify_ssl => $opts{'cmp-validator-verify-ssl'}, timeout => $opts{'cmp-validator-timeout'},);
411  
412 8 ▶ if ($src =~ m{^https?://}i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($src =~ m[^https?://]iu) { } 1 7 8
413 1 $cmp_args{url} = $src;
414 1 ▶ $cmp_args{network_ok} = 1 if $opts{'cmp-validator-network-ok'};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"cmp-validator-network-ok"} 0 1 1
415 }
416 else {
417 7 $cmp_args{file} = $src;
418 }
419  
420 # The CMPValidator emits a `carp` when the registry is older
421 # than 28 days. Surface that warning only when the user has
422 # opted into warnings (--enable-warnings); otherwise filter it
423 # out so routine CLI use stays quiet. Other warnings flow
424 # through unchanged.
425 8 my $cmp_validator;
426 {
427 8 local $SIG{__WARN__} = sub {
428 5 ▶ my $msg = defined($_[0]) ? $_[0] : '';
Subroutine __ANON__: called CC=3 SCAR=13.1
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 5 0 5
429 5 ▶ return if $msg =~ /CMP list is older than 28 days/;
Branch: 1 branch
BranchTrueFalseTotal
if $msg =~ /CMP list is older than 28 days/u 5 0 5
430 0 warn @_; ## no critic (ErrorHandling::RequireCarping)
431 }
432 8 ▶ if !$opts{'enable-warnings'};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"enable-warnings"} 7 1 8
433  
434 8 $cmp_validator = eval { GDPR::IAB::TCFv2::CMPValidator->new(%cmp_args) };
435 }
436  
437 8 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 2 6 8
438 2 $err = _clean_error($err);
439 2 warn "validate: $err\n";
440 2 exit 2;
441 }
442  
443 6 $vargs{cmp_validator} = $cmp_validator;
444 }
445  
446 17 my $validator = eval { GDPR::IAB::TCFv2::Validator->new(%vargs) };
447 17 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 17 17
448 0 $err = _clean_error($err);
449 0 warn "validate: $err\n";
450 0 exit 2;
451 }
452  
453 17 ▶ my $json_pkg = JSON->can('new') ? 'JSON' : 'JSON::PP';
Branch: 1 branch
BranchTrueFalseTotal
'JSON'->can('new') ? : 17 0 17
454 17 my $json = $json_pkg->new->utf8;
455 17 ▶ if ($opts{pretty}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"pretty"}) 0 17 17
456 0 $json->pretty(1);
457 0 ▶ $json->indent_length(4) if $json->isa('JSON::PP');
Branch: 1 branch
BranchTrueFalseTotal
if $json->isa("JSON::PP") 0 0 0
458 }
459  
460 17 my $state = {count => 0, line_num => 0, any_fail => 0,};
461  
462 17 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 17 0 17
463 17 foreach my $str (@args) {
464 17 $state->{line_num}++;
465 17 _validate_string($str, $state, \%opts, $json, $validator);
466 }
467 }
468 else {
469 0 ▶ binmode(STDIN, ':encoding(UTF-8)') if -t STDIN; ## no critic (InputOutput::ProhibitInteractiveTest, InputOutput::RequireEncodingWithUTF8Layer)
Branch: 1 branch
BranchTrueFalseTotal
if -t STDIN 0 0 0
470 0 ▶ while (my $line = <STDIN>) { ## no critic (InputOutput::ProhibitExplicitStdin)
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline STDIN)) 0 0 0
471 0 $state->{line_num}++;
472 0 chomp $line;
473 0 ▶ next unless $line =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\S/u 0 0 0
474 0 _validate_string($line, $state, \%opts, $json, $validator);
475 }
476 }
477  
478 17 ▶ exit($state->{any_fail} ? EXIT_PARSE_ERROR : EXIT_SUCCESS);
Branch: 1 branch
BranchTrueFalseTotal
$state->{'any_fail'} ? : 9 8 17
479 }
480  
481 sub _validate_string {
482 17 ▶ my ($str, $state, $o, $j, $validator) = @_;
Subroutine _validate_string: called CC=15 SCAR=29.7
483  
484 17 ▶ my $result = eval { $o->{all} ? $validator->validate_all($str) : $validator->validate($str); };
Branch: 1 branch
BranchTrueFalseTotal
$o->{'all'} ? : 2 15 17
485 17 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 3 14 17
486 3 $state->{any_fail} = 1;
487  
488 3 ▶ if ($o->{'fail-fast'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"fail-fast"}) 0 3 3
489 0 ▶ warn "Fatal: Failed to parse TC string '$str' at line $state->{line_num}: $err\n" if $o->{'enable-warnings'};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"enable-warnings"} 0 0 0
490 0 exit EXIT_PARSE_ERROR;
491 }
492  
493 3 ▶ warn "Warning: Failed to parse TC string '$str' at line $state->{line_num}: $err\n" if $o->{'enable-warnings'};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"enable-warnings"} 0 3 3
494  
495 3 ▶ return if $o->{'ignore-errors'};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"ignore-errors"} 1 2 3
496  
497 2 $err = _clean_error($err);
498 2 my $output_data = {tc_string => $str, error => $err, success => _json_false(),};
499  
500 2 ▶ if ($o->{'errors-to-stderr'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"errors-to-stderr"}) 0 2 2
501 0 ▶ if ($o->{text}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{'text'}) { } 0 0 0
502 0 warn "ERROR $str: $err\n";
503 }
504 else {
505 0 warn $j->encode($output_data) . "\n";
506 }
507 0 return;
508 }
509  
510 2 ▶ return if $o->{quiet};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"quiet"} 0 2 2
511 2 _emit_validate($output_data, $state, $o, $j);
512 2 return;
513 }
514  
515 14 my $output_data;
516 14 ▶ if ($result->is_valid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->is_valid) { } 8 6 14
517 8 $output_data = {tc_string => $str, vendor_id => $o->{'vendor-id'}, valid => _json_true(),};
518 }
519 else {
520 6 $state->{any_fail} = 1;
521 6 my @reasons = $result->reasons;
522 $output_data = {
523 tc_string => $str,
524 vendor_id => $o->{'vendor-id'},
525 valid => _json_false(),
526 6 ▶ $o->{all} ? (reasons => \@reasons) : (reason => $reasons[0]),
Branch: 1 branch
BranchTrueFalseTotal
$o->{'all'} ? : 2 4 6
527 };
528 }
529  
530 14 ▶ return if $o->{quiet};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"quiet"} 2 12 14
531  
532 12 _emit_validate($output_data, $state, $o, $j);
533  
534 12 ▶ exit EXIT_PARSE_ERROR if !$result->is_valid && $o->{'fail-fast'};
Branch: 1 branch
BranchTrueFalseTotal
if not $result->is_valid and $o->{"fail-fast"} 0 12 12
Condition66%2/3
not $result->is_valid and $o->{"fail-fast"}
!ll&&!rl&&r
750
MC/DC0%0/2
not $result->is_valid and $o->{"fail-fast"}
not $result->is_valid $o->{"fail-fast"}
Truth table66%2/3
not(A) and B
A= not $result->is_validB= $o->{"fail-fast"}
ABresult
0X0
100
111
535  
536 12 return;
537 }
538  
539 sub _emit_validate {
540 14 ▶ my ($output_data, $state, $o, $j) = @_;
Subroutine _emit_validate: called CC=7 SCAR=19.5
541  
542 14 ▶ if ($o->{text}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"text"}) 3 11 14
543 3 my $tc = $output_data->{tc_string};
544 3 my $vid = $output_data->{vendor_id};
545 3 my $line;
546 3 ▶ if (exists $output_data->{error}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $output_data->{'error'}) { } 0 3 3
elsif ($output_data->{'valid'}) { } 1 2 3
547 0 $line = "ERROR $tc: $output_data->{error}";
548 }
549 elsif ($output_data->{valid}) {
550 1 $line = "OK $tc vendor $vid";
551 }
552 else {
553 2 ▶ my @reasons = $o->{all} ? @{$output_data->{reasons} || []} : ($output_data->{reason});
Branch: 2 branches
BranchTrueFalseTotal
$o->{'all'} ? : 1 1 2
$output_data->{"reasons"} or [] 0 1 1
554 2 ▶ if (@reasons == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@reasons == 1) { } 1 1 2
555 1 $line = "FAIL $tc vendor $vid: $reasons[0]";
556 }
557 else {
558 1 $line = join "\n", "FAIL $tc vendor $vid:", map {" - $_"} @reasons;
559 }
560 }
561 3 print "$line\n";
562 3 $state->{count}++;
563 3 return;
564 }
565  
566 11 print $j->encode($output_data) . "\n";
567 11 $state->{count}++;
568  
569 11 return;
570 }
571  
572 __END__
573  
574 =encoding utf8
575  
576 =head1 NAME
577  
578 iabtcfv2 - CLI tool for GDPR IAB TCF v2 strings
579  
580 =head1 SYNOPSIS
581  
582 iabtcfv2 [options] <subcommand> [subcommand-options]
583  
584 Run with B<-h> for a short overview, or B<--help> for the full manual.
585  
586 =head1 OPTIONS
587  
588 =over 4
589  
590 =item B<-h>
591  
592 Print a brief summary (synopsis + common options + pointer to B<--help>) and
593 exits. Pair with a subcommand for a per-subcommand summary, e.g.
594 C<iabtcfv2 dump -h>.
595  
596 =item B<--help>
597  
598 Print the full manual (this document) and exits. Same as C<iabtcfv2 help>.
599 For per-subcommand manuals, run C<iabtcfv2 <sub> --help> or
600 C<iabtcfv2 help <sub>>.
601  
602 =item B<--version>, B<-V>
603  
604 Print the version and exits.
605  
606 =item B<--man>
607  
608 Prints the manual page and exits.
609  
610 =back
611  
612 =head1 SUBCOMMANDS
613  
614 =over 4
615  
616 =item B<dump>
617  
618 Parses TC strings and outputs them as JSON.
619  
620 =item B<validate>
621  
622 Validates TC strings against a vendor identity and a set of purpose lists,
623 emitting one JSON record per string (or text lines with B<--text>).
624  
625 =back
626  
627 =head1 DUMP
628  
629 =head2 Usage
630  
631 iabtcfv2 dump [options] [tc_strings...]
632  
633 Run `iabtcfv2 dump -h` for a short summary, or `--help` for this manual.
634  
635 =head2 Description
636  
637 Parses TC strings and outputs them as JSON.
638  
639 =head2 Options
640  
641 =over 4
642  
643 =item B<--pretty>, B<-p>
644  
645 Output human-readable, indented JSON.
646  
647 =item B<--compact>, B<-c>
648  
649 Output a compact JSON representation (lists of IDs instead of boolean maps).
650  
651 =item B<--vendor-id>, B<-v> I<ID>
652  
653 Filter the output to only show data for a specific vendor ID.
654  
655 =item B<--strict-legal-basis>, B<-s>
656  
657 Enable strict specification validation. In this mode, the tool will fail if
658 mandatory segments are missing (e.g., Disclosed Vendors in TCF v2.3).
659  
660 =item B<--ignore-errors>, B<-i>
661  
662 Do not output any JSON error object for failed strings.
663  
664 =item B<--fail-fast>, B<-f>
665  
666 Stop processing and exit the program immediately upon the first parse error.
667  
668 =item B<--errors-to-stderr>, B<-e>
669  
670 Output JSON error objects to B<STDERR> instead of B<STDOUT>.
671  
672 =item B<--enable-warnings>, B<-w>
673  
674 Emit human-readable warning messages on B<STDERR> when a TC string fails to
675 parse. Off by default; enable to get diagnostic context alongside the JSON
676 error object.
677  
678 =item B<--quiet>, B<-q>
679  
680 Suppress all output on B<STDOUT>. The exit code still reflects whether parsing
681 succeeded, which is convenient for shell-style C<if iabtcfv2 dump -q "$tc">
682 checks. Combine with C<--enable-warnings> if you want diagnostics on B<STDERR>.
683  
684 =back
685  
686 =head2 Examples
687  
688 # Dump a string to JSON line
689 iabtcfv2 dump CPi...AAA
690  
691 # Dump multiple strings (one JSON object per line)
692 iabtcfv2 dump CPi...AAA CPj...BBB
693  
694 # Read from STDIN
695 cat strings.txt | iabtcfv2 dump
696  
697 # Pipe through `jq -s` if you need a single JSON array
698 cat strings.txt | iabtcfv2 dump | jq -s .
699  
700 =head2 Short option bundling
701  
702 Single-character flags can be bundled together after a single dash. The last
703 option in the bundle may take a value as the next argument.
704  
705 # Equivalent of `--pretty --ignore-errors`
706 iabtcfv2 dump -pi CPi...AAA
707  
708 # Equivalent of `--compact --pretty`
709 iabtcfv2 dump -cp CPi...AAA
710  
711 # Last bundled short can take a value: -p (pretty) + -v <id> (vendor-id)
712 iabtcfv2 dump -pv 284 CPi...AAA
713  
714 # Long options accept the GNU `=value` form too
715 iabtcfv2 dump --vendor-id=284 CPi...AAA
716  
717 Bundling does NOT support abbreviating long options (`--ver` is not accepted
718 as a shortcut for `--version`); always use the full long-option name or its
719 single-character short alias.
720  
721 =head1 DOCKER USAGE
722  
723 This tool is also available as a Docker image on Docker Hub.
724  
725 =head2 Basic Usage
726  
727 docker run --rm peczenyj/gdpr-iab-tcfv2 dump "CLcVDxRMWfGmWAVAHCENAXCkAKDAADnAABRgA5mdfCKZuYJez-NQm0TBMYA4oCAAGQYIAAAAAAEAIAEgAA"
728  
729 =head2 Processing Streams (STDIN)
730  
731 To process a stream of strings via pipe:
732  
733 cat strings.txt | docker run -i --rm peczenyj/gdpr-iab-tcfv2 dump
734  
735 To type strings manually:
736  
737 docker run -it --rm peczenyj/gdpr-iab-tcfv2 dump
738  
739 =head1 VALIDATE
740  
741 =head2 Usage
742  
743 iabtcfv2 validate --vendor-id <id> [options] [tc_strings...]
744  
745 Run `iabtcfv2 validate -h` for a short summary, or `--help` for this manual.
746  
747 =head2 Description
748  
749 Validates TC strings against a vendor identity and a set of declared purpose
750 lists. The vendor must be allowed for every purpose in C<--consent-purposes>
751 on a consent basis, and for every purpose in
752 C<--legitimate-interest-purposes> on a legitimate-interest basis. Purposes
753 listed in C<--flexible-purposes> are checked using the GVL flexible-purpose
754 semantics, with the default basis derived from which list also contains the
755 purpose. See L<GDPR::IAB::TCFv2::Validator> for the underlying rule engine.
756  
757 By default the subcommand emits one JSON object per input TC string on
758 B<STDOUT>. With B<--text> it emits one human-readable line per string
759 instead.
760  
761 =head2 Output shape
762  
763 A successful validation produces:
764  
765 {"tc_string":"CO...","vendor_id":32,"valid":true}
766  
767 A failure in default (fail-fast) mode produces a singular C<reason>:
768  
769 {"tc_string":"CO...","vendor_id":32,"valid":false,
770 "reason":"vendor 32 not allowed for purpose 1 (consent)"}
771  
772 A failure in B<--all> mode produces a plural C<reasons> array:
773  
774 {"tc_string":"CO...","vendor_id":32,"valid":false,
775 "reasons":["...","..."]}
776  
777 A parse error produces the same shape as the C<dump> subcommand:
778  
779 {"tc_string":"INVALID","error":"...","success":false}
780  
781 =head2 Required options
782  
783 =over 4
784  
785 =item B<--vendor-id>, B<-v> I<ID>
786  
787 The numeric vendor ID to validate against. Required.
788  
789 =back
790  
791 =head2 Purpose options
792  
793 =over 4
794  
795 =item B<--consent-purposes>, B<-C> I<1,2,3>
796  
797 Comma-separated list of purpose IDs that the vendor must be allowed to
798 process on a B<consent> basis.
799  
800 =item B<--legitimate-interest-purposes>, B<-L> I<1,2,3>
801  
802 Comma-separated list of purpose IDs that the vendor must be allowed to
803 process on a B<legitimate interest> basis.
804  
805 =item B<--flexible-purposes>, B<-F> I<1,2,3>
806  
807 Comma-separated list of purpose IDs that the vendor declared as flexible.
808 Each ID listed here MUST also appear in either C<--consent-purposes> or
809 C<--legitimate-interest-purposes>; the membership determines the default
810 legal basis used for the flexible-purpose check.
811  
812 =back
813  
814 =head2 Rule options
815  
816 =over 4
817  
818 =item B<--verify-disclosed-vendors>, B<-d>
819  
820 Require the vendor to appear in the Disclosed Vendors segment. When the TC string
821 carries the segment, the vendor must be present. If the segment is absent, it
822 only fails if B<--min-tcf-policy-version> is set to 5 or higher (TCF v2.3+).
823  
824 =item B<--strict-legal-basis>, B<-s>
825  
826 Enable strict spec validation in the underlying parser (see C<dump --strict>).
827  
828 =item B<--min-tcf-policy-version>, B<-m> I<N>
829  
830 Reject TC strings whose Global Vendor List policy version is below I<N>.
831 Checked first, before any vendor- or purpose-level rules.
832  
833 =item B<--cmp-validator> I<PATH-OR-URL>
834  
835 Validate the C<cmp_id> embedded in each TC string against an IAB CMP
836 registry snapshot. The argument is detected as a URL when it starts
837 with C<http://> or C<https://>, otherwise it is treated as a local
838 file path. Failures yield a C<reason> mentioning the unknown or
839 deleted CMP id.
840  
841 When the argument is a URL, the standard HTTP-proxy environment
842 variables (C<https_proxy>, C<http_proxy>, C<no_proxy>) are honored
843 automatically.
844  
845 =item B<--cmp-validator-network-ok>
846  
847 Required when B<--cmp-validator> is a URL. Without this flag, URL fetching
848 is refused (mirrors the library's C<network_ok =E<gt> 1> opt-in:
849 fetching from an arbitrary URL is intentional, never accidental).
850 Has no effect when B<--cmp-validator> is a file path.
851  
852 =item B<--cmp-validator-verify-ssl>, B<--no-cmp-validator-verify-ssl>
853  
854 Verify TLS certificates when fetching from an HTTPS URL. On by default;
855 disable with B<--no-cmp-validator-verify-ssl> only when targeting a server
856 with a self-signed or otherwise non-public-CA certificate. Has no
857 effect when B<--cmp-validator> is a file path.
858  
859 =item B<--cmp-validator-timeout> I<SECONDS>
860  
861 Per-request timeout for the URL fetch, in seconds. Defaults to 30.
862 Has no effect when B<--cmp-validator> is a file path.
863  
864 =item B<--all>, B<-a>
865  
866 Accumulate every failing rule into a C<reasons> array instead of
867 short-circuiting on the first failure. The output JSON uses plural
868 C<reasons> (array) instead of singular C<reason> (string).
869  
870 =back
871  
872 =head2 Output options
873  
874 =over 4
875  
876 =item B<--pretty>, B<-p>
877  
878 Output human-readable, indented JSON.
879  
880 =item B<--text>, B<-t>
881  
882 Output one human-readable line per TC string instead of JSON. Format:
883  
884 OK <tc> vendor <id>
885 FAIL <tc> vendor <id>: <reason>
886 ERROR <tc>: <parse error>
887  
888 In B<--all> mode, multi-reason failures span multiple indented lines.
889  
890 =item B<--ignore-errors>, B<-i>
891  
892 Skip parse errors silently (still bumps the exit code). Validation failures
893 are still emitted.
894  
895 =item B<--fail-fast>, B<-f>
896  
897 Exit immediately on the first parse error or the first invalid TC string.
898 Validation failures are emitted before exiting; parse errors are not (matches
899 the C<dump> contract).
900  
901 =item B<--errors-to-stderr>, B<-e>
902  
903 Route parse-error records to B<STDERR> instead of B<STDOUT>.
904  
905 =item B<--enable-warnings>, B<-w>
906  
907 Emit human-readable warning messages on B<STDERR> when a TC string fails to
908 parse, and when the B<--cmp-validator> registry snapshot is older than 28 days.
909 Off by default.
910  
911 =item B<--quiet>, B<-q>
912  
913 Suppress all output on B<STDOUT>. The exit code still reflects validity,
914 which is convenient for shell-style C<if iabtcfv2 validate -q -v 32 ... "$tc">
915 checks.
916  
917 =back
918  
919 =head2 Exit codes
920  
921 =over 4
922  
923 =item *
924  
925 B<0> — every input TC string was parsed and validated cleanly.
926  
927 =item *
928  
929 B<1> — at least one TC string failed validation or could not be parsed.
930  
931 =item *
932  
933 B<2> — bad CLI usage (missing C<--vendor-id>, incoherent purpose lists,
934 unreachable C<--cmp-validator> source).
935  
936 =back
937  
938 =head2 Examples
939  
940 # Single string, fail-fast
941 iabtcfv2 validate -v 32 -C 1,3 -L 7 CO...AAA
942  
943 # All reasons, pretty JSON, text-friendly
944 iabtcfv2 validate -av 32 -C 1,3 -L 7 -t CO...AAA
945  
946 # Pipeline-friendly: just the exit code
947 if iabtcfv2 validate -q -v 32 -C 1,3 "$tc"; then ...
948  
949 # Many strings as JSON Lines (one record per line); pipe through
950 # `jq -s` if you need a single JSON array.
951 iabtcfv2 validate -v 32 -C 1,3 CO...AAA CO...BBB
952 iabtcfv2 validate -v 32 -C 1,3 CO...AAA CO...BBB | jq -s .
953  
954 # Reject TC strings that name an unknown or deleted CMP, using a
955 # local snapshot of the IAB CMP registry.
956 iabtcfv2 validate -v 32 --cmp-validator /etc/iab/cmp-list.json CO...AAA
957  
958 # Same, but fetching the registry over HTTPS through whatever
959 # proxy `https_proxy` points at.
960 iabtcfv2 validate -v 32 \
961 --cmp-validator https://cmplist.consensu.org/v2/cmp-list.json \
962 --cmp-validator-network-ok \
963 CO...AAA
964  
965 =head1 DESCRIPTION
966  
967 B<iabtcfv2> is a command-line interface for the GDPR::IAB::TCFv2 library.
968  
969 =head2 B<Warning: Name Change>
970  
971 Previous versions of this distribution (v0.300) included a standalone utility
972 named B<iabtcf-dump>. This has been unified into the B<iabtcfv2> tool using
973 the B<dump> subcommand.
974  
975 =head1 BUGS
976  
977 Report bugs and feature requests at L<https://github.com/peczenyj/GDPR-IAB-TCFv2/issues>.
978  
979 =cut
« blib/lib/GDPR/IAB/TCFv2/RangeSection.pm ↑ Summary blib/lib/GDPR/IAB/TCFv2/Validator.pm »