Old modules never die...

ajt on 2004-01-15T20:45:55

A long time ago I wrote a configuration module in Perl. It was the first module I'd ever written, and I was happy with it. I never loaded it up to CPAN, partially because I wasn't confident enough, and partially because there is no shortage of Configuration reading modules on CPAN.

In the two years since, I've used the module quite a bit at home and at work. It's not great, but it does it's stuff, and it has proved reliable and useful. I'm starting a new project this year at work, and I will need a configuration module for it. I decided to dust off the old module and combine it with some more recent work I've done, and for the moment to remove the bits I never used in the original.

The new module is all nice and shiny, it's now an OO design, it has lots of tests (they all pass), and it preserves the best bits of the old module. I won't say it's perfect, but I'm happy with it, and it almost conforms to the coding standards we are now using at work. I've been doing my test to make small changes, run the tests, add more tests, make more small changes and so on. It's a really nice feeling to see "All tests successful." after each change!

Even though there is still no shortage of configuration readers on CPAN, I may upload this one, as it solves some unique problems I have. Though to be honest, I should also try and make some patches to ConfigReader::Simple which is the closest reader of those on CPAN I would want to use.


Patches

petdance on 2004-01-16T00:31:07

Send the patches to me, too, since I'm comaintaining brian's modules, and his lag time can be pretty crappy over in Iraq.

Re:Patches

ajt on 2004-01-16T18:00:23

I did gather that brian was quite busy at the moment.... I've downloaded the module, and if I can figure out a sane way of adding the features I want, I'll send you the patches.

The two things I want are:

  • Simple multi-line configuration.
  • Read the data in the callers __DATA__ section automatically.

If I can put them in without perverting the current module, then I'd rather do that than re-invent another circular object...

Re:Patches

petdance on 2004-01-16T18:37:40

I'll see what I can do...

Re:Patches

ajt on 2004-01-17T11:14:20

Ta. I uploaded my module to CPAN yesterday, Config::Trivial, and then started on patching ConfigReader::Simple.

I've not looked at changing the POD yet, but I've added the multi-line option, and updated the tests, and all seems well. I don't know if this breaks how some people have used the module in the past, but all the tests pass okay. If you are still interested, then I can do some more work and email you my version and the patch for you to look at.

diff -bBdru ConfigReader-Simple-1.17/lib/ConfigReader/Simple.pm ConfigReader-Simple-1.17A/lib/ConfigReader/Simple.pm
--- ConfigReader-Simple-1.17/lib/ConfigReader/Simple.pm Sun Nov 30 17:08:35 2003
+++ ConfigReader-Simple-1.17A/lib/ConfigReader/Simple.pm        Fri Jan 16 19:03:55 2004
@@ -273,6 +273,11 @@

        while( <CONFIG> )
                {
+        if (s/\\\s*$//)
+                       {
+                       $_ .= <CONFIG>;
+                       redo unless eof CONFIG;
+                       }
                chomp;
                next if /^\s*(#|$)/;

diff -bBdru ConfigReader-Simple-1.17/t/example.config ConfigReader-Simple-1.17A/t/example.config
--- ConfigReader-Simple-1.17/t/example.config   Fri Mar 29 00:04:05 2002
+++ ConfigReader-Simple-1.17A/t/example.config  Fri Jan 16 21:37:53 2004
@@ -7,3 +7,6 @@
Zero 0
Undef
#Faketest
+Test10 foo \
+bar \
+baz
diff -bBdru ConfigReader-Simple-1.17/t/get.t ConfigReader-Simple-1.17A/t/get.t
--- ConfigReader-Simple-1.17/t/get.t    Mon May 12 05:45:04 2003
+++ ConfigReader-Simple-1.17A/t/get.t   Fri Jan 16 21:44:23 2004
@@ -1,6 +1,6 @@
# $Id: get.t,v 1.4 2003/05/12 04:45:04 petdance Exp $

-use Test::More tests => 26;
+use Test::More tests => 30;

use ConfigReader::Simple;

@@ -20,6 +20,10 @@
is( $config->get( 'Zero' ),  0,, 'Zero has right value as number' );
is( $config->get( 'Undef' ), '', 'Undef has right value (empty)'  );

+# get long lines
+is( $config->get( 'Test10' ), 'foo bar baz', 'Test10 has right value');
+is( $config->Test10, 'foo bar baz') ;
+
# get things that do not exist
# using get
my $value = not defined $config->get( 'Test' );
@@ -45,6 +49,8 @@
        'Scope has right value with AUTOLOAD' );
is( $config->get( 'Test2' ), 'Test 2 value',
        'Test2 has right value with AUTOLOAD' );
+is( $config->get( 'Test10'), 'foo bar baz',
+       'Test10 has right value with AUTOLOAD' );

# try it one at a time
$config = ConfigReader::Simple->new( "t/example.config" );
@@ -53,6 +59,8 @@
        'Test3 has right value with get(), before global' );
is( $config->get( 'Test2' ), 'Test 2 value',
        'Test2 has right value with get(), before global' );
+is( $config->get( 'Test10' ), 'foo bar baz',
+       'Test10 has right value with get), before global' );

$config->add_config_file( "t/global.config" );
is( $config->get( 'Scope' ), 'Global',