Promise/Stream/QuotedPrint.pm

filter: Statementstmt 73.7% 73 / 99 Branchbran 41.3% 19 / 46 Conditioncond 38.1% 8 / 21 MC/DCmcdc 8.3% 1 / 12 Subroutinesub 68.4% 13 / 19 Podpod 100% 7 / 7 totaltotal 59.3% 121 / 204 CC 31 SCAR 27.8
CC
31
Cov
60%
encode
29.5
decode
21.9
decode_qp
6.0
CRAP 16.1
« Promise/Body.pm ↑ Summary Promise/Pool.pm »
1 ##----------------------------------------------------------------------------
2 ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Stream/QuotedPrint.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2022/05/30
7 ## Modified 2023/09/08
8 ## All rights reserved.
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package HTTP::Promise::Stream::QuotedPrint;
15 BEGIN
16 4 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 warnings::register_categories( 'HTTP::Promise' );
20 4 ▶ use HTTP::Promise::Stream;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶ use parent -norequire, qw( HTTP::Promise::Stream::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 ▶ use vars qw( @EXPORT_OK $VERSION $EXCEPTION_CLASS $QuotedPrintError $DEBUG );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 ▶ use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 4 ▶ use Module::Generic::File::IO;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 4 our @EXPORT_OK = qw( decode_qp encode_qp );
26 4 our $EXCEPTION_CLASS = 'HTTP::Promise::Exception';
27 4 our $VERSION = 'v0.2.0';
28 4 our $DEBUG = 0;
29 };
30  
31 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 sub decode
35 1 ▶{
Subroutine decode: called CC=12 SCAR=30.8
Pod documented
36 1 my $self = shift( @_ );
37 1 my $from = shift( @_ );
38 1 my $to = shift( @_ );
39 1 my $opts = $self->_get_args_as_hash( @_ );
40 1 my( $from_fh, $reader ) = $self->_get_glob_from_arg( $from );
41 1 my( $to_fh, $writer ) = $self->_get_glob_from_arg( $to, write => 1 );
42 1 ▶ return( $self->pass_error ) if( !defined( $from_fh ) || !defined( $to_fh ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $from_fh and defined $to_fh 0 1 1
Condition33%1/3
defined $from_fh and defined $to_fh
!ll&&!rl&&r
001
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
43 1 ▶ $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 1 0 1
44 # Wrap the filehandle into an object-oriented one that support the getline() method
45 1 ▶ unless( $self->_can( $from_fh => 'getline' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_can($from_fh, "getline")) 0 1 1
46 {
47 0 my $io = Module::Generic::File::IO->new;
48 0 ▶ $io->fdopen( ( $self->_can( $from_fh => 'fileno' ) ? $from_fh->fileno : fileno( $from_fh ) ), 'r' ) ||
Branch: 2 branches
BranchTrueFalseTotal
$io->fdopen($self->_can($from_fh, "fileno") ? $from_fh->fileno : fileno $from_fh, "r") or return $self->pass_error($io->error) 0 0 0
$self->_can($from_fh, 'fileno') ? : 0 0 0
49 return( $self->pass_error( $io->error ) );
50 0 $from_fh = $io;
51 }
52
53 1 my $buff;
54 1 ▶ while( defined( $buff = $from_fh->getline ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($buff = $from_fh->getline)) 8 1 9
55 {
56 8 my $decoded = MIME::QuotedPrint::decode_qp( $buff );
57 # MIME::QuotedPrint::decode_qp() will decode the data into an utf-8 bytes (not the perl's internal representation)
58 # This is fine and we save it as it is in the output
59 8 my $rv = $writer->( $decoded );
60 8 ▶ return( $self->pass_error ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 8 8
61 }
62 1 ▶ return( $self->pass_error( $from_fh->error ) ) if( !defined( $buff ) && $self->_can( $from_fh => 'error' ) && $self->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $buff and $self->_can($from_fh, "error") and $self->error 0 1 1
Condition33%2/6
not defined $buff and $self->_can($from_fh, "error") and $self->error
!ll&&!rl&&r
010
not defined $buff and $self->_can($from_fh, "error")
!ll&&!rl&&r
001
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
63 1 return( $self );
64 }
65  
66 sub decode_qp
67 0 ▶{
Subroutine decode_qp: not called CC=2 SCAR=17.9
Pod documented
68 0 my $s = __PACKAGE__->new( debug => $DEBUG );
69 0 my $rv = $s->decode( @_ );
70 0 ▶ if( !defined( $rv ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rv) { } 0 0 0
71 {
72 0 $QuotedPrintError = $s->error;
73 0 return( $s->pass_error );
74 }
75 else
76 {
77 0 undef( $QuotedPrintError );
78 0 return( $rv );
79 }
80 }
81  
82 sub encode
83 2 ▶{
Subroutine encode: called CC=16 SCAR=33.8
Pod documented
84 2 my $self = shift( @_ );
85 2 my $from = shift( @_ );
86 2 my $to = shift( @_ );
87 2 my $opts = $self->_get_args_as_hash( @_ );
88 2 my( $from_fh, $reader ) = $self->_get_glob_from_arg( $from );
89 2 my( $to_fh, $writer ) = $self->_get_glob_from_arg( $to, write => 1 );
90 2 ▶ return( $self->pass_error ) if( !defined( $from_fh ) || !defined( $to_fh ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $from_fh and defined $to_fh 0 2 2
Condition33%1/3
defined $from_fh and defined $to_fh
!ll&&!rl&&r
002
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
91 2 ▶ $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 2 0 2
92 # Wrap the filehandle into an object-oriented one that support the getline() method
93 2 ▶ unless( $self->_can( $from_fh => 'getline' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_can($from_fh, "getline")) 0 2 2
94 {
95 0 my $io = Module::Generic::File::IO->new;
96 0 ▶ $io->fdopen( ( $self->_can( $from_fh => 'fileno' ) ? $from_fh->fileno : fileno( $from_fh ) ), 'r' ) ||
Branch: 2 branches
BranchTrueFalseTotal
$io->fdopen($self->_can($from_fh, "fileno") ? $from_fh->fileno : fileno $from_fh, "r") or return $self->pass_error($io->error) 0 0 0
$self->_can($from_fh, 'fileno') ? : 0 0 0
97 return( $self->pass_error( $io->error ) );
98 0 $from_fh = $io;
99 }
100 2 ▶ my $eol = ( exists( $opts->{eol} ) && defined( $opts->{eol} ) ) ? $opts->{eol} : $/;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'eol'} && defined $opts->{'eol'} ? : 1 1 2
Condition66%2/3
exists $opts->{"eol"} and defined $opts->{"eol"}
!ll&&!rl&&r
101
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
101 2 my $has_eol = length( $eol );
102
103 2 my $buff;
104 2 ▶ while( defined( $buff = $from_fh->getline ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($buff = $from_fh->getline)) 11 2 13
105 {
106 # Make sure the chunk of data is in formal utf-8 encoding, i.e. not perl's internal representation
107 # Should probably use Encode::encode( 'utf-8', $buff ) instead though
108 11 ▶ $buff = Encode::encode_utf8( $buff ) if( Encode::is_utf8( $buff ) );
Branch: 1 branch
BranchTrueFalseTotal
if &Encode::is_utf8($buff) 0 11 11
109 11 ▶ my $encoded = MIME::QuotedPrint::encode_qp( $buff, ( $has_eol ? ( $eol ) : () ) );
Branch: 1 branch
BranchTrueFalseTotal
$has_eol ? : 11 0 11
110 # MIME::QuotedPrint::decode_qp() will decode the data into an utf-8 bytes (not the perl's internal representation)
111 # This is fine and we save it as it is in the output
112 11 my $rv = $writer->( $encoded );
113 11 ▶ return( $self->pass_error ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 11 11
114 }
115 2 ▶ return( $self->pass_error( $from_fh->error ) ) if( !defined( $buff ) && $self->_can( $from_fh => 'error' ) && $self->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $buff and $self->_can($from_fh, "error") and $self->error 0 2 2
Condition33%2/6
not defined $buff and $self->_can($from_fh, "error") and $self->error
!ll&&!rl&&r
020
not defined $buff and $self->_can($from_fh, "error")
!ll&&!rl&&r
002
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
116 2 return( $self );
117 }
118  
119 sub encode_qp
120 1 ▶{
Subroutine encode_qp: called CC=2 SCAR=7.6
Pod documented
121 1 my $s = __PACKAGE__->new;
122 1 my $rv = $s->encode( @_ );
123 1 ▶ if( !defined( $rv ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rv) { } 0 1 1
124 {
125 0 $QuotedPrintError = $s->error;
126 0 return( $s->pass_error );
127 }
128 else
129 {
130 1 undef( $QuotedPrintError );
131 1 return( $rv );
132 }
133 }
134  
135 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
136  
137 sub is_decoder_installed
138 0 ▶{
Subroutine is_decoder_installed: not called CC=2 SCAR=17.9
Pod documented
139 0 local $@;
140 eval
141 0 {
142 0 ▶ local $SIG{__DIE__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
143 0 require MIME::QuotedPrint;
144 };
145 0 ▶ return( $@ ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 0 0
146 }
147  
148 sub is_encoder_installed
149 0 ▶{
Subroutine is_encoder_installed: not called CC=2 SCAR=17.9
Pod documented
150 0 local $@;
151 eval
152 0 {
153 0 ▶ local $SIG{__DIE__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
154 0 require MIME::QuotedPrint;
155 };
156 0 ▶ return( $@ ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 0 0
157 }
158  
159 # NOTE: sub FREEZE is inherited
160  
161 # NOTE: sub STORABLE_freeze is inherited
162  
163 # NOTE: sub STORABLE_thaw is inherited
164  
165 # NOTE: sub THAW is inherited
166  
167 4 1;
168 # NOTE: POD
169 __END__
« Promise/Body.pm ↑ Summary Promise/Pool.pm »