| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Stream/UU.pm | ||||||||||||||||||||||||||||
| 3 | ## Version v0.2.0 | ||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2022 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||
| 6 | ## Created 2022/04/29 | ||||||||||||||||||||||||||||
| 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::UU; | ||||||||||||||||||||||||||||
| 15 | BEGIN | ||||||||||||||||||||||||||||
| 16 | { | ||||||||||||||||||||||||||||
| 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' ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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 $UUError ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | use constant { | ||||||||||||||||||||||||||||
| 24 | 3 | DECODE_BUFFER_SIZE => 1024, | |||||||||||||||||||||||||||
| 25 | ENCODE_BUFFER_SIZE => 45, | ||||||||||||||||||||||||||||
| 26 | 3 | ▶ | }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 3 | our @EXPORT_OK = qw( decode_uu encode_uu ); | |||||||||||||||||||||||||||
| 28 | 3 | our $EXCEPTION_CLASS = 'HTTP::Promise::Exception'; | |||||||||||||||||||||||||||
| 29 | 3 | our $VERSION = 'v0.2.0'; | |||||||||||||||||||||||||||
| 30 | }; | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub decode | ||||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||
| 37 | 1 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||
|
Subroutine
decode: called CC=12 SCAR=26.2
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 1 | my $from = shift( @_ ); | |||||||||||||||||||||||||||
| 39 | 1 | my $to = shift( @_ ); | |||||||||||||||||||||||||||
| 40 | 1 | my $opts = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||
| 41 | 1 | my( $from_fh, $reader ) = $self->_get_glob_from_arg( $from ); | |||||||||||||||||||||||||||
| 42 | 1 | my( $to_fh, $writer ) = $self->_get_glob_from_arg( $to, write => 1 ); | |||||||||||||||||||||||||||
| 43 | 1 | ▶ | return( $self->pass_error ) if( !defined( $from_fh ) || !defined( $to_fh ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $from_fh and defined $to_fh
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
| |||||||||||||||||||||||||||||
| 44 | 1 | my( $n, $buff ); | |||||||||||||||||||||||||||
| 45 | 1 | $buff = ''; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | my $getline = sub | ||||||||||||||||||||||||||||
| 48 | { | ||||||||||||||||||||||||||||
| 49 | 8 | ▶ | if( length( $buff ) > 0 && $buff =~ s/^((?:[^\015\012]+)\015?\012)// ) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=17.5
Branch: 1 branch
Condition66%2/3
length $buff > 0 and $buff =~ s/^((?:[^\015\012]+)\015?\012)//
MC/DC50%1/2
length $buff > 0 and $buff =~ s/^((?:[^\015\012]+)\015?\012)//
length $buff > 0
$buff =~ s/^((?:[^\015\012]+)\015?\012)//
Truth table66%2/3
A and B
A= length $buff > 0B= $buff =~ s/^((?:[^\015\012]+)\015?\012)//
| |||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||
| 51 | 7 | return( $1 ); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | else | ||||||||||||||||||||||||||||
| 54 | { | ||||||||||||||||||||||||||||
| 55 | 1 | ▶ | while( $n = $reader->( $buff, DECODE_BUFFER_SIZE, length( $buff ) ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||
| 57 | 1 | ▶ | if( $buff =~ s/^((?:[^\015\012]+)\015?\012)// ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||
| 59 | 1 | return( $1 ); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | else | ||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||
| 63 | 0 | next; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 0 | return; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 1 | }; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 1 | my( $mode, $fname ); | |||||||||||||||||||||||||||
| 71 | 1 | my $done; | |||||||||||||||||||||||||||
| 72 | 1 | local $_; | |||||||||||||||||||||||||||
| 73 | # Credit: brian d foy <https://metacpan.org/dist/PerlPowerTools/view/bin/uudecode> | ||||||||||||||||||||||||||||
| 74 | 1 | ▶ | READ: while( defined( $_ = $getline->() ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||
| 76 | 1 | ▶ | next unless( ( $mode, $fname ) = /^begin[[:blank:]\h]+(\d+)[[:blank:]\h]+(\S+)/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 1 | $self->filename( $fname ); | |||||||||||||||||||||||||||
| 78 | 1 | $self->mode( $mode ); | |||||||||||||||||||||||||||
| 79 | 1 | $opts->{filename} = $fname; | |||||||||||||||||||||||||||
| 80 | 1 | $opts->{mode} = $mode; | |||||||||||||||||||||||||||
| 81 | 1 | $done = 0; | |||||||||||||||||||||||||||
| 82 | 1 | ▶ | LINE: while( defined( $_ = $getline->() ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||
| 84 | 7 | ▶ | if( /^end$/ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||
| 86 | 1 | $done = 1; | |||||||||||||||||||||||||||
| 87 | 1 | last READ; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | 6 | ▶ | next LINE if( /[a-z]/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 6 | ▶ | next LINE unless int( ( ( ( ord( $_ ) - 32 ) & 077 ) + 2 ) / 3 ) == int( length( $_ ) / 4 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 6 | my $rv = $writer->( unpack( 'u', $_ ) ); | |||||||||||||||||||||||||||
| 92 | 6 | ▶ | return( $self->pass_error ) if( !defined( $rv ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 1 | ▶ | return( $self->error( "No UU encoded data found." ) ) if( !defined( $done ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 1 | ▶ | return( $self->error( "Missing end. input data stream may be truncated." ) ) if( !$done ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 1 | return( $self ); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | sub decode_uu | ||||||||||||||||||||||||||||
| 101 | { | ||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my $s = __PACKAGE__->new; | ||||||||||||||||||||||||||
|
Subroutine
decode_uu: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 0 | my $rv = $s->decode( @_ ); | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | if( !defined( $rv ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||
| 106 | 0 | $UUError = $s->error; | |||||||||||||||||||||||||||
| 107 | 0 | return( $s->pass_error ); | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | else | ||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||
| 111 | 0 | undef( $UUError ); | |||||||||||||||||||||||||||
| 112 | 0 | return( $rv ); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | sub encode | ||||||||||||||||||||||||||||
| 117 | { | ||||||||||||||||||||||||||||
| 118 | 1 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||
|
Subroutine
encode: called CC=11 SCAR=26.6
Pod
documented
| |||||||||||||||||||||||||||||
| 119 | 1 | my $from = shift( @_ ); | |||||||||||||||||||||||||||
| 120 | 1 | my $to = shift( @_ ); | |||||||||||||||||||||||||||
| 121 | 1 | my $opts = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||
| 122 | 1 | my( $from_fh, $reader ) = $self->_get_glob_from_arg( $from ); | |||||||||||||||||||||||||||
| 123 | 1 | my( $to_fh, $writer ) = $self->_get_glob_from_arg( $to, write => 1 ); | |||||||||||||||||||||||||||
| 124 | 1 | ▶ | return( $self->pass_error ) if( !defined( $from_fh ) || !defined( $to_fh ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $from_fh and defined $to_fh
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
| |||||||||||||||||||||||||||||
| 125 | 1 | ▶ | my $fname = ( exists( $opts->{filename} ) && length( $opts->{filename} ) ) ? $opts->{filename} : 'unknown.bin'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $opts->{"filename"} and length $opts->{"filename"}
MC/DC0%0/2
exists $opts->{"filename"} and length $opts->{"filename"}
exists $opts->{"filename"}
length $opts->{"filename"}
Truth table33%1/3
A and B
A= exists $opts->{"filename"}B= length $opts->{"filename"}
| |||||||||||||||||||||||||||||
| 126 | 1 | ▶ | my $mode = ( exists( $opts->{mode} ) && length( $opts->{mode} ) ) ? $opts->{mode} : 0644; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $opts->{"mode"} and length $opts->{"mode"}
MC/DC0%0/2
exists $opts->{"mode"} and length $opts->{"mode"}
exists $opts->{"mode"}
length $opts->{"mode"}
Truth table33%1/3
A and B
A= exists $opts->{"mode"}B= length $opts->{"mode"}
| |||||||||||||||||||||||||||||
| 127 | 1 | my( $n, $buff ); | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 1 | my $rv = $writer->( sprintf( "begin %03o $fname\n", $mode ) ); | |||||||||||||||||||||||||||
| 130 | 1 | ▶ | return( $self->pass_error ) if( !defined( $rv ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 1 | ▶ | while( $n = $reader->( $buff, ENCODE_BUFFER_SIZE ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | { | ||||||||||||||||||||||||||||
| 133 | 5 | $writer->( pack( 'u', $buff ) ); | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | 1 | ▶ | defined( $writer->( "`\n" ) ) or return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 1 | ▶ | defined( $writer->( "end\n" ) ) or return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 1 | return( $self ); | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | sub encode_uu | ||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||
| 142 | 0 | ▶ | my $s = __PACKAGE__->new; | ||||||||||||||||||||||||||
|
Subroutine
encode_uu: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 143 | 0 | my $rv = $s->encode( @_ ); | |||||||||||||||||||||||||||
| 144 | 0 | ▶ | if( !defined( $rv ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||||||||
| 146 | 0 | $UUError = $s->error; | |||||||||||||||||||||||||||
| 147 | 0 | return( $s->pass_error ); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | else | ||||||||||||||||||||||||||||
| 150 | { | ||||||||||||||||||||||||||||
| 151 | 0 | undef( $UUError ); | |||||||||||||||||||||||||||
| 152 | 0 | return( $rv ); | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 1 | ▶ | sub filename { return( shift->_set_get_scalar( 'filename', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
filename: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | sub is_decoder_installed { return(1); } | ||||||||||||||||||||||||||
|
Subroutine
is_decoder_installed: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub is_encoder_installed { return(1); } | ||||||||||||||||||||||||||
|
Subroutine
is_encoder_installed: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 1 | ▶ | sub mode { return( shift->_set_get_number( 'mode', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
mode: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | # NOTE: sub FREEZE is inherited | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | # NOTE: sub STORABLE_freeze is inherited | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | # NOTE: sub STORABLE_thaw is inherited | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | # NOTE: sub THAW is inherited | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 3 | 1; | |||||||||||||||||||||||||||
| 173 | # NOTE: POD | ||||||||||||||||||||||||||||
| 174 | __END__ | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | =encoding utf-8 | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =head1 NAME | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | HTTP::Promise::Stream::UU - Stream Encoder for UU Encoding | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | use HTTP::Promise::Stream::UU; | ||||||||||||||||||||||||||||
| 185 | my $s = HTTP::Promise::Stream::UU->new || | ||||||||||||||||||||||||||||
| 186 | die( HTTP::Promise::Stream::UU->error, "\n" ); | ||||||||||||||||||||||||||||
| 187 | $s->encode( $input => $output, eol => "\n" ) || | ||||||||||||||||||||||||||||
| 188 | die( $s->error ); | ||||||||||||||||||||||||||||
| 189 | $s->decode( $input => $output ) || die( $s->error ); | ||||||||||||||||||||||||||||
| 190 | HTTP::Promise::Stream::UU::encode_uu( $input => $output, eol => "\n" ) || | ||||||||||||||||||||||||||||
| 191 | die( $HTTP::Promise::Stream::UU::UUError ); | ||||||||||||||||||||||||||||
| 192 | HTTP::Promise::Stream::UU::decode_uu( $input => $output, eol => "\n" ) || | ||||||||||||||||||||||||||||
| 193 | die( $HTTP::Promise::Stream::UU::UUError ); | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | =head1 VERSION | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | v0.2.0 | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | This implements an encoding and decoding mechanism for UU encoding using either of the following on input and output: | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | =over 4 | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | =item C<filepath> | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | If the parameter is neither a scalar reference nor a file handle, it will be assumed to be a file path. | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | =item C<file handle> | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | This can be a native file handle, or an object oriented one as long as it implements the C<print> or C<write>, and C<read> methods. The C<read> method is expected to return the number of bytes read or C<undef> upon error. The C<print> and C<write> methods are expected to simply return true upon success and C<undef> upon error. | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | Alternatively, those methods can die and those exceptions wil be caught. | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | =item C<scalar reference> | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | This can be a simple scalar reference, or an object scalar reference. | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | =back | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | =head2 new | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | Creates a new L<HTTP::Promise::Stream::UU> object and returns it. | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | =head1 METHODS | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | =head2 decode | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | This takes 2 arguments: an input and an output. Each one can be either a file path, a file handle, or a scalar reference. | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | It will decode the UU encoded data and write the result into the output. | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | It returns true upon success and sets an L<error|Module::Generic/error> and return C<undef> upon error. | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | =head2 encode | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | This takes 2 arguments: an input and an output. Each one can be either a file path, a file handle, or a scalar reference. | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | It will encode the data into UU encoded data and write the result into the output. | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | Possible options are: | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | =over 4 | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | =item I<filename> | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | The file name (not the file path) to be used for UU encoding. | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | =item I<mode> | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | The file octal permisions, like C<0644>. It defaults to C<0644> if nothing is provided. | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | =back | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | It returns true upon success and sets an L<error|Module::Generic/error> and return C<undef> upon error. | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | =head1 CLASS FUNCTIONS | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | The following class functions are available and can also be exported, such as: | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | use HTTP::Promise::Stream::Brotli qw( decode_uu encode_uu ); | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | =head2 decode_uu | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | This takes the same 2 arguments used in L</decode>: an input and an output. Each one can be either a file path, a file handle, or a scalar reference. | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | It will decode the UU encoded data and write the result into the output. | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | It returns true upon success, and upon error, it will set the error in the global variable C<$UUError> and return C<undef> | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | my $decoded = HTTP::Promise::Stream::UU::decode_uu( $encoded ); | ||||||||||||||||||||||||||||
| 274 | die( "Something went wrong: $HTTP::Promise::Stream::UU::UUError\n" if( !defined( $decoded ) ); | ||||||||||||||||||||||||||||
| 275 | print( "Decoded data is: $decoded\n" ); | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | =head2 encode_uu | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | This takes the same 2 arguments used in L</encode>: an input and an output. Each one can be either a file path, a file handle, or a scalar reference. | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | It will encode the data into UU encoded data and write the result into the output. | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | It returns true upon success, and upon error, it will set the error in the global variable C<$UUError> and return C<undef> | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | my $encoded = HTTP::Promise::Stream::UU::encode_uu( $data ); | ||||||||||||||||||||||||||||
| 286 | die( "Something went wrong: $HTTP::Promise::Stream::UU::UUError\n" if( !defined( $encoded ) ); | ||||||||||||||||||||||||||||
| 287 | print( "Encoded data is: $encoded\n" ); | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | =head2 is_decoder_installed | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | Always returns true, because decoding is done internally. | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | =head2 is_encoder_installed | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | Always returns true, because encoding is done internally. | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | =head1 THREAD-SAFETY | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | This module is thread-safe for all operations, as it operates on per-object state and uses thread-safe external libraries. | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | L<Wikipedia page|https://en.wikipedia.org/wiki/Uuencoding> | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | L<HTTP::Promise>, L<HTTP::Promise::Request>, L<HTTP::Promise::Response>, L<HTTP::Promise::Message>, L<HTTP::Promise::Entity>, L<HTTP::Promise::Headers>, L<HTTP::Promise::Body>, L<HTTP::Promise::Body::Form>, L<HTTP::Promise::Body::Form::Data>, L<HTTP::Promise::Body::Form::Field>, L<HTTP::Promise::Status>, L<HTTP::Promise::MIME>, L<HTTP::Promise::Parser>, L<HTTP::Promise::IO>, L<HTTP::Promise::Stream>, L<HTTP::Promise::Exception> | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | Copyright(c) 2022 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | All rights reserved. | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | =cut | ||||||||||||||||||||||||||||