Apache2-API
view release on metacpan or search on metacpan
documented appropriately.
Apache mod_perl is an awesome framework, but quite complexe with a steep
learning curve and methods all over the place. So much so that they have
developed a module dedicated to find appropriate methods
<https://perl.apache.org/docs/2.0/user/coding/coding.html#toc_Where_the_
Methods_Live> with ModPerl::MethodLookup
METHODS
new
my $api = Apache2::API->new( $r, $hash_ref_of_options );
# or
my $api = Apache2::API->new( apache_request => $r, compression_threshold => 102400 );
This initiates the package and takes an Apache2::RequestRec object and
an hash or hash reference of parameters, or only an hash or hash
reference of parameters:
* "apache_request"
See "apache_request"
* "compression_threshold"
See "compression_threshold"
* "debug"
Optional. If set with a positive integer, this will activate
debugging message
apache_request
Returns the Apache2::RequestRec object that was provided upon object
instantiation.
bailout
$api->bailout( $error_string );
$api->bailout( { code => 400, message => $internal_message } );
$api->bailout( { code => 400, message => $internal_message, public_message => "Sorry!" } );
Given an error message, this will prepare the HTTP header and response
accordingly.
It will call "gettext" to get the localised version of the error
message, so this method is expected to be overriden by inheriting
package.
If the outgoing content type set is "application/json" then this will
return a properly formatted standard json error, such as:
{ "error": { "code": 401, "message": "Something went wrong" } }
Otherwise, it will send to the client the message as is.
compression_threshold( $integer )
The number of bytes threshold beyond which, the "reply" method will gzip
compress the data returned to the client.
decode_base64( $data )
Given some data, this will decode it using base64 algorithm. It uses
"decode" in APR::Base64 in the background.
decode_json( $data )
This decode from utf8 some data into a perl structure using JSON
If an error occurs, it will return undef and set an exception that can
be accessed with the error method.
decode_url( $string )
Given a url-encoded string, this returns the decoded string using
"decode" in APR::Request
decode_utf8( $data )
Decode some data from ut8 into perl internal utf8 representation using
Encode
If an error occurs, it will return undef and set an exception that can
be accessed with the error method.
encode_base64( $data )
Given some data, this will encode it using base64 algorithm. It uses
"encode" in APR::Base64.
encode_json( $hash_reference )
Given a hash reference, this will encode it into a json data
representation.
However, this will not utf8 encode it, because this is done upon
printing the data and returning it to the client.
The JSON object has the following properties enabled: "allow_nonref",
"allow_blessed", "convert_blessed" and "relaxed"
encode_url( $string )
Given a string, this returns its url-encoded version using "encode" in
APR::Request
encode_utf8( $data )
This encode in ut8 the data provided and return it.
If an error occurs, it will return undef and set an exception that can
be accessed with the error method.
generate_uuid
Generates an uuid string and return it. This uses APR::UUID
get_auth_bearer
Checks whether an "Authorization" HTTP header was provided, and get the
Bearer value.
If no header was found, it returns an empty string.
If an error occurs, it will return undef and set an exception that can
be accessed with the error method.
get_handlers
Returns a reference to a list of handlers enabled for a given phase.
$handlers_list = $res->get_handlers( $hook_name );
A list of handlers configured to run at the child_exit phase:
( run in 0.656 second using v1.01-cache-2.11-cpan-f52f0507bed )