| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Headers/ContentType.pm | ||||||||||||||||||||||||||||
| 3 | ## Version v0.1.0 | ||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2022 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||
| 6 | ## Created 2022/05/06 | ||||||||||||||||||||||||||||
| 7 | ## Modified 2022/05/06 | ||||||||||||||||||||||||||||
| 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::ContentType; | ||||||||||||||||||||||||||||
| 15 | BEGIN | ||||||||||||||||||||||||||||
| 16 | { | ||||||||||||||||||||||||||||
| 17 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 8 | ▶ | warnings::register_categories( 'HTTP::Promise' ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 8 | ▶ | use parent qw( HTTP::Promise::Headers::Generic ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 8 | our $VERSION = 'v0.1.0'; | |||||||||||||||||||||||||||
| 22 | }; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub init | ||||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||
| 29 | 29 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=9 SCAR=23.3
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 29 | ▶ | @_ = () if( @_ == 1 && $self->_is_a( $_[0] => 'Module::Generic::Null' ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ == 1 and $self->_is_a($_[0], "Module::Generic::Null")
MC/DC0%0/2
@_ == 1 and $self->_is_a($_[0], "Module::Generic::Null")
@_ == 1
$self->_is_a($_[0], "Module::Generic::Null")
Truth table66%2/3
A and B
A= @_ == 1B= $self->_is_a($_[0], "Module::Generic::Null")
| |||||||||||||||||||||||||||||
| 31 | 29 | ▶ | if( @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||
| 33 | 24 | my $str = shift( @_ ); | |||||||||||||||||||||||||||
| 34 | 24 | ▶ | return( $self->error( "No value was provided for Content-Type 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"
| |||||||||||||||||||||||||||||
| 35 | 24 | my $params = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||
| 36 | 24 | ▶ | 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)
| |||||||||||||||||||||||||||||
| 37 | return( $self->pass_error ); | ||||||||||||||||||||||||||||
| 38 | 24 | $hv->param( $_ => $params->{ $_ } ) for( keys( %$params ) ); | |||||||||||||||||||||||||||
| 39 | 24 | $self->_hv( $hv ); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | 29 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 29 | $self->_field_name( 'Content-Type' ); | |||||||||||||||||||||||||||
| 43 | 29 | return( $self ); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 13 | ▶ | sub as_string { return( shift->_hv_as_string( @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 23 | ▶ | sub boundary { return( shift->_set_get_param( boundary => @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
boundary: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 18 | ▶ | sub charset { return( shift->_set_get_param( charset => @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
charset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub make_boundary { return( shift->_make_boundary ); } | ||||||||||||||||||||||||||
|
Subroutine
make_boundary: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub param { return( shift->_set_get_param( @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
param: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub params { return( shift->_set_get_params( @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
params: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | sub type | ||||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||||
| 60 | 25 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||
|
Subroutine
type: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 25 | ▶ | if( @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||
| 63 | 4 | ▶ | my $mime = shift( @_ ) || return( $self->error( "No mime type was provided." ) ); | ||||||||||||||||||||||||||
|
Condition50%1/2
shift @_ || (return $self->error('No mime type was provided.'))
MC/DC0%0/1
shift @_ || (return $self->error('No mime type was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||
| 64 | 4 | ▶ | my $hv = $self->_new_hv( $mime ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->_new_hv($mime) || (return $self->pass_error)
MC/DC0%0/1
$self->_new_hv($mime) || (return $self->pass_error)
$self->_new_hv($mime)
Truth table50%1/2
A
A= $self->_new_hv($mime)
| |||||||||||||||||||||||||||||
| 65 | 4 | $self->_hv( $hv ); | |||||||||||||||||||||||||||
| 66 | 4 | return( $mime ); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | else | ||||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||
| 70 | # No header value object, means there is just nothing set yet | ||||||||||||||||||||||||||||
| 71 | 21 | ▶ | 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 | 21 | return( $hv->value_data ); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # Basically same thing as type() | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub value { return( shift->_set_get_value( @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
value: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 8 | 1; | |||||||||||||||||||||||||||
| 80 | # NOTE: POD | ||||||||||||||||||||||||||||
| 81 | __END__ | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =encoding utf-8 | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =head1 NAME | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | HTTP::Promise::Headers::ContentType - Content-Type Header Field | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | use HTTP::Promise::Headers::ContentType; | ||||||||||||||||||||||||||||
| 92 | my $ct = HTTP::Promise::Headers::ContentType->new || | ||||||||||||||||||||||||||||
| 93 | die( HTTP::Promise::Headers::ContentType->error ); | ||||||||||||||||||||||||||||
| 94 | $ct->value( 'text/plain' ); | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =head1 VERSION | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | v0.1.0 | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | The following description is taken from Mozilla documentation. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | Content-Type: text/html; charset=UTF-8 | ||||||||||||||||||||||||||||
| 105 | Content-Type: application/octet-stream | ||||||||||||||||||||||||||||
| 106 | Content-Type: multipart/form-data; boundary=something | ||||||||||||||||||||||||||||
| 107 | Content-Type: application/x-www-form-urlencoded | ||||||||||||||||||||||||||||
| 108 | # Used with 206 Partial Content; rfc7233, section 5.4.1 | ||||||||||||||||||||||||||||
| 109 | Content-Type: multipart/byteranges | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head1 METHODS | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =head2 as_string | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | Returns a string representation of the C<Content-Type> object. | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =head2 boundary | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | Sets or gets the boundary used for C<multipart/form-data>. | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | If the value is C<undef>, it will be removed. | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =head2 charset | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | Sets or gets the charset associated with this C<Content-Type> | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =head2 make_boundary | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | Returns a unique auto-generated boundary. Such auto-generated boundary is actually an uuid. | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =head2 param | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | Set or get an arbitrary name-value pair attribute. | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =head2 params | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | Set or get multiple name-value parameters. | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | Calling this without any parameters, retrieves the associated L<hash object|Module::Generic::Hash> | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =head2 type | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | Sets or gets the mime-type for this field. | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =head2 value | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | Sets or gets the mime-type for this C<Content-Type>. This is effectively the same as L</type> | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =head1 THREAD-SAFETY | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | This module is thread-safe for all operations, as it operates on per-object state and uses thread-safe external libraries. | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | See also L<rfc7233, section 4.1|https://tools.ietf.org/html/rfc7233#section-4.1>, L<rfc7231, section 3.1.1.5|https://tools.ietf.org/html/rfc7231#section-3.1.1.5> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types>, and L<this Mozilla documentation too|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type> | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 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> | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | L<HTTP::Promise>, L<HTTP::Promise::Headers> | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | Copyright(c) 2022 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | All rights reserved. | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =cut | ||||||||||||||||||||||||||||