NAME

Database::BI::Util - Shared utility functions for Database::BI modules

SYNOPSIS

use Database::BI::Util qw(urlencode);
my $safe = urlencode($query_param_value);

DESCRIPTION

Small helpers shared by the plain-Perl modules (Database::BI::Ask, Database::BI::Insights) that build URLs without depending on Mojolicious. Nothing is exported by default.

FUNCTIONS

urlencode

my $encoded = urlencode($str);

Percent-encodes a string for use as a URI query-parameter value. Preserves the RFC 3986 unreserved characters (A-Z a-z 0-9 - . _ ~) and replaces all other bytes with %XX uppercase hex escapes. A decoded string is encoded as UTF-8 first; a string of bytes is taken as it stands.

API SPECIFICATION

INPUT

$str   # string or undef

OUTPUT

'string'   # percent-encoded; undef gives ''

Each character outside the unreserved set is encoded from its code point, so a character above 0xFF must be encoded to UTF-8 bytes first (Encode::encode_utf8). The application only passes ASCII column names and specs.

parse_number

Read a table cell as a number, or say it is not one.

parse_number('$1,234.56');    # 1234.56
parse_number('(1,234.56)');   # -1234.56
parse_number('USD 100');      # 100
parse_number('SKU123');       # undef

API SPECIFICATION

INPUT

$value: string, optional

OUTPUT

A number, or undef if the value is missing, empty, holds anything other than a number and its currency or thousands formatting, or is too large to be finite.

AUTHOR

Nigel Horne <njh@nigelhorne.com>

LICENCE AND COPYRIGHT

Copyright 2026 Nigel Horne.

Usage is subject to the GPL2 licence terms.