| 1 | package Courriel::Part::Single; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 7 | our $VERSION = '0.49'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use Courriel::Header::Disposition; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use Courriel::Types qw( NonEmptyStr StringRef ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use Email::MIME::Encodings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use Encode qw( decode encode ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use MIME::Base64 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 7 | ▶ | use MIME::QuotedPrint (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 7 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 7 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 7 | with 'Courriel::Role::Part'; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 7 | has content_ref => ( | |||||||||||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||||||||||
| 23 | isa => StringRef, | ||||||||||||||||||||||||||||
| 24 | coerce => 1, | ||||||||||||||||||||||||||||
| 25 | init_arg => 'content', | ||||||||||||||||||||||||||||
| 26 | lazy => 1, | ||||||||||||||||||||||||||||
| 27 | builder => '_build_content_ref', | ||||||||||||||||||||||||||||
| 28 | predicate => '_has_content_ref', | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 7 | has encoded_content_ref => ( | |||||||||||||||||||||||||||
| 32 | is => 'ro', | ||||||||||||||||||||||||||||
| 33 | isa => StringRef, | ||||||||||||||||||||||||||||
| 34 | coerce => 1, | ||||||||||||||||||||||||||||
| 35 | init_arg => 'encoded_content', | ||||||||||||||||||||||||||||
| 36 | lazy => 1, | ||||||||||||||||||||||||||||
| 37 | builder => '_build_encoded_content_ref', | ||||||||||||||||||||||||||||
| 38 | predicate => '_has_encoded_content_ref', | ||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 7 | has disposition => ( | |||||||||||||||||||||||||||
| 42 | is => 'ro', | ||||||||||||||||||||||||||||
| 43 | isa => 'Courriel::Header::Disposition', | ||||||||||||||||||||||||||||
| 44 | lazy => 1, | ||||||||||||||||||||||||||||
| 45 | builder => '_build_disposition', | ||||||||||||||||||||||||||||
| 46 | predicate => '_has_disposition', | ||||||||||||||||||||||||||||
| 47 | handles => [qw( is_attachment is_inline filename )], | ||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 7 | has encoding => ( | |||||||||||||||||||||||||||
| 51 | is => 'rw', | ||||||||||||||||||||||||||||
| 52 | writer => '_set_encoding', | ||||||||||||||||||||||||||||
| 53 | isa => NonEmptyStr, | ||||||||||||||||||||||||||||
| 54 | lazy => 1, | ||||||||||||||||||||||||||||
| 55 | default => '8bit', | ||||||||||||||||||||||||||||
| 56 | predicate => '_has_encoding', | ||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 118 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=6 SCAR=18.4
| |||||||||||||||||||||||||||||
| 60 | 118 | my $self = shift; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 118 | ▶ | unless ( $self->_has_content_ref || $self->_has_encoded_content_ref ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->_has_content_ref or $self->_has_encoded_content_ref
MC/DC0%0/2
$self->_has_content_ref or $self->_has_encoded_content_ref
$self->_has_content_ref
$self->_has_encoded_content_ref
Truth table66%2/3
A or B
A= $self->_has_content_refB= $self->_has_encoded_content_ref
| |||||||||||||||||||||||||||||
| 63 | 0 | die | |||||||||||||||||||||||||||
| 64 | 'You must provide a content or encoded_content parameter when constructing a Courriel::Part::Single object.'; | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 118 | ▶ | if ( !$self->_has_encoding ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 110 | my @enc = $self->headers->get('Content-Transfer-Encoding'); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 110 | ▶ | $self->_set_encoding( $enc[0]->value ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@enc and $enc[0]
MC/DC50%1/2
@enc and $enc[0]
@enc
$enc[0]
Truth table66%2/3
A and B
A= @encB= $enc[0]
| |||||||||||||||||||||||||||||
| 71 | if @enc && $enc[0]; | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 118 | $self->_sync_headers_with_self; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 118 | return; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1 | ▶ | after _set_headers => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 80 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 1 | $self->_sync_headers_with_self; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 1 | return; | |||||||||||||||||||||||||||
| 85 | 7 | }; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 119 | ▶ | sub _sync_headers_with_self { | ||||||||||||||||||||||||||
|
Subroutine
_sync_headers_with_self: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 88 | 119 | my $self = shift; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 119 | $self->_maybe_set_disposition_in_headers; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 119 | $self->headers->replace( 'Content-Transfer-Encoding' => $self->encoding ); | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 119 | return; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 119 | ▶ | sub _maybe_set_disposition_in_headers { | ||||||||||||||||||||||||||
|
Subroutine
_maybe_set_disposition_in_headers: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 98 | 119 | my $self = shift; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 119 | ▶ | return unless $self->_has_disposition; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 2 | $self->headers->replace( 'Content-Disposition' => $self->disposition ); | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||
| 106 | 7 | my $fake_disp = Courriel::Header::Disposition->new_from_value( | |||||||||||||||||||||||||||
| 107 | name => 'Content-Disposition', | ||||||||||||||||||||||||||||
| 108 | value => 'inline', | ||||||||||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 3 | ▶ | sub _build_disposition { | ||||||||||||||||||||||||||
|
Subroutine
_build_disposition: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||
| 112 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 3 | my @disp = $self->headers->get('Content-Disposition'); | |||||||||||||||||||||||||||
| 115 | 3 | ▶ | if ( @disp > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | die | |||||||||||||||||||||||||||
| 117 | 'This email defines more than one Content-Disposition header.'; | ||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 3 | ▶ | return $disp[0] // $fake_disp; | ||||||||||||||||||||||||||
|
Condition66%2/3
$disp[0] // $fake_disp
MC/DC0%0/2
$disp[0] // $fake_disp
$disp[0]
$fake_disp
Truth table66%2/3
A // B
A= $disp[0]B= $fake_disp
| |||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | sub is_multipart {0} | ||||||||||||||||||||||||||
|
Subroutine
is_multipart: not called CC=1 SCAR=1.2
Pod
documented
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | { | ||||||||||||||||||||||||||||
| 127 | 7 | my %unencoded = map { $_ => 1 } qw( 7bit 8bit binary ); | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 9 | ▶ | sub _build_content_ref { | ||||||||||||||||||||||||||
|
Subroutine
_build_content_ref: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 130 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 9 | my $encoding = $self->encoding; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | my $bytes | ||||||||||||||||||||||||||||
| 135 | 9 | ▶ | = $unencoded{ lc $encoding } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | ? $self->encoded_content | ||||||||||||||||||||||||||||
| 137 | : Email::MIME::Encodings::decode( | ||||||||||||||||||||||||||||
| 138 | $encoding, | ||||||||||||||||||||||||||||
| 139 | $self->encoded_content, | ||||||||||||||||||||||||||||
| 140 | ); | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 9 | ▶ | return \$bytes if $self->content_type->is_binary; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 4 | ▶ | return \$bytes | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | if lc $self->content_type->charset eq 'unknown-8bit'; | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | return \( | ||||||||||||||||||||||||||||
| 148 | 3 | decode( | |||||||||||||||||||||||||||
| 149 | $self->content_type->charset, | ||||||||||||||||||||||||||||
| 150 | $bytes, | ||||||||||||||||||||||||||||
| 151 | ) | ||||||||||||||||||||||||||||
| 152 | ); | ||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 4 | ▶ | sub _build_encoded_content_ref { | ||||||||||||||||||||||||||
|
Subroutine
_build_encoded_content_ref: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 156 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 4 | my $encoding = $self->encoding; | |||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 4 | ▶ | my $bytes = $self->content_type->is_binary ? $self->content : encode( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | $self->content_type->charset, | ||||||||||||||||||||||||||||
| 162 | $self->content, | ||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 4 | ▶ | return \$bytes if $unencoded{ lc $encoding }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | return \( | ||||||||||||||||||||||||||||
| 168 | 2 | Email::MIME::Encodings::encode( | |||||||||||||||||||||||||||
| 169 | $encoding, | ||||||||||||||||||||||||||||
| 170 | $bytes, | ||||||||||||||||||||||||||||
| 171 | ) | ||||||||||||||||||||||||||||
| 172 | ); | ||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 7 | ▶ | sub content { | ||||||||||||||||||||||||||
|
Subroutine
content: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 177 | 13 | return ${ $_[0]->content_ref }; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 13 | ▶ | sub encoded_content { | ||||||||||||||||||||||||||
|
Subroutine
encoded_content: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 181 | 13 | return ${ $_[0]->encoded_content_ref }; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) | ||||||||||||||||||||||||||||
| 185 | 0 | ▶ | sub _stream_content { | ||||||||||||||||||||||||||
|
Subroutine
_stream_content: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 186 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 187 | 0 | my $output = shift; | |||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 0 | return $output->( $self->encoded_content ); | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | ## use critic | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 7 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 7 | 1; | |||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | # ABSTRACT: A part which does not contain other parts, only content | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | __END__ | ||||||||||||||||||||||||||||