1use Config::Std; 2use Test::More 'no_plan'; 3 4my $input_file = 'test.cfg'; 5 6my %data = ( 7 # Default section... 8 '' => { 9 'def1' => 'def val 1', 10 'def 2' => 'def val 2', 11 'def 3 ml' => "def val 3\nacross several\n lines", 12 }, 13 14 # Named section... 15 'Named' => { 16 'hi there' => q{What's your name???}, 17 'list' => [qw(a list of values), 'all different'], 18 }, 19 20 # Complex named section... 21 'Complex named!!!' => { 22 123456789 => 'zero', 23 '%^$%$#%' => 'curses', 24 }, 25); 26 27my %config; 28 29ok eval{ read_config $input_file => %config } => 'Read succeeded'; 30diag( $@ ) if $@; 31 32is_deeply \%data, \%config => 'Data correct'; 33 34$config{Extra}{'key 1'} = 'extra key 1'; 35push @{$config{Named}{list}}, 'an extra line'; 36 37ok eval{ write_config %config } => 'Write succeeded'; 38 39ok open(my $fh, '<', $input_file) => 'File opened'; 40 41ok my @config = <$fh> => 'File read'; 42 43ok my @extra = <DATA> => 'DATA loaded'; 44 45is_deeply [@extra[-4..-1]], [@config[-4..-1]] => 'Extra content correct'; 46 47__DATA__ 48[Extra] 49 50key 1: extra key 1 51 52