| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 2 | ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Headers/ContentDisposition.pm | ||||||||||||||||||||||||||||||||
| 3 | ## Version v0.1.0 | ||||||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2022 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||||||
| 6 | ## Created 2022/05/07 | ||||||||||||||||||||||||||||||||
| 7 | ## Modified 2022/05/07 | ||||||||||||||||||||||||||||||||
| 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::Headers::ContentDisposition; | ||||||||||||||||||||||||||||||||
| 15 | BEGIN | ||||||||||||||||||||||||||||||||
| 16 | 6 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | 6 | warnings::register_categories( 'HTTP::Promise' ); | |||||||||||||||||||||||||||||||
| 20 | 6 | ▶ | use parent qw( HTTP::Promise::Headers::Generic ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 21 | 6 | our $VERSION = 'v0.1.0'; | |||||||||||||||||||||||||||||||
| 22 | }; | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 25 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | sub init | ||||||||||||||||||||||||||||||||
| 28 | 42 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=9 SCAR=22.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 29 | 42 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||
| 30 | 42 | $self->{filename_charset} = undef; | |||||||||||||||||||||||||||||||
| 31 | 42 | $self->{filename_lang} = undef; | |||||||||||||||||||||||||||||||
| 32 | 42 | ▶ | @_ = () if( @_ == 1 && $self->_is_a( $_[0] => 'Module::Generic::Null' ) ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ == 1 and $self->_is_a($_[0], "Module::Generic::Null")
MC/DC100%2/2
@_ == 1 and $self->_is_a($_[0], "Module::Generic::Null")
@_ == 1
$self->_is_a($_[0], "Module::Generic::Null")
Truth table100%3/3
A and B
A= @_ == 1B= $self->_is_a($_[0], "Module::Generic::Null")
| |||||||||||||||||||||||||||||||||
| 33 | 42 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||||||
| 35 | 33 | my $str = shift( @_ ); | |||||||||||||||||||||||||||||||
| 36 | 33 | ▶ | return( $self->error( "No value was provided for Content-Disposition field." ) ) if( !defined( $str ) || !length( "$str" ) ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $str and length "$str"
MC/DC0%0/2
defined $str and length "$str"
defined $str
length "$str"
Truth table33%1/3
A and B
A= defined $strB= length "$str"
| |||||||||||||||||||||||||||||||||
| 37 | 33 | my $params = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||||||
| 38 | 33 | ▶ | my $hv = $self->_parse_header_value( $str ) || | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_parse_header_value($str) || (return $self->pass_error)
MC/DC0%0/1
$self->_parse_header_value($str) || (return $self->pass_error)
$self->_parse_header_value($str)
Truth table50%1/2
A
A= $self->_parse_header_value($str)
| |||||||||||||||||||||||||||||||||
| 39 | return( $self->pass_error ); | ||||||||||||||||||||||||||||||||
| 40 | 33 | ▶ | $hv->params( $params ) if( scalar( keys( %$params ) ) ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 41 | 33 | $self->_hv( $hv ); | |||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||
| 43 | 42 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 44 | 42 | $self->_field_name( 'Content-Disposition' ); | |||||||||||||||||||||||||||||||
| 45 | 42 | return( $self ); | |||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 13 | ▶ | sub as_string { return( shift->_hv_as_string( [qw( name filename )], { quote => 'name' } ) ); } | ||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | sub disposition | ||||||||||||||||||||||||||||||||
| 51 | 17 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
disposition: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 52 | 17 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||
| 53 | 17 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 54 | { | ||||||||||||||||||||||||||||||||
| 55 | 8 | ▶ | my $dispo = shift( @_ ) || return( $self->error( "No content disposition was provided." ) ); | ||||||||||||||||||||||||||||||
|
Condition50%1/2
shift @_ || (return $self->error('No content disposition was provided.'))
MC/DC0%0/1
shift @_ || (return $self->error('No content disposition was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||
| 56 | 8 | my $hv = $self->_hv; | |||||||||||||||||||||||||||||||
| 57 | 8 | ▶ | if( $hv ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||||||
| 59 | 4 | $hv->value( $dispo ); | |||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | else | ||||||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||||||
| 63 | 4 | ▶ | $hv = $self->_new_hv( $dispo ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_new_hv($dispo) || (return $self->pass_error)
MC/DC0%0/1
$self->_new_hv($dispo) || (return $self->pass_error)
$self->_new_hv($dispo)
Truth table50%1/2
A
A= $self->_new_hv($dispo)
| |||||||||||||||||||||||||||||||||
| 64 | 4 | $self->_hv( $hv ); | |||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||
| 66 | 8 | return( $dispo ); | |||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||
| 68 | else | ||||||||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||||||
| 70 | # No header value object, means there is just nothing set yet | ||||||||||||||||||||||||||||||||
| 71 | 9 | ▶ | my $hv = $self->_hv || return( '' ); | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_hv || (return '')
MC/DC0%0/1
$self->_hv || (return '')
$self->_hv
Truth table50%1/2
A
A= $self->_hv
| |||||||||||||||||||||||||||||||||
| 72 | 9 | return( $hv->value_data ); | |||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | sub filename | ||||||||||||||||||||||||||||||||
| 77 | 14 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
filename: called CC=9 SCAR=22.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 78 | 14 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||
| 79 | 14 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||||||
| 81 | 4 | my( $fname, $lang ) = @_; | |||||||||||||||||||||||||||||||
| 82 | 4 | ▶ | if( !defined( $fname ) ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||||||
| 84 | 0 | $self->params->delete( 'filename' ); | |||||||||||||||||||||||||||||||
| 85 | 0 | $self->params->delete( 'filename*' ); | |||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||
| 87 | else | ||||||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||||||
| 89 | 4 | ▶ | $lang //= $self->filename_lang; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$lang //= $self->filename_lang
MC/DC50%1/2
$lang //= $self->filename_lang
$lang
$self->filename_lang
Truth table66%2/3
A //= B
A= $langB= $self->filename_lang
| |||||||||||||||||||||||||||||||||
| 90 | 4 | ▶ | if( my $enc = $self->_filename_encode( $fname, $lang ) ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 91 | { | ||||||||||||||||||||||||||||||||
| 92 | 1 | ▶ | $self->_set_get_param( 'filename*' => $enc ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||
| 94 | else | ||||||||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||||||
| 96 | 3 | $self->_set_get_qparam( filename => $fname ); | |||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||
| 100 | else | ||||||||||||||||||||||||||||||||
| 101 | { | ||||||||||||||||||||||||||||||||
| 102 | 10 | my $v = $self->_set_get_qparam( 'filename' ); | |||||||||||||||||||||||||||||||
| 103 | 10 | ▶ | if( defined( $v ) && length( $v ) ) | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $v and length $v
MC/DC50%1/2
defined $v and length $v
defined $v
length $v
Truth table66%2/3
A and B
A= defined $vB= length $v
| |||||||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||||||
| 105 | # decode if necessary | ||||||||||||||||||||||||||||||||
| 106 | 6 | my( $f_charset, $f_lang ); | |||||||||||||||||||||||||||||||
| 107 | 6 | ( $v, $f_charset, $f_lang ) = $self->_filename_decode( $v ); | |||||||||||||||||||||||||||||||
| 108 | 6 | $self->filename_charset( $f_charset ); | |||||||||||||||||||||||||||||||
| 109 | 6 | $self->filename_lang( $f_lang ); | |||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||
| 111 | elsif( $v = $self->_set_get_param( 'filename*' ) ) | ||||||||||||||||||||||||||||||||
| 112 | { | ||||||||||||||||||||||||||||||||
| 113 | 1 | my( $f_charset, $f_lang ); | |||||||||||||||||||||||||||||||
| 114 | 1 | ( $v, $f_charset, $f_lang ) = $self->_filename_decode( $v ); | |||||||||||||||||||||||||||||||
| 115 | 1 | $self->filename_charset( $f_charset ); | |||||||||||||||||||||||||||||||
| 116 | 1 | $self->filename_lang( $f_lang ); | |||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||
| 118 | 10 | return( $v ); | |||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | sub filename_charset | ||||||||||||||||||||||||||||||||
| 123 | 8 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
filename_charset: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 124 | 8 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||
| 125 | 8 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 126 | { | ||||||||||||||||||||||||||||||||
| 127 | 7 | my $v = shift( @_ ); | |||||||||||||||||||||||||||||||
| 128 | 7 | ▶ | if( !defined( $v ) ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 129 | { | ||||||||||||||||||||||||||||||||
| 130 | 6 | return( $self->_set_get_scalar_as_object( 'filename_charset', $v ) ); | |||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||
| 132 | 1 | ▶ | return( $self->error( "Only supported charset is 'utf-8'." ) ) if( lc( $v ) ne 'utf-8' && lc( $v ) ne 'utf8' ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
lc $v ne "utf-8" and lc $v ne "utf8"
MC/DC0%0/2
lc $v ne "utf-8" and lc $v ne "utf8"
lc $v ne "utf-8"
lc $v ne "utf8"
Truth table33%1/3
A and B
A= lc $v ne "utf-8"B= lc $v ne "utf8"
| |||||||||||||||||||||||||||||||||
| 133 | # Convenience | ||||||||||||||||||||||||||||||||
| 134 | 1 | ▶ | $v = 'utf-8' if( lc( $v ) eq 'utf8' ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 135 | 1 | $v = uc( $v ); | |||||||||||||||||||||||||||||||
| 136 | 1 | return( $self->_set_get_scalar_as_object( 'filename_charset', $v ) ); | |||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||
| 138 | 1 | return( $self->_set_get_scalar_as_object( 'filename_charset' ) ); | |||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | 11 | ▶ | sub filename_lang { return( shift->_set_get_scalar_as_object( 'filename_lang', @_ ) ); } | ||||||||||||||||||||||||||||||
|
Subroutine
filename_lang: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | 21 | ▶ | sub name { return( shift->_set_get_param( name => @_ ) ); } | ||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | sub param { return( shift->_set_get_param( @_ ) ); } | ||||||||||||||||||||||||||||||
|
Subroutine
param: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub params { return( shift->_set_get_params( @_ ) ); } | ||||||||||||||||||||||||||||||
|
Subroutine
params: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | 6 | 1; | |||||||||||||||||||||||||||||||
| 150 | # NOTE: POD | ||||||||||||||||||||||||||||||||
| 151 | __END__ | ||||||||||||||||||||||||||||||||