[Catalyst] Clean access to config from outside Cat?

Jesse Sheidlower jester at panix.com
Thu Jun 18 09:50:30 GMT 2009


I included this as part of a long question yesterday about
testing, but I realize that perhaps it's better as a separate
question.

Basically, I have a standard Catalyst config file, where
the database connection section looks like this:

<Model::LibraryDB>
	schema_class Library::Schema::Main
	connect_info DBI:mysql:host=localhost;database=library_test
	connect_info library_test_user
	connect_info library_test_password
	<connect_info>
		mysql_enable_utf8 1
	</connect_info>
</Model::LibraryDB>

I'd like to get access to this information from a script
running outside of Catalyst. How can I do this cleanly?
I grab the file with:

my %config = Config::General->new($config_file)->getall;

But then this leaves me with ugliness like

  $my user_name = $config{'Model::LibraryDB'}->{'connect_info'}->[1];

And getting the database name requires regexing the first
connect_info line. Is there some other Cat-approved way of
setting up the config file so that this information is easily
available both to an external program and to Cat? I suppose I
can put this into a plain variable up front, switch on
variable interpolation, and then include the variables in the
connect info, but I haven't seen this done with Cat before.

Jesse Sheidlower



More information about the Catalyst mailing list