[Catalyst] Constants that refer to rows in a lookup table.
    Bill Moseley 
    moseley at hank.org
       
    Wed May 23 00:14:04 GMT 2007
    
    
  
This is suppose to be an ORM-neutral question.
I often use lookup tables in the database, even for things like, say,
cart_status:
    create table cart_status (
        id      SERIAL PRIMARY KEY,
        name    text NOT NULL,
        active  boolean NOT NULL DEFAULT TRUE
    );
    -- trust the sequence, Luke
    insert into cart_status (name) values ('Pending');
    insert into cart_status (name) values ('Completed');
Then things like this are nice:
    [% cart.cart_status.name %]
And can do this:
    update cart_status set name = 'Finished' where name = 'Completed';
And add new lookup options:
    insert into cart_status (name) values ('Orphaned');
but this is not so nice:
    $cart_class->search( cart_status => 1 );
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
-- 
Bill Moseley
moseley at hank.org
    
    
More information about the Catalyst
mailing list