Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

rjbs (4671)

  (email not shown publicly)
AOL IM: RicardoJBSignes (Add Buddy, Send Message)
Yahoo! ID: RicardoSignes (Add User, Send Message)

I'm a Perl coder living in Bethlehem, PA and working Philadelphia. I'm a philosopher and theologan by training, but I was shocked to learn upon my graduation that these skills don't have many associated careers. Now I write code.

Journal of rjbs (4671)

Saturday June 07, 2008
10:22 AM

new distribution: config-ini-mvp-reader

[ #36609 ]

Some time ago, I wrote about Addex's config, which used a slight variation on INI files and really hit the spot for what I needed. It was possible because of the way Config::INI::Reader acts like a state machine, turning each line into a simple event that can be handled however you want. By default, of course, it mostly collects data and adds it to a structure.

With App::Addex::Config, each data section relates to a package, and that package may provide a method that says which named properties get multiple values and show up in the provided data as an arrayref.

In work on a new project, I found that I wanted this behavior again, and I finally refactored it into its own module, Config::INI::MVP::Reader.

I had a few more needs for the refactored version, so the output of the reader is now a bit odd, but very easy to handle, and you can have multiple sections for one plugin. The only downside, which really bothers me not at all, is that you can't "re-open" a section that you've started and then left.

Here's a sample of what you can do with MVP:

; given this .ini file as input:
name = Paprika Beans
edible = no

layout = standard

[Ingredient / paprika]
amount = 2 tsp

[Ingredient / water]
amount = 1 cup
step = pour

[Ingredient / beans]
amount = 1 cup
step = soak
step = boil
step = cool
step = mash
step = fry

You get this:

  { '=name' => '_', name => 'Paprika Beans', edible => 'no' },
  { '=name' => 'Kitchen', '=package' => 'Kitchen' },
  { '=name' => 'paprika', '=package' => 'Ingredient', amount => '2 tsp' },
  { '=name' => 'water',   '=package' => 'Ingredient', amount => '1 cup',
    step => [ qw(pour) ] },
  { '=name' => 'beans',   '=package' => 'Ingredient', amount => '1 cup',
    step => [ qw(soak boil cool mash fry) ] },

I consume this output by popping off the first element and using it to configure the application, and then instantiating plugins from each of the rest of the entries and adding them to the application.

I suspect that in the future, the stuff I'm working on will may need more sophisticated configuration, but it will be easy to allow other configuration formats. For now, this one is really nice and simple.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.