Re: Code Generation in Perl
[prev]
[thread]
[next]
[Date index for 2004/06/16]
Tony Bowden wrote:
>>Given the XML file, a Perl script will generate the complete Perl code,
>>Class::DBI modules, templates, plugins, documentation and diagrams
>>automatically.
>
> Sounds nice.
>
> It'd sound even nicer to me if it wasn't tied to XML, being as how I
> detest XML.
>
> How easy would a YAML version, for example, be?
Using XML::Simple is very simple:
# sorted project properties (array)
my $project = XMLin(
$filename,
KeyAttr => 0,
ForceArray => ['table','field','rel']
);
This will return all the information from XML in this format (dumped by
Data::Dumper):
$VAR1 = {
'table' => [
{
'descriptor' => 'name',
'caption' => 'contact',
'name' => 'contact',
'field' => [
{
'notnull' => '1',
'caption' => 'first name',
'name' => 'name',
'type' => 'varchar',
'size' => '40'
},
{
'visible' => '1',
'caption' => 'organization',
'name' => 'organization',
'type' => 'varchar',
'size' => '40'
},
{
'caption' => 'address',
'name' => 'address',
'type' => 'varchar',
'size' => '40'
},
{
'caption' => 'city',
'name' => 'city',
'type' => 'varchar',
'size' => '40'
},
{
'caption' => 'state',
'name' => 'state',
'type' => 'varchar',
'size' => '40'
},
'caption' => 'country',
'name' => 'country',
'type' => 'varchar',
'size' => '40'
},
{
'caption' => 'work phone',
'name' => 'phone',
'type' => 'varchar',
'size' => '40'
},
{
'caption' => 'fax',
'name' => 'fax',
'type' => 'varchar',
'size' => '40'
},
{
'caption' => 'mobile',
'name' => 'mobile',
'type' => 'varchar',
'size' => '40'
},
{
'visible' => '1',
'caption' => 'e-mail',
'name' => 'email',
'type' => 'varchar',
'size' => '40'
},
{
'caption' => 'notes',
'name' => 'notes',
'type' => 'text'
}
]
}
],
'name' => 'sample',
'title' => 'Sample Application'
};
If YAML can give me a similar output, I don't see why we couldn't use it.
Nelson