[DCPM] shorthand required
Neil Williams
linux at codehelp.co.uk
Sat Feb 17 13:39:59 PST 2007
On Fri, 16 Feb 2007 12:55:16 +0000
"Aaron Trevena" <aaron.trevena at gmail.com> wrote:
> Hi Neil,
>
> Your XML creation seems incredibly verbose.
I know.
It wouldn't matter if I could collapse it into 3 lines for all
parameters of all objects, instead of 3 lines per parameter, per object.
Note that this isn't just XML creation, it is XML writing,
SQLite queries and other, as yet unwritten, methods too.
> I would suggest two things :
> 1) try using XML::DOM::BagOfTricks
> (http://search.cpan.org/~teejay/XML-DOM-BagOfTricks-0.05/lib/XML/DOM/BagOfTricks.pm)
> which allows you to do create complex XML tags in a single statement.
Just now, I'd rather stick with XML::Simple and XML::Writer.
> 2) Create a dictionary holding source and destination fieldnames and
> loop through that - a simple array of hashes (to preserve any
> necessary ordering) should be fairly simple then you could do stuff
> like:
>
> $destination_object->$destination_fieldname($source_object->$source_fieldname)
> if ($source_object->$source_fieldname);
I'm not sure if I follow you here. There is no 'destination' object and
I don't see how to convert a struct into this dictionary.
Take a small struct:
struct (ToDo => {
"todo_note" => '$', #string (perl: string)
"todo_description" => '$', #string (perl: string)
"category" => '$', #string (perl: string)
"guid" => '$', #guid (perl: string of hexadecimal characters only)
"date_due" => '$', #time (perl: string passed to time2str)
"todo_priority" => '$', #gint32 (perl: integer)
"todo_complete" => '$', #gint32 (perl: integer)
"todo_length" => '$', #gint32 (perl: integer)
});
I get as far as:
my @todos = ('todo_note' => 'string',
'todo_description' => 'string',
'category' => 'string',
'guid' => 'guid',
'date_due' => 'time',
'todo_priority' => 'gint32',
'todo_complete' => 'gint32',
'todo_length' => 'gint32');
But I'm not at all sure that I follow how to get to:
> $destination_object->$destination_fieldname($source_object->$source_fieldname)
> if ($source_object->$source_fieldname);
How does that cope with objects that have different numbers of
different types of parameters, all with different names? How is
the 'dictionary' created and populated?
I've already got a hash of array references where the arrays contain
instances of the structs containing the data.
--
Neil Williams
=============
http://www.data-freedom.org/
http://www.nosoftwarepatents.com/
http://www.linux.codehelp.co.uk/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/devoncornwall-pm/attachments/20070217/1d323c5f/attachment.bin
More information about the Devoncornwall-pm
mailing list