URI/mailto.pm

filter: Statementstmt 100% 54 / 54 Branchbran 92.8% 26 / 28 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 6 / 6 Podpod 33.3% 1 / 3 totaltotal 95.8% 93 / 97 CC 17 SCAR 18.7
CC
17
Cov
98%
to
9.0
headers
7.0
query_form
3.0
CRAP 6.5
« URI/_userpass.pm ↑ Summary URI/urn/isbn.pm »
1 package URI::mailto; # RFC 2368
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '5.40';
7  
8 2 ▶use parent qw(URI URI::_query);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 14 ▶sub to {
Subroutine to: called CC=9 SCAR=22.0
Pod undocumented
11 14 my $self = shift;
12 14 my @old = $self->headers;
13 14 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 11 14
14 3 my @new = @old;
15  
16 # get rid of any other to: fields
17 3 ▶ for (my $i = 0; $i < @new; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @new) 3 3 6
18 6 ▶ if (lc($new[$i] || '') eq "to") {
Branch: 1 branch
BranchTrueFalseTotal
if (lc($new[$i] || "") eq "to") 3 3 6
Condition100%2/2
$new[$i] || ''
l!l
33
MC/DC100%1/1
$new[$i] || ''
$new[$i]
Truth table100%2/2
A
A= $new[$i]
Aresult
11
00
19 3 splice(@new, $i, 2);
20 3 redo;
21 }
22 }
23  
24 3 my $to = shift;
25 3 ▶ $to = "" unless defined $to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $to 0 3 3
26 3 unshift(@new, "to" => $to);
27 3 $self->headers(@new);
28 }
29 14 ▶ return unless defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 2 12 14
30  
31 12 my @to;
32 12 ▶ while (@old) {
Branch: 1 branch
BranchTrueFalseTotal
if (@old) 15 12 27
33 15 my $h = shift @old;
34 15 my $v = shift @old;
35 15 ▶ push(@to, $v) if lc($h) eq "to";
Branch: 1 branch
BranchTrueFalseTotal
if lc $h eq "to" 12 3 15
36 }
37 12 join(",", @to);
38 }
39  
40  
41 20 ▶sub headers {
Subroutine headers: called CC=7 SCAR=19.5
Pod undocumented
42 20 my $self = shift;
43  
44 # The trick is to just treat everything as the query string...
45 20 my $opaque = "to=" . $self->opaque;
46 20 $opaque =~ s/\?/&/;
47  
48 20 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 16 20
49 4 my @new = @_;
50  
51 # strip out any "to" fields
52 4 my @to;
53 4 ▶ for (my $i = 0; $i < @new; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @new) 6 4 10
54 10 ▶ if (lc($new[$i] || '') eq "to") {
Branch: 1 branch
BranchTrueFalseTotal
if (lc($new[$i] || "") eq "to") 4 6 10
Condition100%2/2
$new[$i] || ''
l!l
73
MC/DC100%1/1
$new[$i] || ''
$new[$i]
Truth table100%2/2
A
A= $new[$i]
Aresult
11
00
55 4 push(@to, (splice(@new, $i, 2))[1]); # remove header
56 4 redo;
57 }
58 }
59  
60 4 my $new = join(",", @to);
61 4 $new =~ s/%/%25/g;
62 4 $new =~ s/\?/%3F/g;
63 4 $self->opaque($new);
64 4 ▶ $self->query_form(@new) if @new;
Branch: 1 branch
BranchTrueFalseTotal
if @new 1 3 4
65 }
66 20 ▶ return unless defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 4 16 20
67  
68 # I am lazy today...
69 16 URI->new("mailto:?$opaque")->query_form;
70 }
71  
72 # https://datatracker.ietf.org/doc/html/rfc6068#section-5 requires
73 # plus signs (+) not to be turned into spaces
74 17 ▶sub query_form {
Subroutine query_form: called CC=3 SCAR=11.0
Pod documented
75 17 my $self = shift;
76 17 my @fields = $self->SUPER::query_form(@_);
77 17 ▶ for (my $i = 0; $i < @fields; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @fields) 16 1 17
78 16 ▶ if ($fields[0] eq 'to') {
Branch: 1 branch
BranchTrueFalseTotal
if ($fields[0] eq "to") 16 0 16
79 16 $fields[1] =~ s/ /+/g;
80 16 last;
81 }
82 }
83 17 return @fields;
84 }
85  
86 2 1;
« URI/_userpass.pm ↑ Summary URI/urn/isbn.pm »