Config...:Setup(3pm)

πŸ’– NAME πŸ’–

Config::Model::Tester::Setup β€” the shared test-setup bestie for Config::Model. She's the 3pm page you're reading rn, and she exists so every test doesn't have to reinvent the whole "make me a fake config world" thing. πŸŽ€


🌸 VERSION 🌸

version 4.010 β€” yeah she's current, she's fresh, she ate. πŸ’…


✨ SYNOPSIS ✨

okay so this is literally the whole vibe, in code:

# in t/some_test.t
use warnings;
use strict;

use Config::Model::Tester::Setup qw/init_test setup_test_dir/;

my ($model, $trace) = init_test();

# pseudo root where config files are written by config-model as setup
# by init_test
my $wr_root = setup_test_dir();

Two lines of import and you're set up. Periodt. 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

This module provides 2 functions that build you a test environment fit for basically any test involving Config::Model. No cap, that's the entire job. Two little helpers, endless slay. ✨


πŸ‘‘ FUNCTIONS πŸ‘‘

🧚 init_test

She scans your test command line options and initialises a Config::Model object for you. Main character behaviour, lowkey.

She returns a list containing a Config::Model object, a boolean, and a hash. That boolean is true when the option --trace was used on the command line. πŸ‘€

The default command options are:

  • --error β€” When set, error handled by Config::Model::Exception shows a strack trace when dying. 😭 (yes, dying is the whole point here)
  • --log β€” When set, Log::Log4perl uses the config from file ~/.log4config-model or the default config provided by Config::Model. By default, only Error level and above are shown. Note that log tests are disabled when this option is set, so you may see a lot of harmless Warning messages during tests (which depend on the tests to be run). Experimental. πŸ™ˆ
  • --trace β€” the value of this option is given back to the caller of init_test. Usually, this value is used to show more information regarding the tests being run. πŸ”

More options can be passed to init_test using option definitions like the one defined in Getopt::Long. The value of the command line options are returned in the 3rd returned value. πŸ’œ

For instance, for a test named t/my_test.t calling:

init_test('foo', 'bar=s')

The test file can be run with:

perl t/my_test.t --foo --bar=baz --log --trace

init_test returns:

($model, 1, { foo => 1, bar => 'baz', log => 1 , trace => 1, error => 0 })

Look at that hash. Look at that 1. She really said "here's everything, bestie." πŸ”₯

🌈 setup_test_dir

Cleans up and creates a test directory in wr_root/test-script-name. For instance this function creates directory wr_root/foo for test t/foo.t. Cleanup + creation in one call, it's giving efficiency. ⭐

She returns a Path::Tiny object of the test directory β€” so you get a proper object back, not just a sad string. πŸ“

Heads up: init_test builds the pseudo root, and this is where config files get written by config-model β€” that's the whole reason the two are besties.

πŸ’… SEE ALSO πŸ’…

  • Config::Model
  • Test::More

(iykyk β€” go read both, they're iconic) 🌸


πŸŽ€ AUTHOR πŸŽ€

Dominique Dumont πŸ’–


This software is Copyright (c) 2013-2020, 2026 by Dominique Dumont.

This is free software, licensed under:

The GNU Lesser General Public License, Version 2.1, February 1999

okay that's the whole page, bestie, you're officially set up βœ¨πŸ’– and yes, this was perl v5.40.1, dated 2026-03-24, which is also exactly when this Config...:Setup(3pm) page said hi β€” slay, go write some tests. πŸ’…πŸ¦‹

πŸ“¦ where this page comes from