Put this code in the base class for your Class::DBI-derived data class, and you can define meta-information (using Config::Scoped) for your database rows, including per-column data. The name of the file is mumble.cfg, where mumble is the last part of your CDBI class name, and is in the same directory.

The result produces a hash accessible by calling ->Config on either the class name or an instance. For example, if you want to know that the name column of the My::DB::Address should be displayed as a textfield of width 15, you can put this meta information in Address.cfg as

name { type = textfield width = 15 }
and then access that in Template Toolkit as:
type = row.Config.name.type; width = row.Config.name.width;

This box is too short to show more... I'm probably going to submit this as a separate module soon as a CDBI plugin.

sub Config { my $self = shift; my $class = ref $self || $self; ## compute filename relative to me, based on my packagename my $p = __PACKAGE__; (my $s = $class) =~ s/^\Q$p\E::// or die "$p is not prefix of $class +!"; $p = __FILE__; $p =~ s/\.pm$// or die "$p doesn't end with .pm!"; require File::Spec; my $file = File::Spec->catfile($p, split '::', $s) . ".cfg"; my $config = do { if (-e $file) { require Config::Scoped; Config::Scoped->new (file => $file, warnings => {qw(permissions off parameter off)}, )->parse; } else { {} } }; { no strict 'refs'; *{$class . '::Config'} = sub { $config }; } return $config; }

In reply to Associate a config file with a Class::DBI class for meta information by merlyn

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.