Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

MGLEE (4392)

  (email not shown publicly)

If any of this makes any sense yes I probably am that person : anatomy, anat0010, AND, Banbury, bookstack, Bristol, Community, ebookers, Fitz, GDM, ghosts, IFSBM, mondus, naming company, ox.test, Oxford, Oxdigital, spam, statistics.

Journal of MGLEE (4392)

Monday October 06, 2003
08:42 AM

Using Perl to write PHP

[ #15086 ]

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 !

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.