NAME
Protocol::Tus::Util
SYNOPSIS
use Protocol::Tus::Util qw<
as_ouch
coerce_model
lc_hash
ouch_rethrow
response
response_from_exception
validate_checksum
validate_id
validate_length
validate_tus_resumable
wrap_response
>;
DESCRIPTION
Utility functions for Protocol::Tus.
INTERFACE
as_ouch
my $ouch_exception_object = as_ouch($exception);
Transform an input exception into an Ouch object. Any input Ouch object is preserved as-is.
coerce_model
my $model = coerce_model($spec);
Transform a specification into a model. The input can be an object, which is returned as-is, or a hash reference with the following keys:
class-
The class of the model. The class name must be fully qualified, e.g.
Protocol::Tus::LocalDir. args-
Arguments to pass to the class's constructor.
In this case the provided class is used and its new method invoked passing the args.
lc_hash
my $lowercase_hash = lc_hash($anycase_hash);
Generate a reference to a hash with keys corresponding to lowercase of the input $anycase_hash's hash and the same values. It is assumed that the input hash does not contain two keys that have the same lowercase representation.
ouch_rethrow
ouch_rethrow($exception);
Throw (or most probably re-throw) an exception as a Ouch one. Uses "as_ouch" under the hood.
response
my $response = response(
status => 500,
body => 'Internal Server Error',
headers => { Foo => 'bar' },
exception => $e,
);
Wrapper around Protocol::Tus::Response's constructor new.
response_augment
my $same_response_object = response_augment($response_object);
Add headers needed in most responses for the Tus protocol.
response_from_exception
my $response = response_from_exception($exception);
Turn an exception into a response.
validate_checksum
validate_checksum($ref_to_data, $checksum_header_contents);
Parse $checksum_header_contents (as received from a Tus client) for figuring out the checksum protocol, then calculate the checksum over $ref_to_data (reference to a scalar holding the data) and check it against the one parsed.
Throws an exception if the check fails.
validate_id
validate_id($id);
Throws an exception if the provided $id is not a valid identifier.
validate_length
validate_length($length, $lowercase_headers);
Performs various checks on the provided $length and throws an exception if the relevant conditions are not met. Expects to receive a hash reference with the headers, every key as a lowercase string.
validate_tus_resumable
validate_tus_resumable($lowercase_headers, $supported_version);
Checks the presence and the support for the value of header Tus-Resumable. The input $lowercase_headers is a hash reference with the headers having all keys as lowercase strings. $supported_version is the string representing the supported version to compare against.
ANYTHING ELSE (INCLUDING AUTHOR, COPYRIGHT AND LICENSE)
See documentation for Protocol::Tus.