AppConfig
view release on metacpan or search on metacpan
t/appconfig.t view on Meta::CPAN
}
my $ok_count = 1;
sub ok {
shift or print "not ";
print "ok $ok_count\n";
++$ok_count;
}
use AppConfig qw(:argcount);
$loaded = 1;
ok(1);
#------------------------------------------------------------------------
# define a new AppConfig object
#
my $default = "<default>";
my $anon = "<anon>";
my $noage = "<unborn>";
my $config = AppConfig->new({
GLOBAL => {
DEFAULT => $default,
ARGCOUNT => ARGCOUNT_ONE,
}
},
'verbose', {
DEFAULT => 0,
ARGCOUNT => ARGCOUNT_NONE,
},
'user', {
ALIAS => 'name|uid',
DEFAULT => $anon,
});
$config->define(
'age', {
DEFAULT => $noage,
VALIDATE => '\d+',
});
#------------------------------------------------------------------------
# check and manipulate variables
#
#2: check config got defined
ok( defined $config );
#3 - #5: check variables were defined
ok( $config->verbose() == 0 );
ok( $config->user() eq $anon );
ok( $config->age() eq $noage );
#6: read config file at DATA handle
ok( $config->file(\*DATA) );
#7 - #9: check values got updated correctly
ok( $config->verbose() == 1 );
ok( $config->user() eq 'abw' );
ok( $config->age() == 42 );
__DATA__
verbose = 1
user = abw
age = 42
( run in 0.893 second using v1.01-cache-2.11-cpan-39bf76dae61 )