BIMI/App/Command/checkvmc.pm

filter: Statementstmt 44.2% 23 / 52 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 61.5% 8 / 13 Podpod 100% 5 / 5 totaltotal 34.6% 36 / 104 CC 14 SCAR 36.3
CC
14
Cov
29%
execute
72.0
validate_args
56.0
description
2.0
CRAP 37.8
« BIMI/App/Command/svgfromvmc.pm ↑ Summary BIMI/App/Command/checkdomain.pm »
1 package Mail::BIMI::App::Command::checkvmc;
2 # ABSTRACT: Check an VMC for validation
3 1 our $VERSION = '3.20261116'; # VERSION
4 1 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶BEGIN { $ENV{MAIL_BIMI_CACHE_DEFAULT_BACKEND} = 'Null' };
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Mail::BIMI::Prelude;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Mail::BIMI::App -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Mail::BIMI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Mail::BIMI::Indicator;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Mail::BIMI::VMC;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Term::ANSIColor qw{ :constants };
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 0 ▶sub description { 'Check a VMC from a given URI or File for validity' }
Subroutine description: not called CC=1 SCAR=6.9
Pod documented
15 0 ▶sub usage_desc { "%c checksvg %o <URI>" }
Subroutine usage_desc: not called CC=1 SCAR=6.9
Pod documented
16  
17 0 ▶sub opt_spec {
Subroutine opt_spec: not called CC=1 SCAR=6.9
Pod documented
18 return (
19 0 [ 'profile=s', 'SVG Profile to validate against ('.join('|',@Mail::BIMI::Indicator::VALIDATOR_PROFILES).')' ],
20 [ 'domain=s', 'Domain' ],
21 [ 'selector=s', 'Selector' ],
22 [ 'fromfile', 'Fetch from file instead of from URI' ],
23 );
24 }
25  
26 0 ▶sub validate_args($self,$opt,$args) {
Subroutine validate_args: not called CC=7 SCAR=40.3
Pod documented
27 0 ▶ $self->usage_error('No URI specified') if !@$args;
Branch: 1 branch
BranchTrueFalseTotal
unless @$args 0 0 0
28 0 ▶ $self->usage_error('Multiple URIs specified') if scalar @$args > 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$args > 1 0 0 0
29 0 ▶ $self->usage_error('Unknown SVG Profile') if $opt->profile && !grep {;$_ eq $opt->profile} @Mail::BIMI::Indicator::VALIDATOR_PROFILES;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->profile and not grep({$_ eq $opt->profile;} @Mail::BIMI::Indicator::VALIDATOR_PROFILES) 0 0 0
Condition0%0/3
$opt->profile and not grep({$_ eq $opt->profile;} @Mail::BIMI::Indicator::VALIDATOR_PROFILES)
!ll&&!rl&&r
000
MC/DC0%0/2
$opt->profile and not grep({$_ eq $opt->profile;} @Mail::BIMI::Indicator::VALIDATOR_PROFILES)
$opt->profile not grep({$_ eq $opt->profile;} @Mail::BIMI::Indicator::VALIDATOR_PROFILES)
Truth table0%0/3
A and not(B)
A= $opt->profileB= not grep({$_ eq $opt->profile;} @Mail::BIMI::Indicator::VALIDATOR_PROFILES)
ABresult
0X0
100
111
30 0 ▶ $self->usage_error('Selector requires domain') if $opt->selector && !$opt->domain;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->selector and not $opt->domain 0 0 0
Condition0%0/3
$opt->selector and not $opt->domain
!ll&&!rl&&r
000
MC/DC0%0/2
$opt->selector and not $opt->domain
$opt->selector not $opt->domain
Truth table0%0/3
A and not(B)
A= $opt->selectorB= not $opt->domain
ABresult
0X0
100
111
31 }
32  
33 0 ▶sub execute($self,$opt,$args) {
Subroutine execute: not called CC=8 SCAR=42.8
Pod documented
34 0 my $uri = $args->[0];
35  
36 0 my %bimi_opt;
37 0 ▶ if ( $opt->domain ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->domain) { } 0 0 0
38 0 $bimi_opt{domain} = $opt->domain;
39 }
40 else {
41 0 $bimi_opt{domain} = 'example.com';
42 }
43 0 $bimi_opt{options} = {};
44 0 ▶ $bimi_opt{options}->{vmc_no_check_alt} = 1 if !$opt->domain;
Branch: 1 branch
BranchTrueFalseTotal
unless $opt->domain 0 0 0
45 0 ▶ $bimi_opt{options}->{vmc_from_file} = $uri if $opt->fromfile;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->fromfile 0 0 0
46  
47 0 my $bimi = Mail::BIMI->new(%bimi_opt);
48  
49 0 ▶ my $vmc = Mail::BIMI::VMC->new( check_domain => $opt->domain//'', check_selector => $opt->selector//'default', uri => $uri, bimi_object => $bimi );
Condition0%0/4
$opt->domain // ""
l!l
00
$opt->selector // "default"
l!l
00
MC/DC0%0/1
$opt->domain // ""
$opt->domain
MC/DC0%0/1
$opt->selector // "default"
$opt->selector
Truth table0%0/2
A
A= $opt->domain
Aresult
11
00
Truth table0%0/2
A
A= $opt->selector
Aresult
11
00
50 # $indicator->validator_profile($opt->profile) if $opt->profile;
51 0 say "BIMI VMC checker";
52 0 say '';
53 0 say 'Requested:';
54 0 ▶ say YELLOW.($opt->fromfile?'File':'URI').WHITE.': '.$uri.RESET;
Branch: 1 branch
BranchTrueFalseTotal
$opt->fromfile ? : 0 0 0
55 0 say '';
56 0 $vmc->app_validate;
57 0 say '';
58 0 ▶ if ( $vmc->indicator ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vmc->indicator) 0 0 0
59 0 $vmc->indicator->app_validate;
60 0 say '';
61 }
62  
63 0 $bimi->finish;
64 }
65  
66 1 1;
67  
68 __END__
« BIMI/App/Command/svgfromvmc.pm ↑ Summary BIMI/App/Command/checkdomain.pm »