Message/Field/Structured.pm

filter: Statementstmt 93.2% 83 / 89 Branchbran 84.3% 27 / 32 Conditioncond 85.7% 12 / 14 MC/DCmcdc 77.7% 7 / 9 Subroutinesub 93.3% 14 / 15 Podpod 88.8% 8 / 9 totaltotal 89.8% 151 / 168 SCAR 31.6
CC
23
Cov
90%
parse
15.0
init
7.3
attribute
3.0
CRAP 23.5
« Message/Convert/Html.pm ↑ Summary Message/Body/String.pm »
1 # Copyrights 2001-2023 by [Mark Overmeer <markov@cpan.org>].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.03.
5 # This code is part of distribution Mail-Message. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package Mail::Message::Field::Structured;
10 24 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 24 $VERSION = '3.013';
12  
13 24 ▶use base 'Mail::Message::Field::Full';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 24 ▶use Mail::Message::Field::Attribute;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 24 ▶use Storable 'dclone';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21  
22 sub init($)
23 117 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=5 SCAR=19.8
Pod undocumented
24 117 $self->{MMFS_attrs} = {};
25 117 $self->{MMFS_datum} = $args->{datum};
26  
27 117 $self->SUPER::init($args);
28  
29 117 ▶ my $attr = $args->{attributes} || [];
Condition50%1/2
$args->{'attributes'} || []
l!l
0117
MC/DC0%0/1
$args->{'attributes'} || []
$args->{'attributes'}
Truth table50%1/2
A
A= $args->{'attributes'}
Aresult
11
00
30 117 ▶ $attr = [ %$attr ] if ref $attr eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $attr eq "HASH" 0 117 117
31  
32 117 ▶ while(@$attr)
Branch: 1 branch
BranchTrueFalseTotal
if (@$attr) 0 117 117
33 0 { my $name = shift @$attr;
34 0 ▶ if(ref $name) { $self->attribute($name) }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $name) { } 0 0 0
35 0 else { $self->attribute($name, shift @$attr) }
36 }
37  
38 117 $self;
39 }
40  
41 199 ▶sub clone() { dclone(shift) }
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
42  
43 #------------------------------------------
44  
45  
46 sub attribute($;$)
47 320 ▶{ my ($self, $attr) = (shift, shift);
Subroutine attribute: called CC=3 SCAR=11.0
Pod documented
48 320 my $name;
49 320 ▶ if(ref $attr) { $name = $attr->name }
Branch: 2 branches
BranchTrueFalseTotal
if (ref $attr) { } 77 243 320
elsif (not @_) { } 200 43 243
50 200 elsif( !@_ ) { return $self->{MMFS_attrs}{lc $attr} }
51 else
52 43 { $name = $attr;
53 43 $attr = Mail::Message::Field::Attribute->new($name, @_);
54 }
55  
56 120 delete $self->{MMFF_body};
57 120 $self->{MMFS_attrs}{lc $name} = $attr;
58 }
59  
60  
61 2 ▶sub attributes() { values %{shift->{MMFS_attrs}} }
Subroutine attributes: called CC=1 SCAR=0.0
Pod documented
62 7 ▶sub beautify() { delete shift->{MMFF_body} }
Subroutine beautify: called CC=1 SCAR=0.0
Pod documented
63  
64  
65 0 ▶sub attrPairs() { map +($_->name, $_->value), shift->attributes }
Subroutine attrPairs: not called CC=1 SCAR=6.9
Pod documented
66  
67 #-------------------------
68  
69  
70 sub parse($)
71 83 ▶{ my ($self, $string) = @_;
Subroutine parse: called CC=15 SCAR=27.1
Pod documented
72  
73 83 for($string)
74 { # remove FWS, even within quoted strings
75 83 s/\r?\n(\s)/$1/gs;
76 83 s/\r?\n/ /gs;
77 83 s/\s+$//;
78 }
79  
80 83 my $datum = '';
81 83 ▶ while(length $string && substr($string, 0, 1) ne ';')
Branch: 1 branch
BranchTrueFalseTotal
if (length $string and substr($string, 0, 1) ne ";") 85 83 168
Condition100%3/3
length $string and substr($string, 0, 1) ne ";"
!ll&&!rl&&r
87585
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
82 85 { (undef, $string) = $self->consumeComment($string);
83 85 ▶ $datum .= $1 if $string =~ s/^([^;(]+)//;
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ s/^([^;(]+)// 84 1 85
84 }
85 83 $self->{MMFS_datum} = $datum;
86  
87 83 my $found = '';
88 83 ▶ while($string =~ m/\S/)
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /\S/) 157 83 240
89 157 { my $len = length $string;
90  
91 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
92 5 { my ($name) = $found =~ m/^([^*]+)\*/;
93 5 ▶ if($name && (my $cont = $self->attribute($name)))
Branch: 1 branch
BranchTrueFalseTotal
if ($name and my $cont = $self->attribute($name)) { } 1 4 5
Condition100%3/3
$name and my $cont = $self->attribute($name)
!ll&&!rl&&r
221
MC/DC100%2/2
$name and my $cont = $self->attribute($name)
$name my $cont = $self->attribute($name)
Truth table100%3/3
A and B
A= $nameB= my $cont = $self->attribute($name)
ABresult
0X0
100
111
94 1 { $cont->addComponent($found); # continuation
95 }
96 else
97 4 { my $attr = Mail::Message::Field::Attribute->new($found);
98 4 $self->attribute($attr);
99 }
100 5 $found = '';
101 }
102  
103 157 (undef, $string) = $self->consumeComment($string);
104 157 $string =~ s/^\n//;
105 157 (my $text, $string) = $self->consumePhrase($string);
106 157 ▶ $found .= $text if defined $text;
Branch: 1 branch
BranchTrueFalseTotal
if defined $text 156 1 157
107  
108 157 ▶ if(length($string) == $len)
Branch: 1 branch
BranchTrueFalseTotal
if (length $string == $len) 0 157 157
109 { # nothing consumed, remove character to avoid endless loop
110 0 $string =~ s/^\s*\S//;
111 }
112 }
113  
114 83 ▶ if(length $found)
Branch: 1 branch
BranchTrueFalseTotal
if (length $found) 75 8 83
115 75 { my ($name) = $found =~ m/^([^*]+)\*/;
116 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
7302
MC/DC50%1/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
117 2 { $cont->addComponent($found); # continuation
118 }
119 else
120 73 { my $attr = Mail::Message::Field::Attribute->new($found);
121 73 $self->attribute($attr);
122 }
123 }
124  
125 83 1;
126 }
127  
128 sub produceBody()
129 49 ▶{ my $self = shift;
Subroutine produceBody: called CC=2 SCAR=6.9
Pod documented
130 49 my $attrs = $self->{MMFS_attrs};
131 49 my $datum = $self->{MMFS_datum};
132  
133 join '; '
134 , (defined $datum ? $datum : '')
135 49 ▶ , map {$_->string} @{$attrs}{sort keys %$attrs};
Branch: 1 branch
BranchTrueFalseTotal
defined $datum ? : 47 2 49
136 }
137  
138  
139 sub datum(@)
140 2 ▶{ my $self = shift;
Subroutine datum: called CC=2 SCAR=6.9
Pod documented
141 2 ▶ @_ or return $self->{MMFS_datum};
Branch: 1 branch
BranchTrueFalseTotal
@_ or return $self->{"MMFS_datum"} 1 1 2
142 1 delete $self->{MMFF_body};
143 1 $self->{MMFS_datum} = shift;
144 }
145  
146 24 1;
« Message/Convert/Html.pm ↑ Summary Message/Body/String.pm »