1use Config::Std; 2use Test::More 'no_plan'; 3 4my $output_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 27ok eval{ write_config %data => $output_file } => 'Write succeeded'; 28 29ok open(my $fh, '<', $output_file) => 'File created'; 30 31ok my $config = do{ local $/; <$fh> } => 'File read'; 32 33ok my $orig_config = do{ local $/; <DATA> } => 'DATA loaded'; 34 35is $orig_config, $config => 'Content correct'; 36 37 38__DATA__ 39 40def 2: def val 2 41 42def 3 ml: def val 3 43 : across several 44 : lines 45 46def1: def val 1 47 48[Complex named!!!] 49 50%^$%$#%: curses 51 52123456789: zero 53 54[Named] 55 56hi there: What's your name??? 57 58list: a 59list: list 60list: of 61list: values 62list: all different 63 64