Mail/Make/Stream/QuotedPrint.pm

filter: Statementstmt 78.9% 86 / 109 Branchbran 48.1% 26 / 54 Conditioncond 40.7% 11 / 27 MC/DCmcdc 6.2% 1 / 16 Subroutinesub 76.1% 16 / 21 Podpod 100% 7 / 7 totaltotal 62.8% 147 / 234 CC 37 SCAR 30.8
CC
37
Cov
65%
decode
41.6
encode
29.5
is_decoder_installed
6.0
CRAP 21.7
« Mail/Make/Stream.pm ↑ Summary Mail/Make/Headers.pm »
1 ##----------------------------------------------------------------------------
2 ## MIME Email Builder - ~/lib/Mail/Make/Stream/QuotedPrint.pm
3 ## Version v0.3.0
4 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2026/03/02
7 ## Modified 2026/03/05
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::Stream::QuotedPrint;
14 BEGIN
15 8 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 8 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 8 warnings::register_categories( 'Mail::Make' );
19 8 ▶ use Mail::Make::Stream;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 8 ▶ use parent -norequire, qw( Mail::Make::Stream::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 8 ▶ use vars qw( @EXPORT_OK $VERSION $EXCEPTION_CLASS $QuotedPrintError $DEBUG );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 8 ▶ use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 8 ▶ use Mail::Make::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 8 ▶ use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
25 8 ▶ use Module::Generic::File::IO;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 8 our @EXPORT_OK = qw( decode_qp encode_qp );
27 8 our $EXCEPTION_CLASS = 'Mail::Make::Exception';
28 8 our $VERSION = 'v0.3.1';
29 8 our $DEBUG = 0;
30 };
31  
32 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 # decode( $from, $to [, %opts] )
36 # Decodes QP data from $from line-by-line and writes raw bytes to $to.
37 sub decode
38 5 ▶{
Subroutine decode: called CC=15 SCAR=37.3
Pod documented
39 5 my $self = shift( @_ );
40 5 my $from = shift( @_ );
41 5 my $to = shift( @_ );
42 5 my $opts = $self->_get_args_as_hash( @_ );
43 5 my( $from_fh, $reader ) = $self->_get_glob_from_arg( $from );
44 5 my( $to_fh, $writer ) = $self->_get_glob_from_arg( $to, write => 1 );
45 5 ▶ return( $self->pass_error ) if( !defined( $from_fh ) || !defined( $to_fh ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $from_fh and defined $to_fh 0 5 5
Condition33%1/3
defined $from_fh and defined $to_fh
!ll&&!rl&&r
005
MC/DC0%0/2
defined $from_fh and defined $to_fh
defined $from_fh defined $to_fh
Truth table33%1/3
A and B
A= defined $from_fhB= defined $to_fh
ABresult
0X0
100
111
46 5 ▶ $self->_load_class( 'MIME::QuotedPrint', { no_import => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("MIME::QuotedPrint", {"no_import", 1}) or return $self->pass_error 5 0 5
47  
48 # Wrap the filehandle into an object that supports getline().
49 # Native in-memory handles (fileno = -1) already support readline(); do NOT attempt
50 # fdopen() on them: that call requires a real OS file descriptor.
51 5 ▶ unless( $self->_can( $from_fh => 'getline' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_can($from_fh, "getline")) 0 5 5
52 {
53 0 ▶ my $fd = $self->_can( $from_fh => 'fileno' ) ? $from_fh->fileno : fileno( $from_fh );
Branch: 1 branch
BranchTrueFalseTotal
$self->_can($from_fh, 'fileno') ? : 0 0 0
54 0 ▶ if( defined( $fd ) && $fd >= 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fd and $fd >= 0) 0 0 0
Condition0%0/3
defined $fd and $fd >= 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $fd and $fd >= 0
defined $fd $fd >= 0
Truth table0%0/3
A and B
A= defined $fdB= $fd >= 0
ABresult
0X0
100
111
55 {
56 0 my $io = Module::Generic::File::IO->new;
57 0 ▶ $io->fdopen( $fd, 'r' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$io->fdopen($fd, "r") or return $self->pass_error($io->error) 0 0 0
58 return( $self->pass_error( $io->error ) );
59 0 $from_fh = $io;
60 }
61 # else: native in-memory glob and readline() below works as-is
62 }
63  
64 5 my $buff;
65 5 ▶ while( defined( $buff = $self->_can( $from_fh => 'getline' ) ? $from_fh->getline : readline( $from_fh ) ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined($buff = $self->_can($from_fh, "getline") ? $from_fh->getline : readline $from_fh)) 5 5 10
$self->_can($from_fh, 'getline') ? : 10 0 10
66 {
67 5 my $decoded = MIME::QuotedPrint::decode_qp( $buff );
68 5 my $rv = $writer->( $decoded );
69 5 ▶ return( $self->pass_error ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 5 5
70 }
71 5 ▶ return( $self->pass_error( $from_fh->error ) )
Branch: 1 branch
BranchTrueFalseTotal
if not defined $buff and $self->_can($from_fh, "error") and $self->error 0 5 5
Condition33%2/6
not defined $buff and $self->_can($from_fh, "error") and $self->error
!ll&&!rl&&r
050
not defined $buff and $self->_can($from_fh, "error")
!ll&&!rl&&r
005
MC/DC0%0/3
not defined $buff and $self->_can($from_fh, "error") and $self->error
not defined $buff $self->_can($from_fh, "error") $self->error
Truth table25%1/4
not(A) and B and C
A= not defined $buffB= $self->_can($from_fh, "error")C= $self->error
ABCresult
0XX0
10X0
1100
1111
72 if( !defined( $buff ) && $self->_can( $from_fh => 'error' ) && $self->error );
73 5 return( $self );
74 }
75  
76 sub decode_qp
77 1 ▶{
Subroutine decode_qp: called CC=2 SCAR=7.6
Pod documented
78 1 my $s = __PACKAGE__->new( debug => $DEBUG );
79 1 my $rv = $s->decode( @_ );
80 1 ▶ if( !defined( $rv ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rv) { } 0 1 1
81 {
82 0 $QuotedPrintError = $s->error;
83 0 return( $s->pass_error );
84 }
85 else
86 {
87 1 undef( $QuotedPrintError );
88 1 return( $rv );
89 }
90 }
91  
92 # encode( $from, $to [, %opts] )
93 # Encodes raw data from $from as Quoted-Printable and writes to $to.
94 # Options:
95 # eol => $str line ending (default "\015\012")
96 sub encode
97 44 ▶{
Subroutine encode: called CC=19 SCAR=33.8
Pod documented
98 44 my $self = shift( @_ );
99 44 my $from = shift( @_ );
100 44 my $to = shift( @_ );
101 44 my $opts = $self->_get_args_as_hash( @_ );
102 44 my( $from_fh, $reader ) = $self->_get_glob_from_arg( $from );
103 44 my( $to_fh, $writer ) = $self->_get_glob_from_arg( $to, write => 1 );
104 44 ▶ return( $self->pass_error ) if( !defined( $from_fh ) || !defined( $to_fh ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $from_fh and defined $to_fh 0 44 44
Condition33%1/3
defined $from_fh and defined $to_fh
!ll&&!rl&&r
0044
MC/DC0%0/2
defined $from_fh and defined $to_fh
defined $from_fh defined $to_fh
Truth table33%1/3
A and B
A= defined $from_fhB= defined $to_fh
ABresult
0X0
100
111
105 44 ▶ $self->_load_class( 'MIME::QuotedPrint', { no_import => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("MIME::QuotedPrint", {"no_import", 1}) or return $self->pass_error 44 0 44
106  
107 # Wrap the filehandle into an object that supports getline().
108 # Native in-memory handles (fileno = -1) already support readline(); do NOT attempt
109 # fdopen() on them: that call requires a real OS file descriptor.
110 44 ▶ unless( $self->_can( $from_fh => 'getline' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_can($from_fh, "getline")) 42 2 44
111 {
112 42 ▶ my $fd = $self->_can( $from_fh => 'fileno' ) ? $from_fh->fileno : fileno( $from_fh );
Branch: 1 branch
BranchTrueFalseTotal
$self->_can($from_fh, 'fileno') ? : 0 42 42
113 42 ▶ if( defined( $fd ) && $fd >= 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fd and $fd >= 0) 0 42 42
Condition33%1/3
defined $fd and $fd >= 0
!ll&&!rl&&r
0420
MC/DC0%0/2
defined $fd and $fd >= 0
defined $fd $fd >= 0
Truth table33%1/3
A and B
A= defined $fdB= $fd >= 0
ABresult
0X0
100
111
114 {
115 0 my $io = Module::Generic::File::IO->new;
116 0 ▶ $io->fdopen( $fd, 'r' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$io->fdopen($fd, "r") or return $self->pass_error($io->error) 0 0 0
117 return( $self->pass_error( $io->error ) );
118 0 $from_fh = $io;
119 }
120 # else: native in-memory glob and readline() below works as-is
121 }
122 44 ▶ my $eol = ( exists( $opts->{eol} ) && defined( $opts->{eol} ) ) ? $opts->{eol} : "\015\012";
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'eol'} && defined $opts->{'eol'} ? : 1 43 44
Condition66%2/3
exists $opts->{"eol"} and defined $opts->{"eol"}
!ll&&!rl&&r
4301
MC/DC50%1/2
exists $opts->{"eol"} and defined $opts->{"eol"}
exists $opts->{"eol"} defined $opts->{"eol"}
Truth table66%2/3
A and B
A= exists $opts->{"eol"}B= defined $opts->{"eol"}
ABresult
0X0
100
111
123 44 my $has_eol = length( $eol );
124  
125 44 my $buff;
126 44 ▶ while( defined( $buff = $self->_can( $from_fh => 'getline' ) ? $from_fh->getline : readline( $from_fh ) ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined($buff = $self->_can($from_fh, "getline") ? $from_fh->getline : readline $from_fh)) 47 44 91
$self->_can($from_fh, 'getline') ? : 4 87 91
127 {
128 # Ensure the chunk is raw UTF-8 bytes, not Perl's internal representation
129 47 ▶ $buff = Encode::encode_utf8( $buff ) if( Encode::is_utf8( $buff ) );
Branch: 1 branch
BranchTrueFalseTotal
if &Encode::is_utf8($buff) 0 47 47
130 47 ▶ my $encoded = MIME::QuotedPrint::encode_qp( $buff, ( $has_eol ? ( $eol ) : () ) );
Branch: 1 branch
BranchTrueFalseTotal
$has_eol ? : 47 0 47
131 47 my $rv = $writer->( $encoded );
132 47 ▶ return( $self->pass_error ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 47 47
133 }
134 44 ▶ return( $self->pass_error( $from_fh->error ) )
Branch: 1 branch
BranchTrueFalseTotal
if not defined $buff and $self->_can($from_fh, "error") and $self->error 0 44 44
Condition66%4/6
not defined $buff and $self->_can($from_fh, "error") and $self->error
!ll&&!rl&&r
4220
not defined $buff and $self->_can($from_fh, "error")
!ll&&!rl&&r
0422
MC/DC0%0/3
not defined $buff and $self->_can($from_fh, "error") and $self->error
not defined $buff $self->_can($from_fh, "error") $self->error
Truth table50%2/4
not(A) and B and C
A= not defined $buffB= $self->_can($from_fh, "error")C= $self->error
ABCresult
0XX0
10X0
1100
1111
135 if( !defined( $buff ) && $self->_can( $from_fh => 'error' ) && $self->error );
136 44 return( $self );
137 }
138  
139 sub encode_qp
140 1 ▶{
Subroutine encode_qp: called CC=2 SCAR=7.6
Pod documented
141 1 my $s = __PACKAGE__->new;
142 1 my $rv = $s->encode( @_ );
143 1 ▶ if( !defined( $rv ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rv) { } 0 1 1
144 {
145 0 $QuotedPrintError = $s->error;
146 0 return( $s->pass_error );
147 }
148 else
149 {
150 1 undef( $QuotedPrintError );
151 1 return( $rv );
152 }
153 }
154  
155 0 ▶sub encode_qp_utf8 { return( shift->encode_qp( Encode::encode_utf8( shift( @_ ) ) ) ); }
Subroutine encode_qp_utf8: not called CC=1 SCAR=6.9
Pod documented
156  
157 sub is_decoder_installed
158 0 ▶{
Subroutine is_decoder_installed: not called CC=2 SCAR=17.9
Pod documented
159 0 local $@;
160 eval
161 0 {
162 0 ▶ local $SIG{__DIE__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
163 0 require MIME::QuotedPrint;
164 };
165 0 ▶ return( $@ ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 0 0
166 }
167  
168 sub is_encoder_installed
169 0 ▶{
Subroutine is_encoder_installed: not called CC=2 SCAR=17.9
Pod documented
170 0 local $@;
171 eval
172 0 {
173 0 ▶ local $SIG{__DIE__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
174 0 require MIME::QuotedPrint;
175 };
176 0 ▶ return( $@ ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 0 0
177 }
178  
179 # NOTE: sub FREEZE is inherited
180  
181 # NOTE: sub STORABLE_freeze is inherited
182  
183 # NOTE: sub STORABLE_thaw is inherited
184  
185 # NOTE: sub THAW is inherited
186  
187 8 1;
188 # NOTE: POD
189 __END__
« Mail/Make/Stream.pm ↑ Summary Mail/Make/Headers.pm »