in reply to Best method for dynamic page generation?

I congratulate you on being organized. For small apps, it's good.. for large apps, it's invaluable.

You seem to be using a 2 layer system. But until you flush out the details, I won't say much more on what exactly you are doing. I'm more of the MVC system - model, view, controller. Your model layer would be all your db interfaces (selectUsers(...), updateUser(...)). Your view would take the output and render it somehow. Your controller ties the two, taking care of input/output manipulation and choices.

For your database stuff, you have your DB.pm, which is good. In the case you switch or want to use other DBs, you can swap this layer out with ease, keeping a consistent interace.

For my controler, I would take the input and tarnslate it into XML documents. XML is very portable. Not the uber most efficent way in terms of CPU cycles, but what you lose in performance, you gain in great modulariztion.

Using XSLT, you can then translate into PDF, HTML, WAP, CSV, TXT, since your XML document is a complete description of your data.


For the model/DB stuff, you have little choice but to use DBI + perl. There are other ways, but DBI is prolly the most standard.

For the controler/decision making portion and the XSLT translation, there's a great tutorial at perl-xml.sourceforge.net


There are many arguments against much of this.

XML is slow to process - prototype your system. Using XML would be idiotic to do IPC between threads. The native forms are faster. Using it between systems is quite smart, especially foreign ones, ala web-services. In complex systems, it is also "good". Translating XML to any other formats is quite easy. Translating doc to applewrite format would be a pain. If the speed difference is negligible, I would go with an XML based solution.

XSLT is slow - Many web browsers support XSLT translation on the client end. It would be a matter of giving the XML and XSLT to the browser. For repeditive stuff, such as perlmonks comments, which have a definite pattern, the XML would be sent all the time as really small packets, but the XSLT once. Think of XSLT like CSS.

XML/XSLT are bloated. - mod_gzip is your friend. XML compresses quite well. Also, if you transmit the XSLT once and different XML packets using the same XSLT, you may not even need mod gzip since XSLT would be the work horse.

MVC is slower - MVC may be slower, but you reap the same benefits as you do from writting modules and functions and calling them. Yes, you have the overhead of a stack, but then again, if you want efficiency, you can always use ASM


MVC and XML/XSLT aren't the only ways. You can always do 2 or even 1 layer systems. Sometimes they are better since a project can be really REALLY tiny. XML/XSLT may be too slow for your system if you are working on an 8mhz machine, an embeded device or on a heavily loaded machine with no money to buy another. It's all a matter of choices and architecting what's best for your situation, monitarily and for current and future development.

Play that funky music white boy..
  • Comment on Re: Best method for dynamic page generation?

Replies are listed 'Best First'.
Re: Re: Best method for dynamic page generation?
by tilly (Archbishop) on Jan 04, 2004 at 00:31 UTC
    What is using XSLT really buying you?

    If you have the discipline to keep it clean, there is no reason to convert to XML only to have to introduce a new language and a lot of overhead. Instead you can construct the views in Perl, likely using the various templating modules to organize it.

    If you do this, then you'll likely find no practical performance difference between MVC and any other approach.

      Well, it provides a level of modularity. If I switch from perl, to c++, to java.. there are API's that deal with turning XML to XSLT. So if I have 100 templates, and decide to switch languages, I can do so with ease.

      There are XSLT compilers, so you can gain some performance over ones that do a live string scan.

      XML isn't always slow; Using SAX, it's quite fast. I'd suggest writing a SAX implemented XML parser and see for yourself. It's almost no different from a templating engine. And as I said before, XSLT/XML aren't always THE choice. It's A choice that can take some serious consideration.

      New language? perl is your language, xslt would be your template language. How is it any different from using perl and HTML::Template or HTML::Mason? If your argument is against templating engines, yes, you now have HTML, (your templating engine), perl and your sql language. But that's how life is. You weigh out the advantages and make choices.


      Play that funky music white boy..
Re: Re: Best method for dynamic page generation?
by stonecolddevin (Parson) on Jan 04, 2004 at 00:25 UTC
    Alright, so what I am getting (and DO correct me if I am wrong), is:
    • Use an XML document as my template
    • Extract text from the db
    • Use a perl module to format the text/data against the XML

    Close to correct?


    "and I wonder, when I sing along with you if everything could ever feel this real forever? if anything could ever be this good again? the only thing I'll ever ask of you, you've gotta promise not to stop when I say 'when'", she sang
      Use XSLT as your template engine, generate XML documents. That's how I've done some systems.

      Play that funky music white boy..