[Catalyst] best practice: where to put constants
Tomas Doran
bobtfish at bobtfish.net
Thu Jun 4 15:31:41 GMT 2009
Jarom Smith wrote:
> In the end, this is what I decided to do because I have relatively few
> of these guys (so far) and I'd rather have them thrown together all in
> one place than spread all over the system. But I'm wondering if there
> is a best practice?
>
> I don't want to put them in the config hash or in a configuration file
> because these are not things that a user should be able to change or
> override.
Not sure this is the 'best practice' way of doing what you're trying to
achieve, but that aside - to answer your actual question:
I'd just put them all into their own package, and arrange for them to be
exportable, something like this:
package MyApp::Constants;
use strict;
use warnings;
use Exporter qw/import/;
use constant {
THING_FOO => 0,
THING_BAR => 1,
};
our @EXPORT = qw(
&THING_FOO
&THING_BAR
);
then just 'use MyApp::Constants;' where you need them, job done..
Cheers
t0m
More information about the Catalyst
mailing list