lib/Mail/DMARC/Report/URI.pm

filter: Statementstmt 95.5% 43 / 45 Branchbran 87.5% 21 / 24 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 3 totaltotal 86.6% 78 / 90 CC 18 SCAR 20.7
CC
18
Cov
91%
parse
11.6
get_size_limit
8.0
BEGIN
1.0
CRAP 7.9
« lib/Mail/DMARC/Report/Store/SQL.pm ↑ Summary lib/Mail/DMARC/Report/Aggregate.pm »
1 package Mail::DMARC::Report::URI;
2 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 17 our $VERSION = '2.20261110';
7  
8 17 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 17 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 56 ▶sub new($class) {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
12 56 return bless {}, $class;
13 }
14  
15 99 ▶sub parse( $self, $str = undef ) {
Subroutine parse: called CC=11 SCAR=24.5
Pod undocumented
16 99 ▶ $str or croak "URI string is required!";
Branch: 1 branch
BranchTrueFalseTotal
$str or croak("URI string is required!") 98 1 99
17  
18 98 my @valids = ();
19 98 foreach my $raw ( split /,/, $str ) {
20  
21 # warn "raw: $raw\n";
22 103 my ( $u, $size_f ) = split /!/, $raw;
23  
24 # #39: a bare address is a common slip for a mailto: URI
25 103 ▶ $u = "mailto:$u" if $u =~ m{^[^:/@]+@[^:/@]+$};
Branch: 1 branch
BranchTrueFalseTotal
if $u =~ m[^[^:/\@]+\@[^:/\@]+$] 1 102 103
26 103 my $bytes = $self->get_size_limit($size_f);
27 103 ▶ my $uri = URI->new($u) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $uri = "URI"->new($u) or do { carp("can't parse URI from $u"); next } 103 0 103
28 0 carp "can't parse URI from $u";
29 0 next;
30 };
31 103 ▶ my $scheme = $uri->scheme or next;
Branch: 1 branch
BranchTrueFalseTotal
my $scheme = $uri->scheme or next 103 0 103
32 103 ▶ if ( $scheme eq 'mailto' && lc substr( $u, 0, 7 ) eq 'mailto:' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scheme eq "mailto" and lc substr($u, 0, 7) eq "mailto:") 86 17 103
Condition66%2/3
$scheme eq "mailto" and lc substr($u, 0, 7) eq "mailto:"
!ll&&!rl&&r
17086
MC/DC50%1/2
$scheme eq "mailto" and lc substr($u, 0, 7) eq "mailto:"
$scheme eq "mailto" lc substr($u, 0, 7) eq "mailto:"
Truth table66%2/3
A and B
A= $scheme eq "mailto"B= lc substr($u, 0, 7) eq "mailto:"
ABresult
0X0
100
111
33 86 push @valids, { max_bytes => $bytes, uri => $uri };
34 86 next;
35 }
36 17 ▶ if ( $scheme =~ /^http(s)?/x && lc substr( $u, 0, 4 ) eq 'http' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scheme =~ /^http(s)?/x and lc substr($u, 0, 4) eq "http") 8 9 17
Condition66%2/3
$scheme =~ /^http(s)?/x and lc substr($u, 0, 4) eq "http"
!ll&&!rl&&r
908
MC/DC50%1/2
$scheme =~ /^http(s)?/x and lc substr($u, 0, 4) eq "http"
$scheme =~ /^http(s)?/x lc substr($u, 0, 4) eq "http"
Truth table66%2/3
A and B
A= $scheme =~ /^http(s)?/xB= lc substr($u, 0, 4) eq "http"
ABresult
0X0
100
111
37 8 push @valids, { max_bytes => $bytes, uri => $uri };
38 8 next;
39 }
40  
41 # print "invalid URI scheme: $scheme in $u\n";
42 # 12.1 Discovery - URI schemes found in "rua" tag that are not implemented by
43 # a Mail Receiver MUST be ignored.
44 }
45 98 return \@valids;
46 }
47  
48 111 ▶sub get_size_limit( $self, $size = undef ) {
Subroutine get_size_limit: called CC=8 SCAR=20.8
Pod undocumented
49 111 ▶ return 0 if !defined $size; # no limit
Branch: 1 branch
BranchTrueFalseTotal
unless defined $size 99 12 111
50 12 ▶ return $size if $size =~ /^\d+$/; # no units, raw byte count
Branch: 1 branch
BranchTrueFalseTotal
if $size =~ /^\d+$/ 1 11 12
51  
52 # 6.3 Formal Definition
53 # units are considered to be powers of two; a kilobyte is 2^10, a megabyte is 2^20,
54 11 my $unit = lc chop $size;
55 11 ▶ return $size * ( 2**10 ) if 'k' eq $unit;
Branch: 1 branch
BranchTrueFalseTotal
if "k" eq $unit 2 9 11
56 9 ▶ return $size * ( 2**20 ) if 'm' eq $unit;
Branch: 1 branch
BranchTrueFalseTotal
if "m" eq $unit 7 2 9
57 2 ▶ return $size * ( 2**30 ) if 'g' eq $unit;
Branch: 1 branch
BranchTrueFalseTotal
if "g" eq $unit 1 1 2
58 1 ▶ return $size * ( 2**40 ) if 't' eq $unit;
Branch: 1 branch
BranchTrueFalseTotal
if "t" eq $unit 0 1 1
59 1 croak "unrecognized unit ($unit) in size ($size)";
60 }
61  
62 17 1;
63  
64 __END__
« lib/Mail/DMARC/Report/Store/SQL.pm ↑ Summary lib/Mail/DMARC/Report/Aggregate.pm »