I would go for 5:

5. Keep the official enumeration in the database; query the database to generate code that contains appropriate constants/enums. Have to make sure your code generation really occurs when the database changes. Could automate this as part of the build/test process.

But please note that you don't need to do this as part of the build/test process, but you can also do this at compile time in a BEGIN block.

BEGIN { use DBI; my $dbh = DBI->connect( dsn,user,password ); my $result = $dbh->some sort of query that generates name/value pa +irs; no strict 'refs'; # allow for using variables to make subs foreach (@$result) { *{$_->[0]} = eval "sub () { $_->[1] }"; # use constant on vari +ables } }
That should ensure that your constants are up to date for each run, as opposed to each build/test cycle.

Liz

Update:
As thor pointed out, this could be construed as going with #4, but I was more thinking along the lines of SHOW COLUMNS FROM table LIKE 'columnname' and associated magic as can e.g. be found on the MySQL site.


In reply to Re: Synchronizing constants/enums in database and code by liz
in thread Synchronizing constants/enums in database and code by seattlejohn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.