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
and then access that in Template Toolkit as:name { type = textfield width = 15 }
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; }
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |