Get more from you constants with constant::more

One of my 'nuts and bolts' modules is constant::more. It declares constants, just like constant , however also gives you the ability to set these values in a consistent way from the command line or environment variables.

This can give module authors constants with 'default values', and allow the top level application code to override from the command line if they choose.

This has worked well for my needs to date. I've just released v0.3.0 with some additional features I feel make it even more useful and might make it more useful for others:

Flat list of for multiple constants

Originally I made the interface only work like constant for simple use cases. This meant multiple constants had to be inside a hash ref of actually multiple use constant::more... lines.

use constant::more {CONST1=>1, CONST2=>2};

Now a flat list is usable, which I personally find much more appealing:

use constant::more CONST1=>1, CONST2=>2;

Enumerations

Borrowing the basic syntax from the enum, a flat list can now specify enumerations if the first name contains an '='. So the above example could be written as:

use constant::more qw<CONST1=1 CONST2>;

Each subsequent item in the list increments the enumerated value. Each name that contains a '=' sets the constant (from then left) to the value (on the right).

As for future features, I'll don't anticipate adding anything anytime soon. However, suggestions are welcome!

Leave a comment

About drclaw

user-pic I blog about Perl.