File::KDBX::Util(3pm)
π File::KDBX::Util π
okay bestie so this is the manual for File::KDBX::Util β section 3pm, and it lives in the User Contributed Perl Documentation. it's the lil toolbox full of utility functions for working with KDBX files, and honestly? it's giving β¨essentialβ¨. let's get into it π«Ά
π VERSION
this is version 0.906 π
β¨ FUNCTIONS β¨
π« load_xs
$bool = load_xs();
$bool = load_xs($version);
try to load File::KDBX::XS, babe. returns something truthy if it actually loaded π₯. and if you hand it a $version, it'll double-check that at least that version is the one loaded. no fakes allowed π
π« assert
assert { ... };
it's an executable comment!! literally a comment that runs. only executed if DEBUG is set in the environment, so it's like... a comment with main character energy πΈ
π« can_fork
$bool = can_fork;
tells you if perl can fork π΄. the logic is lifted straight from "CAN_FORK" in Test2::Util, no cap.
π« clone
$clone = clone($thing);
clones deeply π§¬. it's an unadorned alias to Storable's dclone, so no extra β¨spiceβ¨ β just a straight copy situation.
π« clone_nomagic
$clone = clone_nomagic($thing);
clones deeply but without keeping [most of] the magic β¨π«.
β οΈ WARNING: at the moment this implementation is naΓ―ve π and it will NOT respond well to nontrivial data or recursive structures. proceed with caution bestie.
π« DEBUG
a constant number that indicates the level of debuggingness π (yes that's the vibe, it's a number, it says how debuggy things are).
π« dumper
$str = dumper $thing;
dumper $thing; # in void context, prints to STDERR
like Data::Dumper but slightly terser in some cases that are relevant to File::KDBX π. if you call it in void context, it just prints to STDERR instead of returning a string. iykyk.
π« empty / nonempty
$bool = empty $thing;
$bool = nonempty $thing;
tests whether a thing is empty (or nonempty, obviously π). a thing counts as empty if it's one of these:
- nonexistent
undef- zero-length string
- zero-length array
- hash with zero keys
- reference to an empty thing (recursive, yes, we go deep π)
π note in particular that zero0is not considered empty β because0is an actual value, bestie, and we respect it π
π« erase
erase($string, ...);
erase(\$string, ...);
overwrites the memory used by one or more string(s). like, gone. poof. π§Ήβ¨ security girlie behavior.
π« erase_scoped
$scope_guard = erase_scoped($string, ...);
$scope_guard = erase_scoped(\$string, ...);
undef $scope_guard; # erase happens here
gets you a scope guard that'll make scalars get erased later β aka when the scope ends π. this is so useful when you want to make sure a string gets erased after you're done with it, even if the scope ends abnormally (drama happens π).
see "erase" above for the deets.
π« extends
extends $class;
sets up the current module to inherit from another module π§¬π
π« has
has $name => %options;
creates an attribute getter/setter. possible options:
"is"β either"rw"(that's the default) or"ro""default"β a default value"coerce"β a coercive function
π« format_uuid
$string_uuid = format_uuid($raw_uuid);
$string_uuid = format_uuid($raw_uuid, $delimiter);
formats a 128-bit UUID (given as a string of 16 octets) into a hexadecimal string π¦. optionally you can pass a $delimiter to break up the UUID visually into five parts. examples, bestie:
my $uuid = uuid('01234567-89AB-CDEF-0123-456789ABCDEF');
say format_uuid($uuid); # -> 0123456789ABCDEF0123456789ABCDEF
say format_uuid($uuid, '-'); # -> 01234567-89AB-CDEF-0123-456789ABCDEF
this is the inverse of "uuid" π
π« generate_uuid
$uuid = generate_uuid;
$uuid = generate_uuid(\%set);
$uuid = generate_uuid(\&test_uuid);
generates a brand new random UUID π²β¨. it's pretty unlikely this'll generate a repeat, but if you're the anxious type (same π), you can hand over either:
- a set of existing UUIDs β as a hashref where the keys are the elements of a set
- or a function to check for existing UUIDs
and this thing will make sure it doesn't return a UUID that's already in the set you gave it. maybe an example will make it crystal clear π:
my %uuid_set = (
uuid('12345678-9ABC-DEFG-1234-56789ABCDEFG') => 'whatever',
);
$uuid = generate_uuid(\%uuid_set);
# OR
$uuid = generate_uuid(sub { !$uuid_set{$_} });
here, $uuid can't be "12345678-9ABC-DEFG-1234-56789ABCDEFG" π«. this example uses "uuid" to easily pack a 16-byte UUID from a literal, but it otherwise is not a consequential part of the example, fr fr.
π« gunzip
$unzipped = gunzip($string);
decompresses an octet stream π¦β‘οΈβ¨
π« gzip
$zipped = gzip($string);
compresses an octet stream β¨β‘οΈπ¦
π« int64
$int = int64($string);
gets you a scalar integer capable of holding 64-bit values, initialized with a given default value π’. on a 64-bit perl it returns a regular SvIV. on a 32-bit perl it returns a Math::BigInt. flexible queen π
π« pack_Ql
$bytes = pack_Ql($int);
like "pack('Q<', $int)", but it also works on 32-bit perls π the little overachiever.
π« pack_ql
$bytes = pack_ql($int);
like "pack('q<', $int)", but also works on 32-bit perls π
π« unpack_Ql
$int = unpack_Ql($bytes);
like "unpack('Q<', $bytes)", but also works on 32-bit perls π
π« unpack_ql
$int = unpack_ql($bytes);
like "unpack('q<', $bytes)", but also works on 32-bit perls π¦
π« is_uuid
$bool = is_uuid($thing);
checks if a thing is a UUID β meaning a scalar string of length 16 π
π« list_attributes
@attributes = list_attributes($package);
gets you a list of attributes for a class πβ¨
π« load_optional
$package = load_optional($package);
loads a module that isn't required but can provide extra functionality π. if the module isn't available, it throws π€. no silent failures here.
π« memoize
\&memoized_code = memoize(\&code, ...);
memoizes a function π§ β¨. any extra arguments get passed through to &code when it gets called.
π« pad_pkcs7
$padded_string = pad_pkcs7($string, $block_size),
pads a block using the PKCS#7 method π§±π
π« query
$query = query(@where);
$query->(\%data);
generates a function that'll run a series of tests on a passed hashref and return true or false depending on whether the data record in the hash matched the specified logic π΅οΈβοΈβ¨
the logic can be specified in a manner similar to "WHERE CLAUSES" in SQL::Abstract β which was the inspiration for this function, bestie β but heads up: this code is distinct. it supports an overlapping but not identical feature set, and it has its own bugs π (we love honesty).
see "Declarative Syntax" in File::KDBX for examples π«Ά
π« query_any
gets you either a "query" or a "simple_expression_query", depending on the arguments you pass πβ¨
π« read_all
$size = read_all($fh, my $buffer, $size);
$size = read_all($fh, my $buffer, $size, $offset);
like "read FILEHANDLE,SCALAR,LENGTH,OFFSET" in perlfunc, BUT it returns "undef" if not all $size bytes are read π. that counts as an error, and you can tell it apart from other errors by the fact that $! is not set π
π« recurse_limit
\&limited_code = recurse_limit(\&code);
\&limited_code = recurse_limit(\&code, $max_depth);
\&limited_code = recurse_limit(\&code, $max_depth, \&error_handler);
wraps a function with a guard to prevent deep recursion ππ§ (protect urself from the spiral bestie)
π« search
# Generate a query on-the-fly:
\@matches = search(\@records, @where);
# Use a pre-compiled query:
$query = query(@where);
\@matches = search(\@records, $query);
# Use a simple expression:
\@matches = search(\@records, \'query terms', @fields);
\@matches = search(\@records, \'query terms', $operator, @fields);
# Use your own subroutine:
\@matches = search(\@records, \&query);
\@matches = search(\@records, sub { $record = shift; ... });
executes a linear search over an array of records using a "query" πβ¨. a "record" is usually a hash, just so you know.
π« simple_expression_query
$query = simple_expression_query($expression, @fields);
$query = simple_expression_query($expression, $operator, @fields);
generates a query, like "query", to be used with "search" β but built from a "simple expression" as described here: <https://keepass.info/help/base/search.html#mode_se> πΈ
so here's how an expression works, bestie:
- an expression is a string with one or more space-separated terms
- terms that have spaces in them can be enclosed in double quotes
"like this" - terms get negated if they're prefixed with a minus sign
- - a record must match every term on at least one of the given fields β
π« snakify
$string = snakify($string);
turns a CamelCase string into snake_case πβ¨ honestly iconic
π« split_url
($scheme, $auth, $host, $port, $path, $query, $hash, $usename, $password) = split_url($url);
splits a URL into its parts π¦βοΈ
for example, "http://user:pass@localhost:4000/path?query#hash" gets split like:
"http""user:pass""host"4000"/path""?query""#hash""user""pass"
π« to_bool / to_number / to_string / to_time / to_tristate / to_uuid
various typecasting / coercive functions πβ¨ (a whole squad of converters, slay)
π« trim
$string = trim($string);
the ubiquitous "trim" function π
. removes all whitespace from both ends of a string. the classic. the icon. the moment.
π« try_load_optional
$package = try_load_optional($package);
tries to load a module that isn't required but can provide extra functionality, and returns true if it worked β π
π« uri_escape_utf8
$string = uri_escape_utf8($string);
percent-encodes arbitrary text strings, like for a URI πβ¨
π« uri_unescape_utf8
$string = uri_unescape_utf8($string);
inverse of "uri_escape_utf8" π
π« uuid
$raw_uuid = uuid($string_uuid);
packs a 128-bit UUID (given as a hexadecimal string with optional "-"'s, like "12345678-9ABC-DEFG-1234-56789ABCDEFG") into a string of exactly 16 octets ππ¦
this is the inverse of "format_uuid" π
π« UUID_NULL
gets you the null UUID β aka a string of 16 null bytes π³οΈβ¨
π BUGS
pls pls pls report any bugs or feature requests on the bugtracker website π«Ά: <https://github.com/chazmcgarvey/File-KDBX/issues>
when you submit a bug or a request, please include a test-file or a patch to an existing test-file that illustrates the bug or the desired feature π (it makes everything so much easier bestie, we literally need the receipts)
π AUTHOR
Charles McGarvey <ccm@cpan.org> π
π COPYRIGHT AND LICENSE
this software is copyright (c) 2022 by Charles McGarvey.
this is free software ποΈ β you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. periodt π
and that's the whole page bestie!! this doc shipped with perl v5.40.1 and it's dated 2025-05-04 π go forth and use those utilities, you're gonna eat πβ¨
π¦ where this page comes from
- debian trixie: libfile-kdbx-perl 0.906-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libfile-kdbx-perl 0.906-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libfile-kdbx-perl 0.906-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms