exported::constants - Declare constants and export them automatically
package MyProg::Constants; use exported::constants USER_TYPE_USER => 'U', USER_TYPE_APPLICATION => 'A', USER_TYPE_ROBOT => 'B', ; package MyProg::App; use MyProg::Constants; my @real_users = $users->search({ user_type => USER_TYPE_USER, });
This is a boilerplate-removal module for creating modules of just constants in your program. This is useful if you have a lot of magic numbers you want to eliminate, especially things that show up in database schemas or APIs that you want to re-use across multiple modules.
It's pretty simple to use; just say
use exported::constants CONSTANT1 => $value1, CONSTANT2 => $value2, ;
and your package is automatically an exporter, and automatically exports (by default) all the constants listed.
List constants don't work, because exported::constants is intended to always create multiple constants in a single invocation.
exported::constants
This module always works using @EXPORT in Exporter; this is unfortunate for developers who want to explicitly import all their constants.
@EXPORT
constant
Exporter
Jonathan Cast <jonathanccast@fastmail.fm>
Copyright 2017 Jonathan Cast
Licensed under the Apache License, Version 2.0 (the "License").
To install exported::constants, copy and paste the appropriate command in to your terminal.
cpanm
cpanm exported::constants
CPAN shell
perl -MCPAN -e shell install exported::constants
For more information on module installation, please visit the detailed CPAN module installation guide.