Courriel/Role/Part.pm

filter: Statementstmt 86.5% 45 / 52 Branchbran 75.0% 3 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 91.6% 11 / 12 Podpod n/a totaltotal 83.5% 61 / 73 CC 4 SCAR 5.0
CC
4
Cov
85%
_build_content_type
3.2
_maybe_set_content_type_in_headers
2.0
_stream_to
2.0
CRAP 1.6
« Courriel/Header/ContentType.pm ↑ Summary Courriel/Role/Streams.pm »
1 package Courriel::Role::Part;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 our $VERSION = '0.49';
8  
9 8 ▶use Courriel::Header::ContentType;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use Courriel::Header::Disposition;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Courriel::Types qw( NonEmptyStr );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 8 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 8 with 'Courriel::Role::Streams';
16  
17 8 requires qw( _stream_content );
18  
19 8 has headers => (
20 is => 'rw',
21 writer => '_set_headers',
22 does => 'Courriel::Headers',
23 required => 1,
24 );
25  
26 8 has container => (
27 is => 'rw',
28 writer => '_set_container',
29 isa => 'Courriel::Part::Multipart',
30 weak_ref => 1,
31 );
32  
33 8 has content_type => (
34 is => 'ro',
35 isa => 'Courriel::Header::ContentType',
36 lazy => 1,
37 builder => '_build_content_type',
38 predicate => '_has_content_type',
39 handles => [qw( mime_type charset has_charset )],
40 );
41  
42 158 ▶after BUILD => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
43 158 my $self = shift;
44  
45 158 $self->_maybe_set_content_type_in_headers;
46  
47 158 return;
48 8 };
49  
50 1 ▶after _set_headers => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
51 1 my $self = shift;
52  
53 1 $self->_maybe_set_content_type_in_headers;
54  
55 1 return;
56 8 };
57  
58 159 ▶sub _maybe_set_content_type_in_headers {
Subroutine _maybe_set_content_type_in_headers: called CC=2 SCAR=6.9
59 159 my $self = shift;
60  
61 159 ▶ return unless $self->_has_content_type;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_content_type 107 52 159
62  
63 52 $self->headers->replace( 'Content-Type' => $self->content_type );
64 }
65  
66 ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
67 0 ▶sub _stream_to {
Subroutine _stream_to: not called CC=1 SCAR=6.9
68 0 my $self = shift;
69 0 my $output = shift;
70  
71 0 $self->headers->stream_to( output => $output );
72 0 $output->($Courriel::Helpers::CRLF);
73 0 $self->_stream_content($output);
74  
75 0 return;
76 }
77 ## use critic;
78  
79 {
80 8 my $fake_ct = Courriel::Header::ContentType->new_from_value(
81 name => 'Content-Type',
82 value => 'text/plain'
83 );
84  
85 42 ▶ sub _build_content_type {
Subroutine _build_content_type: called CC=3 SCAR=11.8
86 42 my $self = shift;
87  
88 42 my @ct = $self->headers->get('Content-Type');
89 42 ▶ if ( @ct > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ct > 1) 0 42 42
90 0 die 'This part defines more than one Content-Type header.';
91 }
92  
93 42 ▶ return $ct[0] // $fake_ct;
Condition66%2/3
$ct[0] // $fake_ct
l!l&&r!l&&!r
3840
MC/DC0%0/2
$ct[0] // $fake_ct
$ct[0] $fake_ct
Truth table66%2/3
A // B
A= $ct[0]B= $fake_ct
ABresult
1X1
011
000
94 }
95 }
96  
97 8 1;
« Courriel/Header/ContentType.pm ↑ Summary Courriel/Role/Streams.pm »