Config-INI-RefVars
view release on metacpan or search on metacpan
t/09-args.t view on Meta::CPAN
'a var' => '42',
'additional' => 'yet another tocopy var!',
'foo' => 'override!'
},
'sec-B' => {
'#foo' => 'foo with hash',
'additional' => 'yet another tocopy var!',
'foo' => 'override!'
}
},
'variables()');
$obj->parse_ini(src => $src,
tocopy_vars => { '#hash' => 'other value',
'12=ab' => 42,
'foo' => 'sec:$(=)',
'#foo' => 'foo with hash'
},
cleanup => 0
);
local $Global{'=TO_CP_SEC'} = 'TOCOPY!';
is_deeply($obj->variables,
{
'TOCOPY!' => {
'#foo' => 'foo with hash',
'#hash' => 'other value',
'12=ab' => '42',
'=' => 'TOCOPY!',
%Global,
'=srcname' => 'INI data',
'additional' => 'yet another tocopy var!',
'foo' => 'override!'
},
'sec-A' => {
'#foo' => 'foo with hash',
'12=ab' => '42',
'=' => 'sec-A',
%Global,
'=srcname' => 'INI data',
'a var' => '42',
'additional' => 'yet another tocopy var!',
'foo' => 'override!'
},
'sec-B' => {
'#foo' => 'foo with hash',
'12=ab' => '42',
'=' => 'sec-B',
%Global,
'=srcname' => 'INI data',
'additional' => 'yet another tocopy var!',
'foo' => 'override!'
}
},
'variables(), cleanup => 0');
};
};
subtest "backup / restore" => sub {
my $orig_tocopy_section = "!all!";
my $src = ['[sec]'];
my $orig_expected = {
$orig_tocopy_section => {
'a' => '1',
'b' => '2',
'c' => '3',
'd' => '4'
},
'sec' => {
'a' => '1',
'b' => '2',
'd' => '4'
}
};
my $obj = Config::INI::RefVars->new(tocopy_section => $orig_tocopy_section,
tocopy_vars => { a => 1,
b => 2,
c => 3,
d => 4
},
not_tocopy => ['c']
);
is($obj->tocopy_section, $orig_tocopy_section, 'tocopy_section() / after new()');
subtest "parse_ini() without further args" => sub {
$obj->parse_ini(src => $src);
is_deeply($obj->variables, $orig_expected, 'variables(), orig');
};
my $other_tocopy_section = "TOCOPY SECTION";
subtest "parse_ini() with tocopy_section" => sub {
my $expected = {
$other_tocopy_section => dclone($orig_expected->{$orig_tocopy_section}),
'sec' => dclone($orig_expected->{sec})
};
$obj->parse_ini(src => $src, tocopy_section => $other_tocopy_section);
is($obj->tocopy_section, $orig_tocopy_section, 'tocopy_section() restored by parse_ini()');
is_deeply($obj->variables, $expected, 'variables(), changed tocopy section name');
$obj->parse_ini(src => $src);
is_deeply($obj->variables, $orig_expected, 'variables(), back to orig');
};
subtest "parse_ini() with tocopy_vars" => sub {
$obj->parse_ini(src => $src, tocopy_vars => {c => "c-value", x => "x-value"});
is_deeply($obj->variables,
{
'!all!' => {
'c' => 'c-value',
'x' => 'x-value'
},
'sec' => {
'x' => 'x-value'
}
},
'variables(), changed tocopy vars');
$obj->parse_ini(src => $src);
( run in 0.535 second using v1.01-cache-2.11-cpan-f56aa216473 )