blib/lib/Email/MIME.pm

filter: Statementstmt 98.5% 68 / 69 Branchbran 78.5% 11 / 14 Conditioncond 63.6% 7 / 11 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 100% 17 / 17 Podpod 0.0% 0 / 11 totaltotal 81.4% 105 / 129 CC 13 SCAR 9.6
CC
13
Cov
91%
body
5.5
debug_structure
4.0
fill_parts
3.0
CRAP 2.6
↑ Summary
1 package Email::MIME;
2 2 ▶use base 'Email::Simple';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use Email::MIME::ContentType;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Email::MIME::Encodings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 require 5.006;
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 our $VERSION = '1.0_01';
10  
11 sub new {
12 4 ▶ my $self = shift->SUPER::new(@_);
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
13 4 $self->{ct} = parse_content_type($self->content_type);
14 4 $self->parts;
15 4 return $self;
16 }
17  
18 sub parts {
19 10 ▶ my $self = shift;
Subroutine parts: called CC=2 SCAR=6.9
Pod undocumented
20 10 ▶ if (!$self->{parts}) { $self->fill_parts }
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"parts"}) 4 6 10
21 10 return @{$self->{parts}}
22 }
23  
24 sub fill_parts {
25 4 ▶ my $self = shift;
Subroutine fill_parts: called CC=3 SCAR=11.0
Pod undocumented
26 4 ▶ if ($self->{ct}{discrete} eq "multipart"
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'ct'}{'discrete'} eq 'multipart' or $self->{'ct'}{'discrete'} eq 'message') { } 1 3 4
Condition66%2/3
$self->{"ct"}{"discrete"} eq "multipart" or $self->{"ct"}{"discrete"} eq "message"
l!l&&r!l&&!r
103
MC/DC50%1/2
$self->{"ct"}{"discrete"} eq "multipart" or $self->{"ct"}{"discrete"} eq "message"
$self->{"ct"}{"discrete"} eq "multipart" $self->{"ct"}{"discrete"} eq "message"
Truth table66%2/3
A or B
A= $self->{"ct"}{"discrete"} eq "multipart"B= $self->{"ct"}{"discrete"} eq "message"
ABresult
1X1
011
000
27 or $self->{ct}{discrete} eq "message") {
28 1 $self->parts_multipart;
29 } else {
30 3 $self->parts_single_part;
31 }
32 4 return $self;
33 }
34  
35 sub body {
36 3 ▶ my $self = shift;
Subroutine body: called CC=5 SCAR=17.1
Pod undocumented
37 3 my $body = $self->{body};
38 3 my $cte = $self->header("Content-Transfer-Encoding");
39 3 ▶ return $body unless $cte;
Branch: 1 branch
BranchTrueFalseTotal
unless $cte 2 1 3
40 1 ▶ if (!$self->force_decode_hook and $cte =~ /^7bit|8bit|binary/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->force_decode_hook and $cte =~ /^7bit|8bit|binary/i) 0 1 1
Condition33%1/3
not $self->force_decode_hook and $cte =~ /^7bit|8bit|binary/i
!ll&&!rl&&r
010
MC/DC0%0/2
not $self->force_decode_hook and $cte =~ /^7bit|8bit|binary/i
not $self->force_decode_hook $cte =~ /^7bit|8bit|binary/i
Truth table33%1/3
not(A) and B
A= not $self->force_decode_hookB= $cte =~ /^7bit|8bit|binary/i
ABresult
0X0
100
111
41 0 return $body;
42 }
43  
44 1 ▶ $body = $self->decode_hook($body) if $self->can("decode_hook");
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("decode_hook") 1 0 1
45 # For S/MIME, etc.
46  
47 1 $body = Email::MIME::Encodings::decode( $cte, $body );
48 1 return $body;
49 }
50  
51 sub parts_single_part {
52 3 ▶ my $self = shift;
Subroutine parts_single_part: called CC=1 SCAR=0.0
Pod undocumented
53 3 $self->{parts} = [ $self ];
54 3 return $self;
55 }
56  
57 sub body_raw {
58 2 ▶ return $_[0]->{body_raw} || $_[0]->SUPER::body;
Subroutine body_raw: called CC=2 SCAR=7.2
Pod undocumented
Condition66%2/3
$_[0]{'body_raw'} || $_[0]->SUPER::body
l!l&&r!l&&!r
110
MC/DC0%0/2
$_[0]{'body_raw'} || $_[0]->SUPER::body
$_[0]{'body_raw'} $_[0]->SUPER::body
Truth table66%2/3
A || B
A= $_[0]{'body_raw'}B= $_[0]->SUPER::body
ABresult
1X1
011
000
59 }
60  
61 sub parts_multipart {
62 1 ▶ my $self = shift;
Subroutine parts_multipart: called CC=2 SCAR=6.9
Pod undocumented
63 1 my $boundary = $self->{ct}->{attributes}->{boundary};
64 1 $self->{body_raw} = $self->SUPER::body;
65 1 my @bits = split /^--\Q$boundary\E\s*$/sm, $self->body_raw;
66 1 delete $self->{body};
67  
68 # This might be a hack
69 1 ▶ $self->{body} = shift @bits if $bits[0] !~ /.*:.*/;
Branch: 1 branch
BranchTrueFalseTotal
unless $bits[0] =~ /.*:.*/ 1 0 1
70  
71 1 $self->{parts} = [ map { (ref $self)->new($_) } @bits ];
72 1 return @{$self->{parts}};
73  
74 }
75  
76 1 ▶sub force_decode_hook { 0 }
Subroutine force_decode_hook: called CC=1 SCAR=0.0
Pod undocumented
77 1 ▶sub decode_hook { return $_[1] }
Subroutine decode_hook: called CC=1 SCAR=0.0
Pod undocumented
78 7 ▶sub content_type { shift->header("Content-type"); }
Subroutine content_type: called CC=1 SCAR=0.0
Pod undocumented
79  
80 sub debug_structure {
81 3 ▶ my ($self, $level) = @_;
Subroutine debug_structure: called CC=4 SCAR=13.9
Pod undocumented
82 3 ▶ $level ||= 0;
Condition100%2/2
$level ||= 0
l!l
21
MC/DC100%1/1
$level ||= 0
$level
Truth table100%2/2
A
A= $level
Aresult
11
00
83 3 my $rv = " "x(5*$level);
84 3 $rv .= "+ ".$self->content_type."\n";
85 3 my @parts = $self->parts;
86 3 ▶ if (@parts > 1) { $rv .= $_->debug_structure($level +1) for @parts; }
Branch: 1 branch
BranchTrueFalseTotal
if (@parts > 1) 1 2 3
87 3 return $rv;
88 }
89  
90 2 1;
91  
92 __END__
↑ Summary