perldoc > AppConfig::State

📛 NAME

AppConfig::State - application configuration state

🚀 Quick Reference

Use CaseCommandDescription
🆕 Create state objectmy $state = AppConfig::State->new(\%cfg)Create a new configuration state object
📝 Define a variable$state->define("foo")Define a simple variable
🔧 Define with options$state->define("bar", { DEFAULT => 99, ALIAS => 'metavar1' })Define with configuration hash
⚡ Compact define$state->define("foo|bar|baz=i")Define with aliases and argument count
âœī¸ Set variable$state->set("foo", 123)Set variable value
🔍 Get variable$state->get("foo")Get variable value
🚀 Shortcut access$state->foo() or $state->foo(456)Access or set variable via method
📋 List variablesmy %vars = $state->varlist("^file")Extract variables matching pattern
🔧 Validate variable$state->_validate($varname, $value)Check if value passes validation

📖 SYNOPSIS

use AppConfig::State;

my $state = AppConfig::State->new(\%cfg);

$state->define("foo");            # very simple variable definition
$state->define("bar", \%varcfg);  # variable specific configuration
$state->define("foo|bar=i@");     # compact format

$state->set("foo", 123);          # trivial set/get examples
$state->get("foo");

$state->foo();                    # shortcut variable access
$state->foo(456);                 # shortcut variable update

📚 OVERVIEW

AppConfig::State is a Perl5 module to handle global configuration variables for perl programs. It maintains the state of any number of variables, handling default values, aliasing, validation, update callbacks and option arguments for use by other AppConfig::* modules.

AppConfig::State is distributed as part of the AppConfig bundle.

📝 DESCRIPTION

đŸ› ī¸ USING THE AppConfig::State MODULE

To import and use the AppConfig::State module the following line should appear in your Perl script:

use AppConfig::State;

The AppConfig::State module is loaded automatically by the new() constructor of the AppConfig module.

AppConfig::State is implemented using object-oriented methods. A new AppConfig::State object is created and initialised using the new() method. This returns a reference to a new AppConfig::State object.

my $state = AppConfig::State->new();

This will create a reference to a new AppConfig::State with all configuration options set to their default values. You can initialise the object by passing a reference to a hash array containing configuration options:

$state = AppConfig::State->new( {
    CASE      => 1,
    ERROR     => \&my_error,
} );

The new() constructor of the AppConfig module automatically passes all parameters to the AppConfig::State new() constructor. Thus, any global configuration values and variable definitions for AppConfig::State are also applicable to AppConfig.

The following configuration options may be specified.

âš™ī¸ DEFINING VARIABLES

The "define()" function is used to pre-declare a variable and specify its configuration.

$state->define("foo");

In the simple example above, a new variable called "foo" is defined. A reference to a hash array may also be passed to specify configuration information for the variable:

$state->define("foo", {
        DEFAULT   => 99,
        ALIAS     => 'metavar1',
    });

Any variable-wide GLOBAL values passed to the new() constructor in the configuration hash will also be applied. Values explicitly specified in a variable's define() configuration will override the respective GLOBAL values.

The following configuration options may be specified:

đŸ“Ļ DEFINING VARIABLES USING THE COMPACT FORMAT

Variables may be defined in a compact format which allows any ALIAS and ARGS values to be specified as part of the variable name. This is designed to mimic the behaviour of Johan Vromans' Getopt::Long module.

Aliases for a variable should be specified after the variable name, separated by vertical bars, '|'. Any ARGS parameter should be appended after the variable name(s) and/or aliases.

The following examples are equivalent:

$state->define("foo", {
        ALIAS => [ 'bar', 'baz' ],
        ARGS  => '=i',
    });

$state->define("foo|bar|baz=i");

🔄 READING AND MODIFYING VARIABLE VALUES

AppConfig::State defines two methods to manipulate variable values:

Both functions take the variable name as the first parameter and "set()" takes an additional parameter which is the new value for the variable. "set()" returns 1 or 0 to indicate successful or unsuccessful update of the variable value. If there is an ACTION routine associated with the named variable, the value returned will be passed back from "set()". The "get()" function returns the current value of the variable.

Once defined, variables may be accessed directly as object methods where the method name is the same as the variable name. i.e.

$state->set("verbose", 1);

is equivalent to

$state->verbose(1);

Without parameters, the current value of the variable is returned. If a parameter is specified, the variable is set to that value and the result of the set() operation is returned.

$state->age(29);        # sets 'age' to 29, returns 1 (ok)

📋 VARLIST

The varlist() method can be used to extract a number of variables into a hash array. The first parameter should be a regular expression used for matching against the variable names.

my %vars = $state->varlist("^file");   # all "file*" variables

A second parameter may be specified (any true value) to indicate that the part of the variable name matching the regex should be removed when copied to the target hash.

$state->file_name("/tmp/file");
$state->file_path("/foo:/bar:/baz");

my %vars = $state->varlist("^file_", 1);

# %vars:
#    name => /tmp/file
#    path => "/foo:/bar:/baz"

🔧 INTERNAL METHODS

The internal (private) methods of the AppConfig::State class are listed below. They aren't intended for regular use and potential users should consider the fact that nothing about the internal implementation is guaranteed to remain the same. Having said that, the AppConfig::State class is intended to co-exist and work with a number of other modules and these are considered "friend" classes. These methods are provided, in part, as services to them. With this acknowledged co-operation in mind, it is safe to assume some stability in this core interface.

âœī¸ AUTHOR

Andy Wardley, <abw AT wardley.org>

ÂŠī¸ COPYRIGHT

Copyright (C) 1997-2007 Andy Wardley. All Rights Reserved.

Copyright (C) 1997,1998 Canon Research Centre Europe Ltd.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

🔍 SEE ALSO

AppConfig, AppConfig::File, AppConfig::Args, AppConfig::Getopt

AppConfig::State
📛 NAME 🚀 Quick Reference 📖 SYNOPSIS 📚 OVERVIEW 📝 DESCRIPTION
đŸ› ī¸ USING THE AppConfig::State MODULE âš™ī¸ DEFINING VARIABLES đŸ“Ļ DEFINING VARIABLES USING THE COMPACT FORMAT 🔄 READING AND MODIFYING VARIABLE VALUES 📋 VARLIST 🔧 INTERNAL METHODS
âœī¸ AUTHOR ÂŠī¸ COPYRIGHT 🔍 SEE ALSO

Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-29 05:26 @216.73.217.46
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^