Using Perl to write PHP

MGLEE on 2003-10-06T13:42:00

Her indoors wants an e-commerce web site to sell table mats <link posted + discount to journal readers when available >. Despite enthusing about Perl and using it daily, I actually prefer to write dynamic websites in PHP <hiss boo>. Its quick, simple, very easy to prototype, and if an ISP is offering PHP then you know your site will work, rather than having to negotiate module installation and/or maintaining your own mini-CPAN in your user directory.

Most of the donkey work going on behind the scenes in an e-commerce site is simply writing and retrieving data from a database, and adding things together once in a while. My object model might require a dozen classes, although the attributes of each class are very different, the methods are very similar.

  • Store this object.
  • Retrieve this object
  • Show me a list of objects that fulfill these criteria.
I guess I could write a meta-class and identify the common functionality between each class and overload when needed. But this becomes a maintenance nightmare when you try to extend the system and have to walk through the code to find what functionality is coming from where.

So to automate the creation of my PHP I've reduced the various classes to a simple XML template. This template is parsed by a Perl script which not only spits out a fully formed PHP class from the template but also writes the common 'store', 'retrieve', 'retrieveLike' methods too. All thats left is for me to write the unique methods for the classes, about 3 or 4 per class. I dont have to worry about the simple methods, since I know they'll work (sure I'm going to test anyway), any errors I made in the template will tend to be very obvious since the class wont look like the object model or wont interface with the database. Now I have a templating system to help me rapidly create new PHP classes when I need them.

Cool or what !


are you willing to share your perl code?

felixhuber on 2003-10-08T18:36:55

that sounds really interesting!

are you willing to share your perl code?

i would appreciate that

thanks

regards, felix

Re:are you willing to share your perl code?

MGLEE on 2003-10-09T12:49:23

No problem. Its not really suitable for CPAN as its very much a personal tool, but once I'm sure its working as I intended, I shall release it.

Re:are you willing to share your perl code?

huberfelix on 2003-10-10T13:00:37

cool thanks!