From linux at codehelp.co.uk Wed Jan 10 14:50:34 2007 From: linux at codehelp.co.uk (Neil Williams) Date: Wed, 10 Jan 2007 22:50:34 +0000 Subject: [DCPM] Creating a module of objects Message-ID: <20070110225034.690d6d1d.linux@codehelp.co.uk> Starting with a few structs, I'm parsing an XML file to create objects for each, populating the objects and pushing the objects onto an array. I then insert that array into a hash, using the object name as the key, so that I have a single variable to return to the script. This works fine when all this is local to the current script but I want to reuse these objects now and I fancy creating a new module to do it. It may even turn up on CPAN eventually. Example struct: struct (Expense => { form_of_payment => '$', distance_unit => '$', expense_vendor => '$', expense_city => '$', expense_attendees => '$', category => '$', expense_note => '$', type_of_expense => '$', guid => '$', expense_amount => '$', expense_date => '$', currency_code => '$', kvp_mnemonic => '$', kvp_string => '$', kvp_fraction => '$', }); sub QSFParse { my $file = $_; my $xs1 = XML::Simple->new(); my $doc = $xs1->XMLin($file, forcearray => [ 'guid' ]); parse_objects($doc); $object_list{'pilot_address'} = @contacts; $object_list{'pilot_expenses'} = @expenses; $object_list{'gpe_expenses'} = @expenses; $object_list{'pilot_datebook'} = @appointments; $object_list{'Split'} = @splits; $object_list{'Account'} = @accounts; $object_list{'Trans'} = @transactions; return %object_list; } parse_objects just creates and populates each object. 1. I'm missing an new() function and I'm not sure what should go in one - the objects are created during the parse, new doesn't seem to have anything to do. 2. How do I dereference the arrays in the script calling the module? If I simply do: my @splits = $object_list{'Split'}; my @transactions = $object_list{'Trans'}; my @accounts = $object_list{'Account'}; my $trans_count = @transactions; my $acc_count = @accounts; my $split_count = @splits; then each *_count == 1, whatever the incoming file contains. Any good references on objects and modules? -- 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/20070110/d80f19b6/attachment.bin From steve at devon-it.co.uk Wed Jan 10 15:59:56 2007 From: steve at devon-it.co.uk (Steve Marvell) Date: Wed, 10 Jan 2007 23:59:56 +0000 Subject: [DCPM] Creating a module of objects In-Reply-To: <20070110225034.690d6d1d.linux@codehelp.co.uk> References: <20070110225034.690d6d1d.linux@codehelp.co.uk> Message-ID: <20070110235956.GB24607@devon-it.co.uk> Neil Williams wrote: > Any good references on objects and modules? OO perl is a goodie and Extending and Embedding has a fantastic bit on building modules for CPAN. You'll find that the manual pages on OO are good too. Steve From steve at devon-it.co.uk Wed Jan 10 16:05:30 2007 From: steve at devon-it.co.uk (Steve Marvell) Date: Thu, 11 Jan 2007 00:05:30 +0000 Subject: [DCPM] Creating a module of objects In-Reply-To: <20070110225034.690d6d1d.linux@codehelp.co.uk> References: <20070110225034.690d6d1d.linux@codehelp.co.uk> Message-ID: <20070111000530.GC24607@devon-it.co.uk> Neil Williams wrote: > 1. I'm missing an new() function and I'm not sure what should go in one > - the objects are created during the parse, new doesn't seem to have > anything to do. Do you actually need an instance of this object or is it just a library of functions. I can envisage: my $objections = Objections->new($xmlfile); > 2. How do I dereference the arrays in the script calling the module? If > I simply do: my @splits = $object_list{'Split'}; > my @transactions = $object_list{'Trans'}; > my @accounts = $object_list{'Account'}; > > my $trans_count = @transactions; > my $acc_count = @accounts; > my $split_count = @splits; > > then each *_count == 1, whatever the incoming file contains. Personally, I'd use array references. This will get you all in step for Perl 6. I hardly use hashes and arrays in most contexts. I favour the references. I must admit, I'm still not sure what you are actually doing :) Steve From aaron.trevena at gmail.com Thu Jan 11 01:46:44 2007 From: aaron.trevena at gmail.com (Aaron Trevena) Date: Thu, 11 Jan 2007 09:46:44 +0000 Subject: [DCPM] Creating a module of objects In-Reply-To: <20070110235956.GB24607@devon-it.co.uk> References: <20070110225034.690d6d1d.linux@codehelp.co.uk> <20070110235956.GB24607@devon-it.co.uk> Message-ID: On 10/01/07, Steve Marvell wrote: > Neil Williams wrote: > > > Any good references on objects and modules? > > OO perl is a goodie and Extending and Embedding has a fantastic bit on > building modules for CPAN. OO Perl is gem of a book, the 'recaps' on both Perl and basic OO are worth the price of the book alone, and the rest of the book is very helpful, and best of all most of the things he discusses are now implemented and available from CPAN. > You'll find that the manual pages on OO are good too. Yup, but the manual pages on OO don't mention the nice cpan classes you can use to make life easier like Class::Accessor. I love CPAN, me :) A. -- http://www.aarontrevena.co.uk LAMP System Integration, Development and Hosting From linux at codehelp.co.uk Thu Jan 11 03:46:37 2007 From: linux at codehelp.co.uk (Neil Williams) Date: Thu, 11 Jan 2007 11:46:37 +0000 Subject: [DCPM] Creating a module of objects In-Reply-To: <20070111000530.GC24607@devon-it.co.uk> References: <20070110225034.690d6d1d.linux@codehelp.co.uk> <20070111000530.GC24607@devon-it.co.uk> Message-ID: <20070111114637.566123a8.linux@codehelp.co.uk> On Thu, 11 Jan 2007 00:05:30 +0000 Steve Marvell wrote: > Neil Williams wrote: > > > 1. I'm missing an new() function and I'm not sure what should go in one > > - the objects are created during the parse, new doesn't seem to have > > anything to do. > > Do you actually need an instance of this object or is it just a > library of functions. Only one function, really: FooParse. Accepts an XML file to pass to XML::Simple and returns an array of objects read from the file. I may want a second function FooWrite later. > Personally, I'd use array references. Thanks, it's working now. > I must admit, I'm still not sure what you are actually doing :) > > Steve I've attached the working module. Basically, I'm trying to make it trivial to parse a particular (generic) XML format that is used by a variety of my programs by hiding all the XML stuff and just providing an array of objects where the object members are exact matches for the object members in the original C source code and in the XML itself. Objects belong to pilot-qof, cashutil / gnucash and gpe-expenses and more will be added later. The snippet in the module pod content does a simple calculation of the total number of miles claimed from a pilot-qof XML file. pilot-qof provides the query interface to isolate the expenses on a variety of criteria (client, date range etc.) and the script just provides a useful summary output. Subsequent scripts will collate data from pilot-qof into a gnucash style invoice. The XML format is prescribed by the XML schema within the QOF backend code - applications linked against QOF provide their object definitions, the library creates the XML format for those objects from the definition and the script parses the XML format to provide an array where members are described by the same definition. -- 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: QOFQSF.pm Type: text/x-perl Size: 11809 bytes Desc: not available Url : http://mail.pm.org/pipermail/devoncornwall-pm/attachments/20070111/41d0c2d6/attachment-0002.bin -------------- 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/20070111/41d0c2d6/attachment-0003.bin From steve at devon-it.co.uk Mon Jan 15 11:11:01 2007 From: steve at devon-it.co.uk (Steve Marvell) Date: Mon, 15 Jan 2007 19:11:01 +0000 Subject: [DCPM] maypole on debian stable Message-ID: <20070115191101.GA25318@devon-it.co.uk> I'm going to give it a go. Anyone running it on stable? Steve From simon at technocool.net Mon Jan 15 13:19:51 2007 From: simon at technocool.net (Simon Waters) Date: Mon, 15 Jan 2007 21:19:51 +0000 Subject: [DCPM] maypole on debian stable In-Reply-To: <20070115191101.GA25318@devon-it.co.uk> References: <20070115191101.GA25318@devon-it.co.uk> Message-ID: <45ABEFF7.5090402@technocool.net> Steve Marvell wrote: > I'm going to give it a go. > > Anyone running it on stable? No, we have Catalyst on stable, but we went the CPAN route for getting the relevant versions of Perl modules, which isn't ideal. Depending when the "delivery date' is, I'd say "go Etch", unless you really need the revenue from upgrading the server from Sarge to Etch next month (or "when it is ready"). Etch will have packaged versions of Catalyst and Maypole, but I'm pretty sure the Catalyst will be out of date before it ships. Possibly Maypole is more mature, and a slightly older but stable version will get you further? Simon -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 288 bytes Desc: OpenPGP digital signature Url : http://mail.pm.org/pipermail/devoncornwall-pm/attachments/20070115/9cf09d52/attachment.bin From steve at devon-it.co.uk Mon Jan 15 13:22:51 2007 From: steve at devon-it.co.uk (Steve Marvell) Date: Mon, 15 Jan 2007 21:22:51 +0000 Subject: [DCPM] maypole on debian stable In-Reply-To: <45ABEFF7.5090402@technocool.net> References: <20070115191101.GA25318@devon-it.co.uk> <45ABEFF7.5090402@technocool.net> Message-ID: <20070115212251.GA27385@devon-it.co.uk> Simon Waters wrote: > Depending when the "delivery date' is, I'd say "go Etch", unless you > really need the revenue from upgrading the server from Sarge to Etch > next month (or "when it is ready"). Pet project, so I'll wait. Steve From simon at technocool.net Mon Jan 15 13:30:48 2007 From: simon at technocool.net (Simon Waters) Date: Mon, 15 Jan 2007 21:30:48 +0000 Subject: [DCPM] maypole on debian stable In-Reply-To: <20070115212251.GA27385@devon-it.co.uk> References: <20070115191101.GA25318@devon-it.co.uk> <45ABEFF7.5090402@technocool.net> <20070115212251.GA27385@devon-it.co.uk> Message-ID: <45ABF288.5080801@technocool.net> Steve Marvell wrote: > Simon Waters wrote: > >> Depending when the "delivery date' is, I'd say "go Etch", unless you >> really need the revenue from upgrading the server from Sarge to Etch >> next month (or "when it is ready"). > > Pet project, so I'll wait. Why wait, I have Etch box at work, not serving stuff, but my desktop/test box. It is still a tad dynamic for operational servers but it is doing the job. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 288 bytes Desc: OpenPGP digital signature Url : http://mail.pm.org/pipermail/devoncornwall-pm/attachments/20070115/ccda69f0/attachment.bin From steve at devon-it.co.uk Mon Jan 15 13:32:06 2007 From: steve at devon-it.co.uk (Steve Marvell) Date: Mon, 15 Jan 2007 21:32:06 +0000 Subject: [DCPM] maypole on debian stable In-Reply-To: <45ABF288.5080801@technocool.net> References: <20070115191101.GA25318@devon-it.co.uk> <45ABEFF7.5090402@technocool.net> <20070115212251.GA27385@devon-it.co.uk> <45ABF288.5080801@technocool.net> Message-ID: <20070115213206.GA27516@devon-it.co.uk> Simon Waters wrote: > >> Depending when the "delivery date' is, I'd say "go Etch", unless you > >> really need the revenue from upgrading the server from Sarge to Etch > >> next month (or "when it is ready"). > > > > Pet project, so I'll wait. > > Why wait, I have Etch box at work, not serving stuff, but my > desktop/test box. It is still a tad dynamic for operational servers but > it is doing the job. I keep my box parallel with my my clients. Steve From aaron.trevena at gmail.com Tue Jan 16 01:09:30 2007 From: aaron.trevena at gmail.com (Aaron Trevena) Date: Tue, 16 Jan 2007 09:09:30 +0000 Subject: [DCPM] maypole on debian stable In-Reply-To: <20070115213206.GA27516@devon-it.co.uk> References: <20070115191101.GA25318@devon-it.co.uk> <45ABEFF7.5090402@technocool.net> <20070115212251.GA27385@devon-it.co.uk> <45ABF288.5080801@technocool.net> <20070115213206.GA27516@devon-it.co.uk> Message-ID: On 15/01/07, Steve Marvell wrote: > > Why wait, I have Etch box at work, not serving stuff, but my > > desktop/test box. It is still a tad dynamic for operational servers but > > it is doing the job. > > I keep my box parallel with my my clients. I gave up on that - I don't get to choose my client's boxes half the time, and I can't be bothered to upgrade rather than update small virtual machines with only ports 80 and 22 open, so I'm dealing with fedora (at home), RH9 on one virtual server (due for upgrade in march hopefully), RHEL on another virtual server and Debian on one client's cluster and freebsd on yet another. I have maypole versions 2.10 to 2.12(from SVN) running on various machines against various versions of mysql and postgres :) If you want to try Maypole I would suggest grabbing a checkout from SVN - it's pretty much what 2.12 will be when I release it some time later this month. I would especially reccomend trying out Data::FormValidator (Maypole::Model::CDBI::DFV) over CGI::Untaint as it is the Mutt's nutts. Cheers, A. -- http://www.aarontrevena.co.uk LAMP System Integration, Development and Hosting From steve at devon-it.co.uk Thu Jan 25 09:11:41 2007 From: steve at devon-it.co.uk (Steve Marvell) Date: Thu, 25 Jan 2007 17:11:41 +0000 Subject: [DCPM] xml hell Message-ID: <20070125171141.GA22409@devon-it.co.uk> Why is it so hard to write a simple XML well fordness checker? I don't care if it's an undefined element, I want to know of the tags match or not, etc. How hard can that be? Steve From steve at devon-it.co.uk Thu Jan 25 09:15:18 2007 From: steve at devon-it.co.uk (Steve Marvell) Date: Thu, 25 Jan 2007 17:15:18 +0000 Subject: [DCPM] xml hell In-Reply-To: <20070125171141.GA22409@devon-it.co.uk> References: <20070125171141.GA22409@devon-it.co.uk> Message-ID: <20070125171518.GA22613@devon-it.co.uk> Steve Marvell wrote: > How hard can that be? It can be XML::Simple, but with an eval! Steve From aaron.trevena at gmail.com Fri Jan 26 08:02:43 2007 From: aaron.trevena at gmail.com (Aaron Trevena) Date: Fri, 26 Jan 2007 16:02:43 +0000 Subject: [DCPM] xml hell In-Reply-To: <20070125171518.GA22613@devon-it.co.uk> References: <20070125171141.GA22409@devon-it.co.uk> <20070125171518.GA22613@devon-it.co.uk> Message-ID: On 25/01/07, Steve Marvell wrote: > Steve Marvell wrote: > > > How hard can that be? > > It can be XML::Simple, but with an eval! Sweet :) I'm actually rather happy with Perl's XML offerings.. XML::Twig, XML::DOM and XML::Simple cover most of the bases, and I've never needed to use SaX yet, as Twig makes it almost redundant. cheers, A. -- http://www.aarontrevena.co.uk LAMP System Integration, Development and Hosting