BodyMunger.pm

filter: Statementstmt 72.0% 36 / 50 Branchbran 33.3% 8 / 24 Conditioncond 50.0% 2 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 77.7% 7 / 9 Podpod 100% 2 / 2 totaltotal 61.5% 56 / 91 SCAR 36.1
CC
17
Cov
59%
rewrite_content
72.0
rewrite_lines
10.2
__ANON__
2.0
CRAP 37.0
↑ Summary Visitor.pm »
1 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package MIME::BodyMunger;
4 {
5 4 $MIME::BodyMunger::VERSION = '0.006';
6 }
7 # ABSTRACT: rewrite the content of text parts, minding charset
8  
9 4 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Variable::Magic ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 sub rewrite_content {
15 0 ▶ my ($self, $entity, $code) = @_;
Subroutine rewrite_content: not called CC=8 SCAR=42.8
Pod documented
16  
17 0 ▶ Carp::confess "rewrite_content called on non-text part"
Branch: 1 branch
BranchTrueFalseTotal
unless $entity->effective_type =~ qr"\Atext/(?:html|plain)(?:$|;)"i 0 0 0
18 unless $entity->effective_type =~ qr{\Atext/(?:html|plain)(?:$|;)}i;
19  
20 0 ▶ my $charset = $entity->head->mime_attr('content-type.charset')
Condition0%0/2
$entity->head->mime_attr('content-type.charset') || 'ISO-8859-1'
l!l
00
MC/DC0%0/1
$entity->head->mime_attr('content-type.charset') || 'ISO-8859-1'
$entity->head->mime_attr('content-type.charset')
Truth table0%0/2
A
A= $entity->head->mime_attr('content-type.charset')
Aresult
11
00
21 || 'ISO-8859-1';
22  
23 0 ▶ $charset = 'MacRoman' if lc $charset eq 'macintosh';
Branch: 1 branch
BranchTrueFalseTotal
if lc $charset eq "macintosh" 0 0 0
24  
25 0 ▶ Carp::carp(qq{rewriting message in unknown charset "$charset"})
Branch: 1 branch
BranchTrueFalseTotal
unless my $known_charset = &Encode::find_encoding($charset) 0 0 0
26 unless my $known_charset = Encode::find_encoding($charset);
27  
28 0 my $changed = 0;
29 0 ▶ my $got_set = Variable::Magic::wizard(set => sub { $changed = 1 });
Subroutine __ANON__: not called CC=1 SCAR=6.9
30  
31 0 ▶ my $body = $known_charset
Branch: 1 branch
BranchTrueFalseTotal
$known_charset ? : 0 0 0
32 ? Encode::decode($charset, $entity->bodyhandle->as_string)
33 : $entity->bodyhandle->as_string;
34  
35 0 Variable::Magic::cast($body, $got_set);
36 0 $code->(\$body, $entity);
37  
38 0 ▶ if ($changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($changed) 0 0 0
39 0 my $io = $entity->open('w');
40 0 ▶ $io->print($known_charset ? Encode::encode($charset, $body) : $body);
Branch: 1 branch
BranchTrueFalseTotal
$known_charset ? : 0 0 0
41 }
42 }
43  
44  
45 sub rewrite_lines {
46 8 ▶ my ($self, $entity, $code) = @_;
Subroutine rewrite_lines: called CC=10 SCAR=23.2
Pod documented
47  
48 8 ▶ Carp::confess "rewrite_lines called on non-text part"
Branch: 1 branch
BranchTrueFalseTotal
unless $entity->effective_type =~ qr"\Atext/(?:html|plain)(?:$|;)"i 0 8 8
49 unless $entity->effective_type =~ qr{\Atext/(?:html|plain)(?:$|;)}i;
50  
51 8 ▶ my $charset = $entity->head->mime_attr('content-type.charset')
Condition100%2/2
$entity->head->mime_attr('content-type.charset') || 'ISO-8859-1'
l!l
71
MC/DC100%1/1
$entity->head->mime_attr('content-type.charset') || 'ISO-8859-1'
$entity->head->mime_attr('content-type.charset')
Truth table100%2/2
A
A= $entity->head->mime_attr('content-type.charset')
Aresult
11
00
52 || 'ISO-8859-1';
53  
54 8 ▶ $charset = 'MacRoman' if lc $charset eq 'macintosh';
Branch: 1 branch
BranchTrueFalseTotal
if lc $charset eq "macintosh" 1 7 8
55  
56 8 ▶ Carp::carp(qq{rewriting message in unknown charset "$charset"})
Branch: 1 branch
BranchTrueFalseTotal
unless my $known_charset = &Encode::find_encoding($charset) 0 8 8
57 unless my $known_charset = Encode::find_encoding($charset);
58  
59 8 my $changed = 0;
60 8 ▶ my $got_set = Variable::Magic::wizard(set => sub { $changed = 1 });
Subroutine __ANON__: called CC=1 SCAR=0.0
61  
62 8 my @lines = $entity->bodyhandle->as_lines;
63  
64 8 for my $line (@lines) {
65 13 ▶ local $_ = $known_charset ? Encode::decode($charset, $line) : $line;
Branch: 1 branch
BranchTrueFalseTotal
$known_charset ? : 13 0 13
66 13 Variable::Magic::cast($_, $got_set);
67 13 $code->(\$_, $entity);
68 13 Variable::Magic::dispell($_, $got_set);
69 13 $line = $_;
70 };
71  
72 8 ▶ if ($changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($changed) 7 1 8
73 7 my $io = $entity->open('w');
74 7 ▶ $io->print($known_charset ? Encode::encode($charset, $_) : $_) for @lines;
Branch: 1 branch
BranchTrueFalseTotal
$known_charset ? : 13 0 13
75 }
76 }
77  
78  
79 4 1;
80  
81 __END__
↑ Summary Visitor.pm »