blib/lib/HTTP/Promise/Headers/ContentType.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 16 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 95 CC 5 SCAR 18.3
CC
5
Cov
0%
init
20.0
type
6.0
BEGIN
2.0
CRAP 6.2
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 use strict;
18 use warnings;
19 warnings::register_categories( 'HTTP::Promise' );
20 use parent qw( HTTP::Promise::Headers::Generic );
21 our $VERSION = 'v0.1.0';
22 };
23  
24 use strict;
25 use warnings;
26  
27 sub init
28 {
29 my $self = shift( @_ );
30 @_ = () if( @_ == 1 && $self->_is_a( $_[0] => 'Module::Generic::Null' ) );
31 if( @_ )
32 {
33 my $str = shift( @_ );
34 return( $self->error( "No value was provided for Content-Type field." ) ) if( !defined( $str ) || !length( "$str" ) );
35 my $params = $self->_get_args_as_hash( @_ );
36 my $hv = $self->_parse_header_value( $str ) ||
37 return( $self->pass_error );
38 $hv->param( $_ => $params->{ $_ } ) for( keys( %$params ) );
39 $self->_hv( $hv );
40 }
41 $self->SUPER::init( @_ ) || return( $self->pass_error );
42 $self->_field_name( 'Content-Type' );
43 return( $self );
44 }
45  
46 sub as_string { return( shift->_hv_as_string( @_ ) ); }
47  
48 sub boundary { return( shift->_set_get_param( boundary => @_ ) ); }
49  
50 sub charset { return( shift->_set_get_param( charset => @_ ) ); }
51  
52 sub make_boundary { return( shift->_make_boundary ); }
53  
54 sub param { return( shift->_set_get_param( @_ ) ); }
55  
56 sub params { return( shift->_set_get_params( @_ ) ); }
57  
58 sub type
59 {
60 my $self = shift( @_ );
61 if( @_ )
62 {
63 my $mime = shift( @_ ) || return( $self->error( "No mime type was provided." ) );
64 my $hv = $self->_new_hv( $mime ) || return( $self->pass_error );
65 $self->_hv( $hv );
66 return( $mime );
67 }
68 else
69 {
70 # No header value object, means there is just nothing set yet
71 my $hv = $self->_hv || return( '' );
72 return( $hv->value_data );
73 }
74 }
75  
76 # Basically same thing as type()
77 sub value { return( shift->_set_get_value( @_ ) ); }
78  
79 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