2
# Testcases for using perl hooks in Ini configuration files
9
BEGIN { $| = 1; plan tests => 13 }
17
# Get files from the 't' directory, portably
18
chdir('t') if ( -d 't' );
21
# Create ini object with allowcode Option set to 1
22
$ini = new Config::IniFiles(-file => 'hook.ini',
24
ok($ini->{allowcode});
27
# check standard parameter access
28
ok($ini->val('hooksection', 'testval') eq 'ok');
31
#check perl hook - accessing environment variables from a hooks sub
32
$ENV{'HOOK'}='PERLHOOK';
33
ok($ini->val('hooksection', 'envhook') eq 'PERLHOOK');
36
# check if a global sub can be called from a hook
42
ok($ini->val('hooksection', 'hooksub') eq 'HOOK(4711)');
45
#check if single elements of an array are evaluated
47
@hookary=$ini->val('hooksection', 'hookary');
51
ok($hookary[0] eq 'hook1');
54
ok($hookary[1] eq 'PERLHOOK');
57
ok($hookary[2] eq 'HOOK(4711)');
60
ok($hookary[3] eq 'hook4');
64
$ini->WriteConfig('hook_2.ini');
66
$ENV{'HOOK'}='PERLHOOK_2';
67
# check if perl hook still exist in the written file
68
$ini = new Config::IniFiles(-file => 'hook_2.ini',
70
ok($ini->val('hooksection', 'envhook') eq 'PERLHOOK_2');
73
# check if perl hook in here document still exists
74
@hookary=$ini->val('hooksection', 'hookary');
75
ok($hookary[1] eq 'PERLHOOK_2');
79
# check if -allowcode => 0 prohibits perl code in ini files
80
$ini = new Config::IniFiles(-file => 'hook.ini',
84
$ini->val('hooksection', 'hooksub');