[Petal] Class::DBI and Petal

William McKee william at knowmad.com
Fri Sep 19 16:50:46 BST 2003


Hi All,

Here's an interesting side effect of the TAL syntax used by Petal that I
thought you might appreciate.

I have just started using Class::DBI in one of my projects. For those
unfamiliar with this module, it's a thin glue over the DBI. I've tried
another package called DBIx::RecordSet and have rolled my own module for
simple database reads and updates in the past. Class::DBI seems to be a
nice compromise between these two options.

Anyhow, I have a loop in one of my templates like so:

<option petal:repeat="rate rates" petal:content="rate/country"
petal:attr="value rate/country">Country</option>

Using my module, I was passing in a list of hash references that looked
like the following:

	{
		'country' => 'AFGHANISTAN'
	},
	{
		'country' => 'ALBANIA'
	},
	....

When I replaced my function that generated the list of countries by a
Class::DBI object, the same template code shown earlier continued to work
without modification even though the list was now populated by objects
instead of hashrefs. This feature appears to be due to the fact that
Class::DBI creates accessors for each fieldname.

You've got to appreciate it when your software "does the right thing."


William

-- 
Knowmad Services Inc.
http://www.knowmad.com


More information about the Petal mailing list