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 a Config::Model::Node object. 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 the mode parameter. 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" in Config::Model::Value. That's where the lore lives πŸ“–
  • skip_auto_write β€” Skip nodes that have a "perl write" capability in their model. See Config::Model::BackendMgr for 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 (since 2.129). For instance:
to_boolean => sub { boolean($_[0]); }

Default is:

sub { return $_[0] }
⚠️ heads up bestie: full_dump is deprecated, mode overrides it, and skip_auto_write is 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

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