libconfig-simple-perl (4.59-5) non_word_chars.patch

Summary

 Simple.pm    |    2 -
 t/colors.ini |   10 +++++++++
 t/colors.t   |   62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+), 1 deletion(-)

    
download this patch

Patch contents

Description: change regexp for splitting "key = value" pairs in the ini style parser,
 otherwise it chokes on non "word" chars
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=546534
Bugs-CPAN: http://rt.cpan.org/Public/Bug/Display.html?id=49682
Author: gregor herrmann <gregoa@debian.org>
Last-Update: 2010-07-16

--- a/Simple.pm
+++ b/Simple.pm
@@ -287,7 +287,7 @@
     # parsing the block name:
     $line =~ /^\s*\[\s*([^\]]+)\s*\]$/       and $bn = lcase($1), next;
     # parsing key/value pairs
-    $line =~ /^\s*([^=]*\w)\s*=\s*(.*)\s*$/  and $data{$bn}->{lcase($1)}=[parse_line(READ_DELIM, 0, $2)], next;
+    $line =~ /^\s*([^=]+?)\s*=\s*(.*)\s*$/   and $data{$bn}->{lcase($1)}=[parse_line(READ_DELIM, 0, $2)], next;
     # if we came this far, the syntax couldn't be validated:
     $errstr = "syntax error on line $. '$line'";
     return undef;    
--- /dev/null
+++ b/t/colors.ini
@@ -0,0 +1,10 @@
+; Config::Simple 4.59
+; Mon Sep 14 21:02:18 CEST 2009
+
+[colors]
+average (2009) = blue
+average (2009 = blue
+average (2009)a = blue
+average (2010)=blue
+average (2010=blue
+average (2010)a=blue
--- /dev/null
+++ b/t/colors.t
@@ -0,0 +1,62 @@
+#!/usr/bin/perl -w
+# Before `make install' is performed this script should be runnable with
+# `make test'. After `make install' it should work as `perl 1.t'
+
+#########################
+
+use strict;
+use Test;
+use Data::Dumper;
+use FindBin '$RealBin';
+use File::Spec;
+BEGIN {
+  plan tests => 30;
+}
+
+use Config::Simple;
+ok(1);
+#########################
+
+# Insert your test code below, the Test::More module is use()ed here so read
+# its man page ( perldoc Test::More ) for help writing this test script.
+
+my $ini_file = File::Spec->catfile($RealBin, 'colors.ini');
+
+my $cfg = new Config::Simple();
+ok($cfg);
+ok($cfg->read($ini_file));
+ok($cfg->param('colors.average (2009)') eq 'blue');
+ok($cfg->param('colors.average (2009') eq 'blue');
+ok($cfg->param('colors.average (2009)a') eq 'blue');
+ok($cfg->param('colors.average (2010)') eq 'blue');
+ok($cfg->param('colors.average (2010') eq 'blue');
+ok($cfg->param('colors.average (2010)a') eq 'blue');
+ok($cfg->block() == 1);
+my $vars = $cfg->vars();
+ok($vars->{'colors.average (2009)'} eq 'blue');
+ok($vars->{'colors.average (2009'} eq 'blue');
+ok($vars->{'colors.average (2009)a'} eq 'blue');
+ok($vars->{'colors.average (2010)'} eq 'blue');
+ok($vars->{'colors.average (2010'} eq 'blue');
+ok($vars->{'colors.average (2010)a'} eq 'blue');
+ok($cfg->param(-name=>'colors.average (2009)', -value =>'blue'));
+ok($cfg->param(-name=>'colors.average (2009', -value =>'blue'));
+ok($cfg->param(-name=>'colors.average (2009)a', -value =>'blue'));
+ok($cfg->param(-name=>'colors.average (2010)', -value =>'blue'));
+ok($cfg->param(-name=>'colors.average (2010', -value =>'blue'));
+ok($cfg->param(-name=>'colors.average (2010)a', -value =>'blue'));
+
+# testing get_block():
+ok( ref($cfg->param(-block=>'colors')) eq 'HASH' );
+ok( $cfg->param(-block=>'colors')->{'average (2009)'} eq 'blue');
+ok( $cfg->param(-block=>'colors')->{'average (2009'} eq 'blue');
+ok( $cfg->param(-block=>'colors')->{'average (2009)a'} eq 'blue');
+ok( $cfg->param(-block=>'colors')->{'average (2010)'} eq 'blue');
+ok( $cfg->param(-block=>'colors')->{'average (2010'} eq 'blue');
+ok( $cfg->param(-block=>'colors')->{'average (2010)a'} eq 'blue');
+
+# now testing the new syntax:
+my $data = Config::Simple->parse_ini_file($ini_file);
+ok(ref($data) eq 'HASH');
+
+