1Devel::StringInfo(3)  User Contributed Perl Documentation Devel::StringInfo(3)
2
3
4

NAME

6       Devel::StringInfo - Gather information about strings
7

SYNOPSIS

9               my $string = get_string_from_somewhere();
10
11               use Devel::StringInfo qw(string_info);
12
13               # warn()s a YAML dump in void context
14               string_info($string);
15
16
17
18               # the above is actually shorthand for:
19               Devel::StringInfo->new->dump_info($string);
20
21
22               # you can also customize with options:
23               my $d = Devel::StringInfo->new(
24                       guess_encoding => 0,
25               );
26
27
28               # and collect data instead of formatting it as a string
29               my %hash = $d->gather_data( $string );
30
31               warn "it's a utf8 string" if $hash{is_utf8};
32

DESCRIPTION

34       This module is a debugging aid that helps figure out more information
35       about strings.
36
37       Perl has two main "types" of strings, unicode strings ("utf8::is_utf8"
38       returns true), and octet strings (just a bunch of bytes).
39
40       Depending on the source of the data, what data it interacted with, as
41       well as the fact that Perl may implicitly upgrade octet streams which
42       represent strings in the native encoding to unicode strings, it's
43       sometimes hard to know what exactly is going on with a string.
44
45       This module clumps together a bunch of checks you can perform on a
46       string to figure out what's in it.
47

EXPORTS

49       This module optionally exports a "string_info" subroutine. It uses
50       Sub::Exporter, so you can pass any options to the import routine, and
51       they will be used to construct the dumper for your exported sub:
52
53               use Devel::StringInfo string_info => { guess_encoding => 0 };
54

ATTRIBUTES

56       guess_encoding
57           Whether or not to use Encode::Guess to guess the encoding of the
58           data if it's not a unicode string.
59
60       encoding_suspects
61           The list of suspect encodings. See Encode::Guess. Defaults to the
62           empty list, which is a special case for Encode::Guess.
63
64       include_value_info
65           Include some information about the string value (does it contain
66           0x00 chars, is it alphanumeric, does it have newlines, etc).
67
68       include_decoded
69           Whether to include a recursive dump of the decoded versions of a
70           non unicode string.
71
72       include_hex
73           Whether to include a Data::HexDump::XXD dump in "dump_info".
74
75       include_raw
76           Whether to include a simple interpolation of the string in
77           "dump_info".
78

METHODS

80       dump_info $string, %extra_fields
81           Use YAML to dump information about $string.
82
83           In void context prints, in other contexts returns the dump string.
84
85           If "include_raw" is set then a "raw" version (no escaping of the
86           string) is appended with some boundry markings. This can help
87           understand what's going on if YAML's escaping is confusing.
88
89           If "include_hex" is set then Data::HexDump::XXD will be required
90           and used to dump the value as well.
91
92       gather_data $string, %opts
93           Gathers information about the string.
94
95           Calls various other "gather_" methods internally.
96
97           Used by "dump_info" to dump the results.
98
99           In scalar context returns a hash reference, in list context key
100           value pairs.
101
102           All hash references are tied to Tie::IxHash in order to be layed
103           out logically in the dump.
104
105           %opts is not yet used but may be in the future.
106

AUTHOR

108       Yuval Kogman <nothingmuch@woobling.org>
109
111               Copyright (c) 2007 Yuval Kogman. All rights reserved
112               This program is free software; you can redistribute it and/or modify it
113               under the terms of the MIT license or the same terms as Perl itself.
114
115
116
117perl v5.38.0                      2023-07-20              Devel::StringInfo(3)
Impressum