[Catalyst] best practice: where to put constants

Jarom Smith jarom at jaromsmith.net
Thu Jun 4 15:52:18 GMT 2009


Thanks t0m.  I will do the MyApp::Constants thing, thanks for the idea.

But out of curiosity... in your opinion, what *would* be the "best 
practice" way of doing what I'm trying to achieve?  (or was your comment 
"Not sure this is the 'best practice' way of doing what you're trying to 
achieve" referring to my way of doing things, and your opinion of best 
practice is the MyApp::Constants thing?)  Yeah, it appears that is what 
you meant...

I've been doing my thing in isolation for so long, I'm completely 
disconnected from best practices, which is why I'm asking...  that, and 
I am a bit of a Perl hack.  Being here is definitely raising my game!

jarom smith
tech go-to guy


Tomas Doran wrote:
> 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