lib/Mail/Make/Headers/ContentDisposition.pm

filter: Statementstmt 94.4% 85 / 90 Branchbran 68.4% 26 / 38 Conditioncond 52.3% 11 / 21 MC/DCmcdc 23.0% 3 / 13 Subroutinesub 100% 15 / 15 Podpod 100% 7 / 7 totaltotal 79.8% 147 / 184 CC 28 SCAR 19.9
CC
28
Cov
82%
filename
14.6
disposition
8.2
filename_charset
6.8
CRAP 7.3
« lib/MM/Table.pm ↑ Summary blib/lib/Mail/Make/Body/InCore.pm »
1 ##----------------------------------------------------------------------------
2 ## MIME Email Builder - ~/lib/Mail/Make/Headers/ContentDisposition.pm
3 ## Version v0.1.0
4 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2026/03/02
7 ## Modified 2026/03/02
8 ## All rights reserved.
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.
12 ##----------------------------------------------------------------------------
13 package Mail::Make::Headers::ContentDisposition;
14 BEGIN
15 {
16 10 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 10 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 10 ▶ warnings::register_categories( 'Mail::Make' );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 10 ▶ use parent qw( Mail::Make::Headers::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 10 ▶ use vars qw( $VERSION $EXCEPTION_CLASS $VALID_DISPOSITIONS );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 10 ▶ use Mail::Make::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 10 our $EXCEPTION_CLASS = 'Mail::Make::Exception';
23 10 our $VALID_DISPOSITIONS = qr/^(?:inline|attachment|form-data)$/i;
24 10 our $VERSION = 'v0.1.0';
25 };
26  
27 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 sub init
31 {
32 42 ▶ my $self = shift( @_ );
Subroutine init: called CC=6 SCAR=18.0
Pod documented
33 42 $self->{filename_charset} = undef;
34 42 $self->{filename_lang} = undef;
35 42 $self->{_exception_class} = $EXCEPTION_CLASS;
36 42 my $disposition = shift( @_ );
37 42 ▶ return( $self->error( "No value was provided for Content-Disposition field." ) )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $disposition and length "$disposition" 1 41 42
Condition66%2/3
defined $disposition and length "$disposition"
!ll&&!rl&&r
1041
MC/DC50%1/2
defined $disposition and length "$disposition"
defined $disposition length "$disposition"
Truth table66%2/3
A and B
A= defined $dispositionB= length "$disposition"
ABresult
0X0
100
111
38 if( !defined( $disposition ) || !length( "$disposition" ) );
39 41 my $params = $self->_get_args_as_hash( @_ );
40 41 my $debug = delete( $params->{debug} );
41 41 $self->debug( $debug );
42 41 ▶ $self->disposition( $disposition, ( scalar( %$params ) ? %$params : () ) ) || return( $self->pass_error );
Branch: 2 branches
BranchTrueFalseTotal
$self->disposition($disposition, scalar %$params ? %$params : ()) or return $self->pass_error 1 40 41
scalar %$params ? : 0 41 41
43 40 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 40 40
44 40 $self->_field_name( 'Content-Disposition' );
45 40 return( $self );
46 }
47  
48 33 ▶sub as_string { return( shift->_hv_as_string( [qw( filename )] ) ); }
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
49  
50 sub disposition
51 {
52 54 ▶ my $self = shift( @_ );
Subroutine disposition: called CC=8 SCAR=21.0
Pod documented
53 54 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 47 7 54
54 {
55 47 ▶ my $dispo = shift( @_ ) || return( $self->error( "No content disposition was provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No content disposition was provided.'))
l!l
470
MC/DC0%0/1
shift @_ || (return $self->error('No content disposition was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
56 47 ▶ unless( $dispo =~ $VALID_DISPOSITIONS )
Branch: 1 branch
BranchTrueFalseTotal
unless ($dispo =~ /$Mail::Make::Headers::ContentDisposition::VALID_DISPOSITIONS/) 2 45 47
57 {
58 2 return( $self->error( "Invalid disposition '$dispo': must be one of inline, attachment, form-data." ) );
59 }
60 45 my $params = $self->_get_args_as_hash( @_ );
61 45 $dispo = lc( $dispo );
62 45 my $hv = $self->_hv;
63 45 ▶ if( $hv )
Branch: 1 branch
BranchTrueFalseTotal
if ($hv) { } 5 40 45
64 {
65 5 $hv->value( $dispo );
66 }
67 else
68 {
69 40 ▶ $hv = $self->_parse_header_value( $dispo ) || return( $self->pass_error );
Condition50%1/2
$self->_parse_header_value($dispo) || (return $self->pass_error)
l!l
400
MC/DC0%0/1
$self->_parse_header_value($dispo) || (return $self->pass_error)
$self->_parse_header_value($dispo)
Truth table50%1/2
A
A= $self->_parse_header_value($dispo)
Aresult
11
00
70 40 $self->_hv( $hv );
71 }
72 45 ▶ $hv->params( $params ) if( scalar( keys( %$params ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %$params 0 45 45
73 45 return( $dispo );
74 }
75 else
76 {
77 7 ▶ my $hv = $self->_hv || return( '' );
Condition50%1/2
$self->_hv || (return '')
l!l
70
MC/DC0%0/1
$self->_hv || (return '')
$self->_hv
Truth table50%1/2
A
A= $self->_hv
Aresult
11
00
78 7 return( $hv->value_data );
79 }
80 }
81  
82 # Sets or gets the filename parameter.
83 # On assignment, applies RFC 2231 encoding automatically when the filename
84 # contains non-ASCII or RFC 2045 special characters (including commas).
85 # This is the fix for the MIME::Entity silent failure bug.
86 sub filename
87 {
88 34 ▶ my $self = shift( @_ );
Subroutine filename: called CC=11 SCAR=26.8
Pod documented
89 34 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 33 1 34
90 {
91 33 my( $fname, $lang ) = @_;
92 33 ▶ if( !defined( $fname ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fname) 1 32 33
93 {
94 # Remove both the plain and extended forms
95 1 my $hv = $self->_hv;
96 1 ▶ if( $hv )
Branch: 1 branch
BranchTrueFalseTotal
if ($hv) 1 0 1
97 {
98 1 $hv->params->delete( 'filename' );
99 1 $hv->params->delete( 'filename*' );
100 }
101 1 return( $self );
102 }
103 32 ▶ $lang //= $self->filename_lang;
Condition66%2/3
$lang //= $self->filename_lang
l!l&&r!l&&!r
0131
MC/DC50%1/2
$lang //= $self->filename_lang
$lang $self->filename_lang
Truth table66%2/3
A //= B
A= $langB= $self->filename_lang
ABresult
1X1
011
000
104 32 my $encoded = $self->_filename_encode( $fname, $lang );
105 32 ▶ if( defined( $encoded ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $encoded) { } 7 25 32
106 {
107 # Non-trivial filename: use RFC 2231 extended notation (filename*)
108 7 ▶ $self->_set_get_param( 'filename*' => $encoded ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_set_get_param("filename*", $encoded) or return $self->pass_error 0 7 7
109 }
110 else
111 {
112 # Pure safe ASCII: use plain quoted filename
113 25 $self->_set_get_qparam( filename => $fname );
114 }
115 32 return( $fname );
116 }
117 else
118 {
119 # Prefer filename* (RFC 2231) over plain filename
120 1 my $v = $self->_set_get_param( 'filename*' );
121 1 ▶ if( defined( $v ) && length( "$v" ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v and length "$v") 0 1 1
Condition33%1/3
defined $v and length "$v"
!ll&&!rl&&r
100
MC/DC0%0/2
defined $v and length "$v"
defined $v length "$v"
Truth table33%1/3
A and B
A= defined $vB= length "$v"
ABresult
0X0
100
111
122 {
123 0 my( $decoded, $charset, $lang ) = $self->_filename_decode( $v );
124 0 ▶ $self->filename_charset( $charset ) if( defined( $charset ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $charset 0 0 0
125 0 ▶ $self->filename_lang( $lang ) if( defined( $lang ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $lang 0 0 0
126 0 return( $decoded );
127 }
128 1 $v = $self->_set_get_qparam( 'filename' );
129 1 return( $v );
130 }
131 }
132  
133 sub filename_charset
134 {
135 2 ▶ my $self = shift( @_ );
Subroutine filename_charset: called CC=6 SCAR=19.2
Pod documented
136 2 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 0 2
137 {
138 2 my $v = shift( @_ );
139 2 ▶ if( defined( $v ) && length( $v ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v and length $v) 2 0 2
Condition33%1/3
defined $v and length $v
!ll&&!rl&&r
002
MC/DC0%0/2
defined $v and length $v
defined $v length $v
Truth table33%1/3
A and B
A= defined $vB= length $v
ABresult
0X0
100
111
140 {
141 2 ▶ if( lc( $v ) ne 'utf-8' && lc( $v ) ne 'utf8' )
Branch: 1 branch
BranchTrueFalseTotal
if (lc $v ne "utf-8" and lc $v ne "utf8") 1 1 2
Condition66%2/3
lc $v ne "utf-8" and lc $v ne "utf8"
!ll&&!rl&&r
101
MC/DC50%1/2
lc $v ne "utf-8" and lc $v ne "utf8"
lc $v ne "utf-8" lc $v ne "utf8"
Truth table66%2/3
A and B
A= lc $v ne "utf-8"B= lc $v ne "utf8"
ABresult
0X0
100
111
142 {
143 1 return( $self->error( "Only 'utf-8' is supported as filename charset." ) );
144 }
145 1 $v = 'UTF-8';
146 }
147 1 return( $self->_set_get_scalar_as_object( 'filename_charset', $v ) );
148 }
149 0 return( $self->_set_get_scalar_as_object( 'filename_charset' ) );
150 }
151  
152 33 ▶sub filename_lang { return( shift->_set_get_scalar_as_object( 'filename_lang', @_ ) ); }
Subroutine filename_lang: called CC=1 SCAR=0.0
Pod documented
153  
154 2 ▶sub name { return( shift->_set_get_param( name => @_ ) ); }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
155  
156 10 1;
157 # NOTE: POD
158 __END__
« lib/MM/Table.pm ↑ Summary blib/lib/Mail/Make/Body/InCore.pm »