Kit/Role/ManifestDesugarer.pm

filter: Statementstmt 100% 25 / 25 Branchbran 75.0% 3 / 4 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 97.3% 36 / 37 CC 6 SCAR 13.9
CC
6
Cov
97%
__ANON__
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.0
« Kit/Assembler/Standard.pm ↑ Summary Kit/Renderer/TestRenderer.pm »
1 package Email::MIME::Kit::Role::ManifestDesugarer 3.000007;
2 # ABSTRACT: helper for desugaring manifests
3  
4 6 ▶use v5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 #pod =head1 IMPLEMENTING
8 #pod
9 #pod This role also performs L<Email::MIME::Kit::Role::Component>.
10 #pod
11 #pod This is a role more likely to be consumed than implemented. It wraps C<around>
12 #pod the C<read_manifest> method in the consuming class, and "desugars" the contents
13 #pod of the loaded manifest before returning it.
14 #pod
15 #pod At present, desugaring is what allows the C<type> attribute in attachments and
16 #pod alternatives to be given instead of a C<content_type> entry in the
17 #pod C<attributes> entry. In other words, desugaring turns:
18 #pod
19 #pod {
20 #pod header => [ ... ],
21 #pod type => 'text/plain',
22 #pod }
23 #pod
24 #pod Into:
25 #pod
26 #pod {
27 #pod header => [ ... ],
28 #pod attributes => { content_type => 'text/plain' },
29 #pod }
30 #pod
31 #pod More behavior may be added to the desugarer later.
32 #pod
33 #pod =cut
34  
35 6 my $ct_desugar;
36 $ct_desugar = sub {
37 25 ▶ my ($self, $content) = @_;
Subroutine __ANON__: called CC=6 SCAR=17.9
38  
39 25 for my $thing (qw(alternatives attachments)) {
40 50 for my $part (@{ $content->{ $thing } }) {
41 17 ▶ my $headers = $part->{header} ||= [];
Condition100%2/2
$part->{"header"} ||= []
l!l
314
MC/DC100%1/1
$part->{"header"} ||= []
$part->{"header"}
Truth table100%2/2
A
A= $part->{"header"}
Aresult
11
00
42 17 ▶ if (my $type = delete $part->{type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = delete $part->{"type"}) 14 3 17
43 confess "specified both type and content_type attribute"
44 14 ▶ if $part->{attributes}{content_type};
Branch: 1 branch
BranchTrueFalseTotal
if $part->{"attributes"}{"content_type"} 0 14 14
45  
46 14 $part->{attributes}{content_type} = $type;
47 }
48  
49 17 $self->$ct_desugar($part);
50 }
51 }
52 6 };
53  
54 around read_manifest => sub {
55 8 ▶ my ($orig, $self, @args) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
56 8 my $content = $self->$orig(@args);
57  
58 8 $self->$ct_desugar($content);
59  
60 8 return $content;
61 6 };
62  
63 6 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 6 1;
65  
66 __END__
67  
68 =pod
69  
70 =encoding UTF-8
71  
72 =head1 NAME
73  
74 Email::MIME::Kit::Role::ManifestDesugarer - helper for desugaring manifests
75  
76 =head1 VERSION
77  
78 version 3.000007
79  
80 =head1 PERL VERSION
81  
82 This library should run on perls released even a long time ago. It should work
83 on any version of perl released in the last five years.
84  
85 Although it may work on older versions of perl, no guarantee is made that the
86 minimum required version will not be increased. The version may be increased
87 for any reason, and there is no promise that patches will be accepted to lower
88 the minimum required perl.
89  
90 =head1 IMPLEMENTING
91  
92 This role also performs L<Email::MIME::Kit::Role::Component>.
93  
94 This is a role more likely to be consumed than implemented. It wraps C<around>
95 the C<read_manifest> method in the consuming class, and "desugars" the contents
96 of the loaded manifest before returning it.
97  
98 At present, desugaring is what allows the C<type> attribute in attachments and
99 alternatives to be given instead of a C<content_type> entry in the
100 C<attributes> entry. In other words, desugaring turns:
101  
102 {
103 header => [ ... ],
104 type => 'text/plain',
105 }
106  
107 Into:
108  
109 {
110 header => [ ... ],
111 attributes => { content_type => 'text/plain' },
112 }
113  
114 More behavior may be added to the desugarer later.
115  
116 =head1 AUTHOR
117  
118 Ricardo Signes <rjbs@cpan.org>
119  
120 =head1 COPYRIGHT AND LICENSE
121  
122 This software is copyright (c) 2023 by Ricardo Signes.
123  
124 This is free software; you can redistribute it and/or modify it under
125 the same terms as the Perl 5 programming language system itself.
126  
127 =cut
« Kit/Assembler/Standard.pm ↑ Summary Kit/Renderer/TestRenderer.pm »