Message/Field/Structured.pm

filter: Statementstmt 93.1% 81 / 87 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.7% 149 / 166 CC 22 SCAR 19.8
CC
22
Cov
90%
parse
14.0
init
7.3
attribute
3.0
CRAP 7.2
« Message/Convert/Html.pm ↑ Summary Message/Field/Full.pm »
1 # Copyrights 2001-2022 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 23 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 23 $VERSION = '3.012';
12  
13 23 ▶use base 'Mail::Message::Field::Full';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 23 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 23 ▶use Mail::Message::Field::Attribute;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 23 ▶use Storable 'dclone';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21  
22 sub init($)
23 111 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=5 SCAR=19.8
Pod undocumented
24 111 $self->{MMFS_attrs} = {};
25 111 $self->{MMFS_datum} = $args->{datum};
26  
27 111 $self->SUPER::init($args);
28  
29 111 ▶ my $attr = $args->{attributes} || [];
Condition50%1/2
$args->{'attributes'} || []
l!l
0111
MC/DC0%0/1
$args->{'attributes'} || []
$args->{'attributes'}
Truth table50%1/2
A
A= $args->{'attributes'}
Aresult
11
00
30 111 ▶ $attr = [ %$attr ] if ref $attr eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $attr eq "HASH" 0 111 111
31  
32 111 ▶ while(@$attr)
Branch: 1 branch
BranchTrueFalseTotal
if (@$attr) 0 111 111
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 111 $self;
39 }
40  
41 181 ▶sub clone() { dclone(shift) }
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
42  
43 #------------------------------------------
44  
45  
46 sub attribute($;$)
47 298 ▶{ my ($self, $attr) = (shift, shift);
Subroutine attribute: called CC=3 SCAR=11.0
Pod documented
48 298 my $name;
49 298 ▶ if(ref $attr) { $name = $attr->name }
Branch: 2 branches
BranchTrueFalseTotal
if (ref $attr) { } 72 226 298
elsif (not @_) { } 186 40 226
50 186 elsif( !@_ ) { return $self->{MMFS_attrs}{lc $attr} }
51 else
52 40 { $name = $attr;
53 40 $attr = Mail::Message::Field::Attribute->new($name, @_);
54 }
55  
56 112 delete $self->{MMFF_body};
57 112 $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 78 ▶{ my ($self, $string) = @_;
Subroutine parse: called CC=14 SCAR=26.4
Pod documented
72  
73 # remove FWS, even within quoted strings
74 78 $string =~ s/\r?\n\s?/ /gs;
75 78 $string =~ s/ +$//;
76  
77 78 my $datum = '';
78 78 ▶ while(length $string && substr($string, 0, 1) ne ';')
Branch: 1 branch
BranchTrueFalseTotal
if (length $string and substr($string, 0, 1) ne ";") 80 78 158
Condition100%3/3
length $string and substr($string, 0, 1) ne ";"
!ll&&!rl&&r
87080
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
79 80 { (undef, $string) = $self->consumeComment($string);
80 80 ▶ $datum .= $1 if $string =~ s/^([^;(]+)//;
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ s/^([^;(]+)// 79 1 80
81 }
82 78 $self->{MMFS_datum} = $datum;
83  
84 78 my $found = '';
85 78 ▶ while($string =~ m/\S/)
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /\S/) 147 78 225
86 147 { my $len = length $string;
87  
88 147 ▶ if($string =~ s/^\s*\;\s*// && length $found)
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ s/^\s*\;\s*// and length $found) 5 142 147
Condition100%3/3
$string =~ s/^\s*\;\s*// and length $found
!ll&&!rl&&r
72705
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
89 5 { my ($name) = $found =~ m/^([^*]+)\*/;
90 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
91 1 { $cont->addComponent($found); # continuation
92 }
93 else
94 4 { my $attr = Mail::Message::Field::Attribute->new($found);
95 4 $self->attribute($attr);
96 }
97 5 $found = '';
98 }
99  
100 147 (undef, $string) = $self->consumeComment($string);
101 147 $string =~ s/^\n//;
102 147 (my $text, $string) = $self->consumePhrase($string);
103 147 ▶ $found .= $text if defined $text;
Branch: 1 branch
BranchTrueFalseTotal
if defined $text 146 1 147
104  
105 147 ▶ if(length($string) == $len)
Branch: 1 branch
BranchTrueFalseTotal
if (length $string == $len) 0 147 147
106 { # nothing consumed, remove character to avoid endless loop
107 0 $string =~ s/^\s*\S//;
108 }
109 }
110  
111 78 ▶ if(length $found)
Branch: 1 branch
BranchTrueFalseTotal
if (length $found) 70 8 78
112 70 { my ($name) = $found =~ m/^([^*]+)\*/;
113 70 ▶ if($name && (my $cont = $self->attribute($name)))
Branch: 1 branch
BranchTrueFalseTotal
if ($name and my $cont = $self->attribute($name)) { } 2 68 70
Condition66%2/3
$name and my $cont = $self->attribute($name)
!ll&&!rl&&r
6802
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
114 2 { $cont->addComponent($found); # continuation
115 }
116 else
117 68 { my $attr = Mail::Message::Field::Attribute->new($found);
118 68 $self->attribute($attr);
119 }
120 }
121  
122 78 1;
123 }
124  
125 sub produceBody()
126 46 ▶{ my $self = shift;
Subroutine produceBody: called CC=2 SCAR=6.9
Pod documented
127 46 my $attrs = $self->{MMFS_attrs};
128 46 my $datum = $self->{MMFS_datum};
129  
130 join '; '
131 , (defined $datum ? $datum : '')
132 46 ▶ , map {$_->string} @{$attrs}{sort keys %$attrs};
Branch: 1 branch
BranchTrueFalseTotal
defined $datum ? : 44 2 46
133 }
134  
135  
136 sub datum(@)
137 2 ▶{ my $self = shift;
Subroutine datum: called CC=2 SCAR=6.9
Pod documented
138 2 ▶ @_ or return $self->{MMFS_datum};
Branch: 1 branch
BranchTrueFalseTotal
@_ or return $self->{"MMFS_datum"} 1 1 2
139 1 delete $self->{MMFF_body};
140 1 $self->{MMFS_datum} = shift;
141 }
142  
143 23 1;
« Message/Convert/Html.pm ↑ Summary Message/Field/Full.pm »