Promise/Stream/Brotli.pm

filter: Statementstmt 36.1% 34 / 94 Branchbran 3.1% 1 / 32 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 58.8% 10 / 17 Podpod 100% 6 / 6 totaltotal 32.0% 51 / 159 CC 19 SCAR 35.4
CC
19
Cov
27%
decode
72.0
encode
72.0
decode_bro
6.0
CRAP 34.4
« Promise/Stream/LZW.pm ↑ Summary Promise/Body/Form/Data.pm »
1 ##----------------------------------------------------------------------------
2 ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Stream/Brotli.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2022/05/04
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::Brotli;
15 BEGIN
16 3 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 warnings::register_categories( 'HTTP::Promise' );
20 3 ▶ use HTTP::Promise::Stream;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶ use parent -norequire, qw( HTTP::Promise::Stream::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶ use vars qw( @EXPORT_OK $VERSION $EXCEPTION_CLASS $BrotliError );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 # use Nice::Try;
24 3 ▶ use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 ENCODE_BUFFER_SIZE => ( 32 * 1024 ),
26 DECODE_BUFFER_SIZE => ( 32 * 1024 ),
27 3 };
28 3 our @EXPORT_OK = qw( decode_bro encode_bro );
29 3 our $EXCEPTION_CLASS = 'HTTP::Promise::Exception';
30 3 our $VERSION = 'v0.2.0';
31 };
32  
33 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 sub decode
37 0 ▶{
Subroutine decode: not called CC=8 SCAR=42.8
Pod documented
38 0 my $self = shift( @_ );
39 0 my $from = shift( @_ );
40 0 my $to = shift( @_ );
41 0 my $opts = $self->_get_args_as_hash( @_ );
42 0 my( $from_fh, $reader ) = $self->_get_glob_from_arg( $from );
43 0 my( $to_fh, $writer ) = $self->_get_glob_from_arg( $to, write => 1 );
44 0 ▶ return( $self->pass_error ) if( !defined( $from_fh ) || !defined( $to_fh ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $from_fh and defined $to_fh 0 0 0
Condition0%0/3
defined $from_fh and defined $to_fh
!ll&&!rl&&r
000
MC/DC0%0/2
defined $from_fh and defined $to_fh
defined $from_fh defined $to_fh
Truth table0%0/3
A and B
A= defined $from_fhB= defined $to_fh
ABresult
0X0
100
111
45 0 my( $n, $buff );
46 0 ▶ $self->_load_class( 'IO::Uncompress::Brotli', { no_import => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("IO::Uncompress::Brotli", {"no_import", 1}) or return $self->pass_error 0 0 0
47 0 my $c = IO::Uncompress::Brotli->create;
48
49 0 ▶ while( $n = $reader->( $buff, DECODE_BUFFER_SIZE ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($n = &$reader($buff, 32768)) 0 0 0
50 {
51 0 my $decoded = $c->decompress( $buff );
52 # try-catch
53 0 local $@;
54 my $rv = eval
55 0 {
56 0 $writer->( $decoded );
57 };
58 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
59 {
60 0 return( $self->error( "Error decompressing with Brotli: $@" ) );
61 }
62 0 ▶ return( $self->pass_error ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 0 0
63 }
64 0 ▶ return( $self->pass_error ) if( !defined( $n ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 0 0 0
65 0 return( $self );
66 }
67  
68 sub decode_bro
69 0 ▶{
Subroutine decode_bro: not called CC=2 SCAR=17.9
Pod documented
70 0 my $s = __PACKAGE__->new;
71 0 my $rv = $s->decode( @_ );
72 0 ▶ if( !defined( $rv ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rv) { } 0 0 0
73 {
74 0 $BrotliError = $s->error;
75 0 return( $s->pass_error );
76 }
77 else
78 {
79 0 undef( $BrotliError );
80 0 return( $rv );
81 }
82 }
83  
84 sub encode
85 0 ▶{
Subroutine encode: not called CC=8 SCAR=42.8
Pod documented
86 0 my $self = shift( @_ );
87 0 my $from = shift( @_ );
88 0 my $to = shift( @_ );
89 0 my $opts = $self->_get_args_as_hash( @_ );
90 0 my( $from_fh, $reader ) = $self->_get_glob_from_arg( $from );
91 0 my( $to_fh, $writer ) = $self->_get_glob_from_arg( $to, write => 1 );
92 0 ▶ return( $self->pass_error ) if( !defined( $from_fh ) || !defined( $to_fh ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $from_fh and defined $to_fh 0 0 0
Condition0%0/3
defined $from_fh and defined $to_fh
!ll&&!rl&&r
000
MC/DC0%0/2
defined $from_fh and defined $to_fh
defined $from_fh defined $to_fh
Truth table0%0/3
A and B
A= defined $from_fhB= defined $to_fh
ABresult
0X0
100
111
93 0 my( $n, $buff );
94 0 ▶ $self->_load_class( 'IO::Compress::Brotli', { no_import => 1 } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("IO::Compress::Brotli", {"no_import", 1}) or return $self->pass_error 0 0 0
95 0 my $c = IO::Compress::Brotli->create;
96
97 0 ▶ while( $n = $reader->( $buff, ENCODE_BUFFER_SIZE ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($n = &$reader($buff, 32768)) 0 0 0
98 {
99 0 my $encoded = $c->compress( $buff );
100 # try-catch
101 0 local $@;
102 my $rv = eval
103 0 {
104 0 $writer->( $encoded );
105 };
106 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
107 {
108 0 return( $self->error( "Error compressing with Brotli: $@" ) );
109 }
110 0 ▶ return( $self->pass_error ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 0 0
111 }
112 0 $c->finish;
113  
114 0 ▶ return( $self->pass_error ) if( !defined( $n ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 0 0 0
115 0 return( $self );
116 }
117  
118 sub encode_bro
119 0 ▶{
Subroutine encode_bro: not called CC=2 SCAR=17.9
Pod documented
120 0 my $s = __PACKAGE__->new;
121 0 my $rv = $s->encode( @_ );
122 0 ▶ if( !defined( $rv ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rv) { } 0 0 0
123 {
124 0 $BrotliError = $s->error;
125 0 return( $s->pass_error );
126 }
127 else
128 {
129 0 undef( $BrotliError );
130 0 return( $rv );
131 }
132 }
133  
134 sub is_decoder_installed
135 4 ▶{
Subroutine is_decoder_installed: called CC=2 SCAR=7.0
Pod documented
136 4 local $@;
137 eval
138 4 {
139 4 ▶ local $SIG{__DIE__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=0.0
140 4 require IO::Uncompress::Brotli;
141 };
142 # eval( 'use IO::Uncompress::Brotli ();' );
143 4 ▶ return( $@ ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 4 4
144 }
145  
146 sub is_encoder_installed
147 0 ▶{
Subroutine is_encoder_installed: not called CC=2 SCAR=17.9
Pod documented
148 0 local $@;
149 # eval( 'use IO::Compress::Brotli ();' );
150 eval
151 0 {
152 0 ▶ local $SIG{__DIE__} = sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
153 0 require IO::Uncompress::Brotli;
154 };
155 0 ▶ return( $@ ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 0 0
156 }
157  
158 # NOTE: sub FREEZE is inherited
159  
160 # NOTE: sub STORABLE_freeze is inherited
161  
162 # NOTE: sub STORABLE_thaw is inherited
163  
164 # NOTE: sub THAW is inherited
165  
166 3 1;
167 # NOTE: POD
168 __END__
« Promise/Stream/LZW.pm ↑ Summary Promise/Body/Form/Data.pm »