Message/Field/Structured.pm

filter: Statementstmt 93.2% 83 / 89 Branchbran 83.3% 25 / 30 Conditioncond 81.2% 13 / 16 MC/DCmcdc 50.0% 5 / 10 Subroutinesub 93.3% 14 / 15 Podpod 88.8% 8 / 9 totaltotal 87.5% 148 / 169 CC 23 SCAR 20.6
CC
23
Cov
90%
parse
15.1
init
7.3
attribute
3.0
CRAP 7.8
« Message/Field/Addresses.pm ↑ Summary Message/Construct/Rebuild.pm »
1 # This code is part of Perl distribution Mail-Message version 4.05.
2 # The POD got stripped from this file by OODoc version 3.06.
3 # For contributors see file ChangeLog.
4  
5 # This software is copyright (c) 2001-2026 by Mark Overmeer.
6  
7 # This is free software; you can redistribute it and/or modify it under
8 # the same terms as the Perl 5 programming language system itself.
9 # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10  
11  
12 package Mail::Message::Field::Structured;{
13 28 our $VERSION = '4.05';
14 }
15  
16 28 ▶use parent 'Mail::Message::Field::Full';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 28 ▶use Log::Report 'mail-message', import => [ qw// ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 28 ▶use Mail::Message::Field::Attribute ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 28 ▶use Storable qw/dclone/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 #--------------------
27  
28 sub init($)
29 158 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=5 SCAR=19.8
Pod undocumented
30 158 $self->{MMFS_attrs} = {};
31 158 $self->{MMFS_datum} = $args->{datum};
32  
33 158 $self->SUPER::init($args);
34  
35 158 ▶ my $attr = $args->{attributes} || [];
Condition50%1/2
$args->{'attributes'} || []
l!l
0158
MC/DC0%0/1
$args->{'attributes'} || []
$args->{'attributes'}
Truth table50%1/2
A
A= $args->{'attributes'}
Aresult
11
00
36 158 ▶ $attr = [ %$attr ] if ref $attr eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $attr eq "HASH" 0 158 158
37  
38 158 ▶ while(@$attr)
Branch: 1 branch
BranchTrueFalseTotal
if (@$attr) 0 158 158
39 0 { my $name = shift @$attr;
40 0 ▶ if(ref $name) { $self->attribute($name) }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $name) { } 0 0 0
41 0 else { $self->attribute($name, shift @$attr) }
42 }
43  
44 158 $self;
45 }
46  
47 195 ▶sub clone() { dclone(shift) }
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
48  
49 #--------------------
50  
51 sub attribute($;$)
52 320 ▶{ my ($self, $attr) = (shift, shift);
Subroutine attribute: called CC=3 SCAR=11.0
Pod documented
53 320 my $name;
54 320 ▶ if(ref $attr) { $name = $attr->name }
Branch: 2 branches
BranchTrueFalseTotal
if (ref $attr) { } 77 243 320
elsif (not @_) { } 200 43 243
55 200 elsif( !@_ ) { return $self->{MMFS_attrs}{lc $attr} }
56 else
57 43 { $name = $attr;
58 43 $attr = Mail::Message::Field::Attribute->new($name, @_);
59 }
60  
61 120 delete $self->{MMFF_body};
62 120 $self->{MMFS_attrs}{lc $name} = $attr;
63 }
64  
65  
66 2 ▶sub attributes() { values %{$_[0]->{MMFS_attrs}} }
Subroutine attributes: called CC=1 SCAR=0.0
Pod documented
67 7 ▶sub beautify() { delete $_[0]->{MMFF_body} }
Subroutine beautify: called CC=1 SCAR=0.0
Pod documented
68  
69  
70 0 ▶sub attrPairs() { map +($_->name, $_->value), $_[0]->attributes }
Subroutine attrPairs: not called CC=1 SCAR=6.9
Pod documented
71  
72 #--------------------
73  
74 sub parse($)
75 93 ▶{ my ($self, $string) = @_;
Subroutine parse: called CC=15 SCAR=27.1
Pod documented
76  
77 93 for($string)
78 { # remove FWS, even within quoted strings
79 93 s/\r?\n(\s)/$1/gs;
80 93 s/\r?\n/ /gs;
81 93 s/\s+$//;
82 }
83  
84 93 my $datum = '';
85 93 ▶ while(length $string && substr($string, 0, 1) ne ';')
Branch: 1 branch
BranchTrueFalseTotal
if (length $string and substr($string, 0, 1) ne ";") 105 93 198
Condition100%3/3
length $string and substr($string, 0, 1) ne ";"
!ll&&!rl&&r
1875105
MC/DC100%2/2
length $string and substr($string, 0, 1) ne ";"
length $string substr($string, 0, 1) ne ";"
Truth table100%3/3
A and B
A= length $stringB= substr($string, 0, 1) ne ";"
ABresult
0X0
100
111
86 105 { (undef, $string) = $self->consumeComment($string);
87 105 ▶ $datum .= $1 if $string =~ s/^([^;(]+)//;
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ s/^([^;(]+)// 98 7 105
88 }
89 93 $self->{MMFS_datum} = $datum;
90  
91 93 my $found = '';
92 93 ▶ while($string =~ m/\S/)
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /\S/) 157 93 250
93 157 { my $len = length $string;
94  
95 157 ▶ if($string =~ s/^\s*\;\s*// && length $found)
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ s/^\s*\;\s*// and length $found) 5 152 157
Condition100%3/3
$string =~ s/^\s*\;\s*// and length $found
!ll&&!rl&&r
77755
MC/DC100%2/2
$string =~ s/^\s*\;\s*// and length $found
$string =~ s/^\s*\;\s*// length $found
Truth table100%3/3
A and B
A= $string =~ s/^\s*\;\s*//B= length $found
ABresult
0X0
100
111
96 5 { my ($name) = $found =~ m/^([^*]+)\*/;
97 5 ▶ if($name && (my $cont = $self->attribute($name)))
Branch: 1 branch
BranchTrueFalseTotal
if ($name and my $cont = $self->attribute($name)) { } 1 4 5
Condition66%2/3
$name and my $cont = $self->attribute($name)
!ll&&!rl&&r
230
MC/DC0%0/2
$name and my $cont = $self->attribute($name)
$name my $cont = $self->attribute($name)
Truth table66%2/3
A and B
A= $nameB= my $cont = $self->attribute($name)
ABresult
0X0
100
111
98 1 { $cont->addComponent($found); # continuation
99 }
100 else
101 4 { my $attr = Mail::Message::Field::Attribute->new($found);
102 4 $self->attribute($attr);
103 }
104 5 $found = '';
105 }
106  
107 157 (undef, $string) = $self->consumeComment($string);
108 157 $string =~ s/^\n//;
109 157 (my $text, $string) = $self->consumePhrase($string);
110 157 ▶ $found .= $text if defined $text;
Branch: 1 branch
BranchTrueFalseTotal
if defined $text 156 1 157
111  
112 157 ▶ if(length($string) == $len)
Branch: 1 branch
BranchTrueFalseTotal
if (length $string == $len) 0 157 157
113 { # nothing consumed, remove character to avoid endless loop
114 0 $string =~ s/^\s*\S//;
115 }
116 }
117  
118 93 ▶ if(length $found)
Branch: 1 branch
BranchTrueFalseTotal
if (length $found) 75 18 93
119 75 { my ($name) = $found =~ m/^([^*]+)\*/;
120 75 ▶ if($name && (my $cont = $self->attribute($name)))
Branch: 1 branch
BranchTrueFalseTotal
if ($name and my $cont = $self->attribute($name)) { } 2 73 75
Condition66%2/3
$name and my $cont = $self->attribute($name)
!ll&&!rl&&r
7320
MC/DC0%0/2
$name and my $cont = $self->attribute($name)
$name my $cont = $self->attribute($name)
Truth table33%1/3
A and B
A= $nameB= my $cont = $self->attribute($name)
ABresult
0X0
100
111
121 2 { $cont->addComponent($found); # continuation
122 }
123 else
124 73 { my $attr = Mail::Message::Field::Attribute->new($found);
125 73 $self->attribute($attr);
126 }
127 }
128  
129 93 1;
130 }
131  
132 sub produceBody()
133 49 ▶{ my $self = shift;
Subroutine produceBody: called CC=2 SCAR=6.9
Pod documented
134 49 my $attrs = $self->{MMFS_attrs};
135 49 my $datum = $self->{MMFS_datum};
136  
137 join '; ', ($datum // ''),
138 49 ▶ map $_->string, @{$attrs}{sort keys %$attrs};
Condition100%2/2
$datum // ""
l!l
472
MC/DC100%1/1
$datum // ""
$datum
Truth table100%2/2
A
A= $datum
Aresult
11
00
139 }
140  
141  
142 sub datum(@)
143 2 ▶{ my $self = shift;
Subroutine datum: called CC=2 SCAR=6.9
Pod documented
144 2 ▶ @_ or return $self->{MMFS_datum};
Branch: 1 branch
BranchTrueFalseTotal
@_ or return $self->{"MMFS_datum"} 1 1 2
145 1 delete $self->{MMFF_body};
146 1 $self->{MMFS_datum} = shift;
147 }
148  
149 28 1;
« Message/Field/Addresses.pm ↑ Summary Message/Construct/Rebuild.pm »