Devel::StringInfo(3)

πŸ“¦
version 0.04 Β· 2 versions
, in fedora 43

πŸ¦‹ Devel::StringInfo β€” the manual page, but make it make sense πŸ¦‹

okay bestie, so this is a User Contributed Perl Documentation page for Devel::StringInfo(3). It's a debugging aid. It's giving detective energy. Let's get into it πŸ’…


✨ NAME ✨

Devel::StringInfo β€” gather information about strings. that's it, that's the whole vibe. it's the "what even IS this string" module πŸŽ€


🌸 SYNOPSIS 🌸

my $string = get_string_from_somewhere();

use Devel::StringInfo qw(string_info);

# warn()s a YAML dump in void context
string_info($string);

# the above is actually shorthand for:
Devel::StringInfo->new->dump_info($string);

# you can also customize with options:
my $d = Devel::StringInfo->new(
        guess_encoding => 0,
);

# and collect data instead of formatting it as a string
my %hash = $d->gather_data( $string );

warn "it's a utf8 string" if $hash{is_utf8};

so you can just call string_info($string) and let it warn at you, but under the hood that's literally the same as Devel::StringInfo->new->dump_info($string) β€” it's the shorthand, iykyk. and if you want to be extra (affectionate) you pass options to new, or grab the raw data with gather_data and check $hash{is_utf8} yourself like the main character you are πŸ”₯


πŸ’– DESCRIPTION πŸ’–

This module is a debugging aid that helps figure out more information about strings. it's your little investigative bestie πŸ•΅οΈβ™€οΈ

so here's the tea: Perl has two main "types" of strings, and you will get confused about which one you're holding.

  • unicode strings β€” where utf8::is_utf8 returns true ✨
  • octet strings β€” just a bunch of bytes, no thoughts, head empty πŸ’€

Depending on the source of the data, what data it interacted with, as well as the fact that Perl may implicitly upgrade octet streams which represent strings in the native encoding to unicode strings, it's sometimes genuinely hard to know what exactly is going on with a string. not me getting gaslit by my own scalar πŸ™ˆ

This module clumps together a bunch of checks you can perform on a string to figure out what's in it. one call, all the lore. periodt πŸ’…


πŸŽ€ EXPORTS πŸŽ€

This module optionally exports a string_info subroutine. It uses Sub::Exporter, so you can pass any options to the import routine, and they will be used to construct the dumper for your exported sub:

use Devel::StringInfo string_info => { guess_encoding => 0 };

yes, the options you pass at use time become the default vibe of your exported sub. iconic 🫢


⭐ ATTRIBUTES ⭐

  • guess_encoding β€” Whether or not to use Encode::Guess to guess the encoding of the data if it's not a unicode string. let it play detective, or don't πŸ”
  • encoding_suspects β€” The list of suspect encodings. See Encode::Guess. Defaults to the empty list, which is a special case for Encode::Guess. so like, no suspects named means Encode::Guess does its special thing. slay πŸ•΅οΈ
  • include_value_info β€” Include some information about the string value (does it contain 0x00 chars, is it alphanumeric, does it have newlines, etc). the little gossipy details about your string πŸ“
  • include_decoded β€” Whether to include a recursive dump of the decoded versions of a non unicode string. go deeper. inception but for encodings πŸŒ€
  • include_hex β€” Whether to include a Data::HexDump::XXD dump in dump_info. hex girlies rise 🌈
  • include_raw β€” Whether to include a simple interpolation of the string in dump_info. raw and unfiltered, no escaping, just vibes πŸ’œ

πŸ’… METHODS πŸ’…

dump_info $string, %extra_fields

Use YAML to dump information about $string. yep, YAML. we love a structured format ✨

In void context it prints, in other contexts it returns the dump string. so know where you're calling it or you'll be out here wondering why nothing came back 😭

If include_raw is set then a "raw" version (no escaping of the string) is appended with some boundry markings. This can help understand what's going on if YAML's escaping is confusing. honestly? yeah. YAML escaping will humble you.

If include_hex is set then Data::HexDump::XXD will be required and used to dump the value as well. so that module gets pulled in on demand, no cap πŸ”₯

gather_data $string, %opts

Gathers information about the string. the collector behavior, we stan 🌸

Calls various other gather_ methods internally.

Used by dump_info to dump the results. so dump_info is basically gather_data + a glow-up πŸ’–

In scalar context returns a hash reference, in list context key value pairs. know your context bestie, it changes everything.

All hash references are tied to Tie::IxHash in order to be laid out logically in the dump. so the ordering stays cute and sensible instead of randomized chaos πŸŽ€

%opts is not yet used but may be in the future. it's reserved. it's waiting for its moment. main character arc pending πŸ‘‘


🌈 AUTHOR 🌈

Yuval Kogman <nothingmuch@woobling.org>


Copyright (c) 2007 Yuval Kogman. All rights reserved
This program is free software; you can redistribute it and/or modify it
under the terms of the MIT license or the same terms as Perl itself.

okay so that's the whole page. this was documented by the fine people doing User Contributed Perl Documentation, running on perl v5.42.0, dated 2025-07-25. go forth and figure out what your strings are actually doing, bestie πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from