| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Mail::BIMI::App::Command::checksvg; | 
| 2 |  |  |  |  |  |  | # ABSTRACT: Check an SVG for validation | 
| 3 |  |  |  |  |  |  | our $VERSION = '3.20210301'; # VERSION | 
| 4 | 2 |  |  | 2 |  | 2031 | use 5.20.0; | 
|  | 2 |  |  |  |  | 9 |  | 
| 5 | 2 |  |  | 2 |  | 48 | BEGIN { $ENV{MAIL_BIMI_CACHE_DEFAULT_BACKEND} = 'Null' }; | 
| 6 | 2 |  |  | 2 |  | 12 | use Mail::BIMI::Prelude; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 14 |  | 
| 7 | 2 |  |  | 2 |  | 561 | use Mail::BIMI::App -command; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 14 |  | 
| 8 | 2 |  |  | 2 |  | 584 | use Mail::BIMI; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 38 |  | 
| 9 | 2 |  |  | 2 |  | 9 | use Mail::BIMI::Indicator; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 90 |  | 
| 10 | 2 |  |  | 2 |  | 12 | use File::Slurp qw{ read_file write_file }; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 134 |  | 
| 11 | 2 |  |  | 2 |  | 15 | use Term::ANSIColor qw{ :constants }; | 
|  | 2 |  |  |  |  | 13 |  | 
|  | 2 |  |  |  |  | 1469 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 1 |  |  | 1 | 1 | 612 | sub description { 'Check a SVG from a given URI or File for validity' } | 
| 15 | 7 |  |  | 7 | 1 | 65235 | sub usage_desc { "%c checksvg %o <URI>" } | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | sub opt_spec { | 
| 18 |  |  |  |  |  |  | return ( | 
| 19 | 7 |  |  | 7 | 1 | 55 | [ 'profile=s', 'SVG Profile to validate against ('.join('|',@Mail::BIMI::Indicator::VALIDATOR_PROFILES).')' ], | 
| 20 |  |  |  |  |  |  | [ 'fromfile', 'Fetch from file instead of from URI' ], | 
| 21 |  |  |  |  |  |  | ); | 
| 22 |  |  |  |  |  |  | } | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 6 |  |  | 6 | 1 | 4409 | sub validate_args($self,$opt,$args) { | 
|  | 6 |  |  |  |  | 12 |  | 
|  | 6 |  |  |  |  | 10 |  | 
|  | 6 |  |  |  |  | 10 |  | 
|  | 6 |  |  |  |  | 9 |  | 
| 25 | 6 | 100 |  |  |  | 24 | $self->usage_error('No URI specified') if !@$args; | 
| 26 | 5 | 100 |  |  |  | 19 | $self->usage_error('Multiple URIs specified') if scalar @$args > 1; | 
| 27 | 4 | 100 | 100 |  |  | 12 | $self->usage_error('Unknown SVG Profile') if $opt->profile && !grep {;$_ eq $opt->profile} @Mail::BIMI::Indicator::VALIDATOR_PROFILES; | 
|  | 6 |  |  |  |  | 35 |  | 
| 28 |  |  |  |  |  |  | } | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 3 |  |  | 3 | 1 | 30 | sub execute($self,$opt,$args) { | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 6 |  | 
| 31 | 3 |  |  |  |  | 6 | my $uri = $args->[0]; | 
| 32 | 3 |  |  |  |  | 20 | my $bimi = Mail::BIMI->new(domain=>'example.com'); | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 3 |  |  |  |  | 8944 | my %bimi_opt = ( | 
| 35 |  |  |  |  |  |  | bimi_object => $bimi, | 
| 36 |  |  |  |  |  |  | ); | 
| 37 | 3 | 100 |  |  |  | 12 | if ( $opt->fromfile ) { | 
| 38 | 2 |  |  |  |  | 14 | my $data = scalar read_file($uri); | 
| 39 | 2 |  |  |  |  | 229 | $bimi_opt{data} = $data; | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  | else { | 
| 42 | 1 |  |  |  |  | 6 | $bimi_opt{uri} = $uri; | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 3 |  |  |  |  | 30 | my $indicator = Mail::BIMI::Indicator->new(%bimi_opt); | 
| 46 | 3 | 100 |  |  |  | 11 | $indicator->validator_profile($opt->profile) if $opt->profile; | 
| 47 | 3 |  |  |  |  | 21 | say "BIMI SVG checker"; | 
| 48 | 3 |  |  |  |  | 50 | say ''; | 
| 49 | 3 |  |  |  |  | 34 | say 'Requested:'; | 
| 50 | 3 | 100 |  |  |  | 79 | say YELLOW.($opt->fromfile?'File':'URI').WHITE.': '.$uri.RESET; | 
| 51 | 3 |  |  |  |  | 187 | say ''; | 
| 52 | 3 |  |  |  |  | 39 | $indicator->app_validate; | 
| 53 | 3 |  |  |  |  | 9 | say ''; | 
| 54 |  |  |  |  |  |  |  | 
| 55 | 3 |  |  |  |  | 39 | $bimi->finish; | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | 1; | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | __END__ | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | =pod | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | =encoding UTF-8 | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | =head1 NAME | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | Mail::BIMI::App::Command::checksvg - Check an SVG for validation | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | =head1 VERSION | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | version 3.20210301 | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | App::Cmd class implementing the 'mailbimi checksvg' command | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | =head1 REQUIRES | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | =over 4 | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | =item * L<File::Slurp|File::Slurp> | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | =item * L<Mail::BIMI|Mail::BIMI> | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | =item * L<Mail::BIMI::App|Mail::BIMI::App> | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | =item * L<Mail::BIMI::Indicator|Mail::BIMI::Indicator> | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | =item * L<Mail::BIMI::Prelude|Mail::BIMI::Prelude> | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | =item * L<Term::ANSIColor|Term::ANSIColor> | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | =back | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | =head1 AUTHOR | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | Marc Bradshaw <marc@marcbradshaw.net> | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | This software is copyright (c) 2020 by Marc Bradshaw. | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | This is free software; you can redistribute it and/or modify it under | 
| 105 |  |  |  |  |  |  | the same terms as the Perl 5 programming language system itself. | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | =cut |