Config...pAsData(3pm)
π Config::Model::DumpAsData π
okay so bestie, welcome to Config...pAsData(3pm) β that's the Config::Model::DumpAsData page from the User Contributed Perl Documentation, and it's literally the glow-up your config tree deserves β¨
π NAME π
Config::Model::DumpAsData β turns your config content into a perl data structure. It's giving "dump it, bestie." π
πΈ VERSION πΈ
version 2.166 β yes, she's current, she's hydrated, she's thriving π¦
β¨ SYNOPSIS β¨
Here's the whole vibe, copy-paste ready, no cap:
use Config::Model ;
use Data::Dumper ;
# define configuration tree object
my $model = Config::Model->new ;
$model ->create_config_class (
name => "MyClass",
element => [
[qw/foo bar/] => {
type => 'leaf',
value_type => 'string'
},
baz => {
type => 'hash',
index_type => 'string' ,
cargo => {
type => 'leaf',
value_type => 'string',
},
},
],
) ;
my $inst = $model->instance(root_class_name => 'MyClass' );
my $root = $inst->config_root ;
# put some data in config tree the hard way
$root->fetch_element('foo')->store('yada') ;
$root->fetch_element('bar')->store('bla bla') ;
$root->fetch_element('baz')->fetch_with_id('en')->store('hello') ;
# put more data the easy way
my $steps = 'baz:fr=bonjour baz:hr="dobar dan"';
$root->load( steps => $steps ) ;
print Dumper($root->dump_as_data);
# $VAR1 = {
# 'bar' => 'bla bla',
# 'baz' => {
# 'en' => 'hello',
# 'fr' => 'bonjour',
# 'hr' => 'dobar dan'
# },
# 'foo' => 'yada'
# };
Likeβ¦ look at that output. So tidy. So organized. The baz hash is alphabetized-ish and everything just works. Obsessed ππ
π DESCRIPTION π
So what's actually going on here? Bestie, let me tell you:
This module is used directly by Config::Model::Node to dump the content of a configuration tree into a perl data structure. You're not really supposed to summon it yourself, it's more like the backstage crew making the show happen π«Ά
The perl data structure it makes is a hash of hash. That's the whole vibe. The only exception: CheckList content gets stored in an array ref instead. That's it, that's the one plot twist π
You can also pass a sub reference to apply to values of boolean type. What's the point? Well, this sub can convert the value into an object that represents a boolean β like boolean, for example. (since 2.129) Fancy, right? π
Also important, don't skip this part: undefined values are skipped for list elements. So if your list element contains ('a',undef,'b'), then the resulting data structure contains 'a','b'. The undef just ghosts the party and nobody talks about it π
π§ CONSTRUCTOR π§
new
No parameter. That's it, that's the whole thing π
She should be used only by Config::Model::Node. Don't be out here calling her up directly, that's not the move, iykyk.
π« Methods π«
dump_as_data
Returns a perl data structure. Slay. β¨
Parameters are:
nodeβ Reference to aConfig::Model::Nodeobject. Mandatory β like, you actually need this one, no skipping πfull_dumpβ Also dumps the default values into the data structure. Super useful if the dumped configuration data is going to be used by the application. BUT β οΈ this parameter is deprecated in favor of themodeparameter. So likeβ¦ she's iconic but she's retired.modeβ Note that the"mode"parameter is also accepted and it overrides the"full_dump"parameter. If you want the details on"mode", go look at"fetch"inConfig::Model::Value. That's where the lore lives πskip_auto_writeβ Skip nodes that have a"perl write"capability in their model. SeeConfig::Model::BackendMgrfor that.
This option must be used when you're using DumpAsData to write back configuration data. Why? Because when a configuration model contains several backends β one at the tree root and others in tree nodes β setting this option makes sure that the "root" configuration file does not contain data that's duplicated in the configuration files of the other tree nodes. Basically: no duplicates, no mess, we love a clean root π
auto_vivifyβ Scan and create data for nodes elements even if no actual data was stored in them. This may be useful to trap missing mandatory values. Like a vibe check for your config β if something's missing, you'll know π₯ordered_hash_as_listβ By default, ordered hash (i.e. the order of the keys is important, we care) is dumped as a Perl list. This is the faster way to dump such hashes while keeping the key order. But it's the less readable way. Speed vs. beauty, the eternal struggle π
When this parameter is 1 (default), the ordered hash is dumped as a list:
my_hash => [ A => 'foo', B => 'bar', C => 'baz' ]
When this parameter is set as 0, the ordered hash is dumped with a special key that specifies the order of keys. E.g.:
my_hash => {
__my_hash_order => [ 'A', 'B', 'C' ] ,
B => 'bar', A => 'foo', C => 'baz'
}
to_booleanβ Sub reference to map a value of type boolean to a boolean class (since2.129). For instance:
to_boolean => sub { boolean($_[0]); }
Default is:
sub { return $_[0] }
β οΈ heads up bestie:full_dumpis deprecated,modeoverrides it, andskip_auto_writeis not optional when you're writing config data back. Don't fumble those, fr fr.
π AUTHOR π
Dominique Dumont, (ddumont at cpan dot org) π«Ά
π SEE ALSO π
Config::Model, Config::Model::Node, Config::Model::ObjTreeScanner
(the whole friend group, honestly πΈ)
π AUTHOR π
Dominique Dumont
π COPYRIGHT AND LICENSE π
This software is Copyright (c) 2005-2022 by Dominique Dumont.
This is free software, licensed under:
The GNU Lesser General Public License, Version 2.1, February 1999
and that's the whole page, bestie! π She's perl v5.42.3, dated 2026-07-23, and she ate. No crumbs. Periodt. πβ¨π¦
π¦ where this page comes from
- ubuntu stonking: libconfig-model-perl 2.166-1 Β· LGPL-2.1-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms