[Catalyst] Constants that refer to rows in a lookup table.

Perrin Harkins perrin at elem.com
Wed May 23 23:45:14 GMT 2007


On 5/22/07, Bill Moseley <moseley at hank.org> wrote:
> So, what have you found that works nicely?
>
>     use MyApp::Const qw/ cart_pending /;  # potentially long list
>     cart_status => cart_pending  # runtime checking
>
>     use MyApp::Const qw/ :cart /; # Shorter list :)
>
>
>     cart_status => MyApp::CONST::pending, # global constants
>
>
>     # Make it very clear where a constant should be used
>     # by adding the constants as methods to the cart namespace
>
>     cart_status => $cart_class->pending_status

I think I've done all of these over the years.  Adding them as methods
is probably my favorite, but importing constants is okay (although I
use $CART_PENDING_STATUS so it will interpolate in strings).  Put the
constants in the cart class -- MyApp::Const becomes a mess very
quickly.

What bothers me about these is that I have the constants in two
places, but elaborate schemes to read them on startup always seemed
like they create more problems than they solve.

If I had one where the contents changed a lot at runtime, I would just
make a real ORM class for the lookup table and hope that my database
caches queries well.

- Perrin



More information about the Catalyst mailing list