Introducing constant::string and constant::string::uc

If you're like me, you use a constant a lot (I may overuse it). I often use it to turn typos in words and fields into compile-time errors, and for that I usually create constants that either are the named the same as the word, or the word uppercased, like this

use constant +{ SERVICE => 'Service', INSTANCE => 'Instance' };

or

use constant +{ map +( $_ => $_ ), @constants }

and doing that too many times inspired the creation of constant::string and constant::string::uc.

Basically they are very thin wrappers over constant, creating the words as constants, either as is or in uppercase

The equivalent code using these new modules

use constant::string::uc qw/SERVICE INSTANCE/;

and

use constant::string @constants;

Leave a comment

About James

user-pic I blog about Perl.