NAME
Twilio::Serialize - Convert Perl values to what the Twilio API expects
SYNOPSIS
my $flag = Twilio::Serialize::boolean_to_string(1); # 'true'
my $now = Time::Piece->gmtime;
my $date = Twilio::Serialize::iso8601_date_time($now);
DESCRIPTION
Functions that generated resources use to build their requests. None of them are exported.
FUNCTIONS
boolean_to_string
Returns true or false for a Perl boolean. The strings true and false, and undef, are returned as they are.
iso8601_date_time
Returns any object with an epoch method, such as Time::Piece or DateTime, as a UTC date in ISO 8601 format. Anything else is returned as it is, so a date can also be given as a string.
Inside a hash, Time::Piece->gmtime returns a list of date parts instead of an object, and that breaks the options. Keep the date in a variable first, or use scalar:
my $send_at = gmtime(time + 3600); # with "use Time::Piece"
$client->messages->create($to, { schedule_type => 'fixed', send_at => $send_at });
iso8601_date
Returns any object with an epoch method as a UTC date in the form 2026-11-06, for values that have no time. Anything else is returned as it is.
json_object
Returns a hash or array reference as JSON. Anything else is returned as it is, so a value can also be given as text that is already JSON.
json_body
my $sent = Twilio::Serialize::json_body($body, { sendAt => 'iso8601_date_time' });
Returns a copy of a JSON body, ready to be encoded. The rules name the top-level fields that need a conversion: iso8601_date, iso8601_date_time, or boolean, which turns a Perl boolean, or the text true or false, into a JSON boolean. Below the top level, any object with an epoch method is written as an ISO 8601 date and time, and everything else is sent as it is, so use \1 and \0 for booleans there. undef is an empty body, and anything else that is not a hash reference dies.
map_values
my $sent = Twilio::Serialize::map_values($types, \&Twilio::Serialize::json_object);
Returns a new array reference with the function applied to each element. Anything that is not an array reference is returned as it is.
prefixed_collapsible_map
my $params = Twilio::Serialize::prefixed_collapsible_map(
{ payfone_tcpa_compliance => { RightPartyContactedDate => '20160101' } }, 'AddOns');
# { 'AddOns.payfone_tcpa_compliance.RightPartyContactedDate' => '20160101' }
Returns a hash reference with one entry for each value in a nested hash, named by the prefix and the keys that lead to it, joined with dots. Arrays inside are walked by index, as twilio-php does. undef returns an empty hash, and anything else that is not a hash reference dies.
path_segment
Returns a value encoded for use as one part of a URL path. It croaks when the value is undefined or empty.
LICENSE
Copyright (c) 2026 Francisco Zarabozo. Released under the MIT License.