Re: Code Generation in Perl

[prev] [thread] [next] [Date index for 2004/06/16]

From: Nelson Ferraz
Subject: Re: Code Generation in Perl
Date: 00:25 on 16 Jun 2004
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

(message missing)

Code Generation in Perl
Nelson Ferraz 18:25 on 15 Jun 2004

Re: Code Generation in Perl
Allen Day 18:38 on 15 Jun 2004

Re: Code Generation in Perl
Nelson Ferraz 23:58 on 15 Jun 2004

Re: Code Generation in Perl
Tim Bunce 08:51 on 16 Jun 2004

Re: Code Generation in Perl
Nelson Ferraz 13:57 on 16 Jun 2004

Re: Code Generation in Perl
Tim Bunce 15:44 on 16 Jun 2004

Re: Code Generation in Perl
Tony Bowden 20:00 on 15 Jun 2004

Re: Code Generation in Perl
Nelson Ferraz 00:25 on 16 Jun 2004

RE: Code Generation in Perl
Addison, Mark 11:24 on 16 Jun 2004

Re: Code Generation in Perl
Allen Day 23:52 on 16 Jun 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52