novastorm0 has asked for the wisdom of the Perl Monks concerning the following question:

I have a problem that I just don't have enough experience to answer. I have some projects ranging from mini content portals to e-mail feedback forms that I would like accomplish over the next few years. The problem is I'm going to have relatively little free time to learn lots of new things.

I'm new to Perl but I've managed to use HTML::Template and CGI + mailer of choice to create a e-mail feedback form that lets you know what fields are wrong ect, has a simple spam preventing question etc. Now I can probably find a way to use HTML::Template + DBI + CGI to solve most my problems but I need to take the path of least resistance. Should I shift to apache/mod_perl/mason/dbi ? or should I forgo Perl all together and use *gasp* PHP? The last thing to add is I will continue to use Perl for other non-web reasons, so I'll be using Perl regardless.

If I had to creatively form my question in one line it would be "What is the shortest list of Perl modules you would need to master to become a Web Programming Ninja (because I cant devote enough time to become a Monk ;))?"

I know there are lots of ways to solve a problem, and there is certainly always a better way, but I really need to be looking to the future to the most flexible and future proof solution.

Thanks.
  • Comment on Perl, Web Apps, HTML::Template, HTML::Mason and the future

Replies are listed 'Best First'.
Re: Perl, Web Apps, HTML::Template, HTML::Mason and the future
by CountZero (Bishop) on Jun 11, 2008 at 19:26 UTC
    The simple questions are the most difficult to answer.

    The traditional answer would probably be CGI and (m)any of its derived modules (to manage sessions, authentication and authorization, ...), DBI and your choice of Templating System (Template::Toolkit springs to mind).

    A more modern answer would be Catalyst and any related modules in that namespace to handle your particular challenge. Again a templating system (see above) and DBIx::Class if you need a database.

    And I am probably forgetting a thousand other modules you cannot do without as my brethren will certainly point out!

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Catalyst looks very interesting. I've heard of it before but dismissed it fairly quickly (I didn't know much Perl at the time) DBIx is in. Now just to pick a template system..Template Toolkit seems to be popular. Do you have anything against HTML::Template for simple applications?

        Templating systems are like religions, so the answer strongly depends on who you ask, or who replies... ;)

        It's probably a good idea to try a few yourself to see which approach you like best.  This classic article might serve as a good introduction.

        I have nothing against HTML::Template and I'm quite sure that it can handle much more than simple applications.

        Template::Toolkit on the other hand is a more general templating solution which will equally well handle non-HTML / non-Web matters.

        I use it regularly to write LaTex files which when rendered make nice lay-outed PDF-files. Although not impossible to do, it would require more effort to do so from a less performant templating system.

        Its biggest strength is the way it can handle easily and elegantly, all kinds of data-structures (such as hashes of arrays of hashes of hashes of ...) and can use most of the standard Perl-modules (CGI, DBI, ...) directly from within itself. And before someone complains and starts a holy flame war: this indeed breaks the holy law of division of concerns and allows you to sneak in programming into your display layer, but sometimes it is damn handy to do so ...

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Perl, Web Apps, HTML::Template, HTML::Mason and the future
by perrin (Chancellor) on Jun 11, 2008 at 19:29 UTC
    It sounds like you're looking for this article. I would replace Class::DBI with Rose::DB::Object now, and I'd probably use CGI::Application instead of the basic CGI she shows. Then you can run your code under CGI or mod_perl or FastCGI.

      Just curious: why Rose::DB::Object over DBIx::Class?

        No offense to DBIx::Class, I just think RDBO is great. It has excellent docs, a great feature set, and the design seems very natural to me. The support on the mailing list is friendly and helpful, and a lot of people whose technical opinions I respect (merlyn, Ask Hansen, Bill Moseley) are on there and contributing.
Re: Perl, Web Apps, HTML::Template, HTML::Mason and the future
by Cody Pendant (Prior) on Jun 12, 2008 at 05:01 UTC
    If you're looking for the path of least resistance/shortest time, then you just need to add database access to the things you're already using.

    So, yes, just add DBI to CGI and HTML::Template, and you've got all the basics in place.

    I've built fairly large and complex websites with just those three elements.

    Of course it wouldn't be a bad idea to use Catalyst or CGI::Application, but the P of Least R is just to add one more module to your kit and get to work. You can always add those frameworks later, and you'll understand what they're doing better when you do.



    Nobody says perl looks like line-noise any more
    kids today don't know what line-noise IS ...
Re: Perl, Web Apps, HTML::Template, HTML::Mason and the future
by marcussen (Pilgrim) on Jun 12, 2008 at 05:54 UTC
Re: Perl, Web Apps, HTML::Template, HTML::Mason and the future
by alexm (Chaplain) on Jun 12, 2008 at 08:27 UTC
Re: Perl, Web Apps, HTML::Template, HTML::Mason and the future
by strfry() (Monk) on Jun 13, 2008 at 03:35 UTC
    Disclaimer/short version: I'm rather fond of frameworks for most things that last more than one application. For that matter, I often like them for just one application, too.

    I often prefer CGI::Application and Template Toolkit for small to medium sites and applications. Catalyst seems like a more robust framework, however, and as such offers quite a bit if you're going to be working on a lot of things for the same site (or nest of sites, or nest of nests, etc).

    One thing to think of, if you haven't already, is ease of maintenance. While the snippets of code within a framework might differ, it will still follow the same general path. That really helps when you find yourself revisiting a project after a year (or several) of doing other things. (Not to mention the relief of anyone else having to work with the code - if nothing else, think of the interns)

    That said, if none of the popular - and/or not-so-popular - frameworks work for you, there's the beauty of Perl. Roll your own - using the modules that others have worked hard to make darn good. CGI + HTML::Mason have powered a lot of great sites in the past, and I'm sure they'll do so in the future, as well.
Re: Perl, Web Apps, HTML::Template, HTML::Mason and the future
by lihao (Monk) on Jun 13, 2008 at 20:02 UTC

    If you are looking for simplicity and flexibility, HTML::Mason could be a very very good choice. It works well with both mod_perl and FastCGI.

    Highly recommend jQuery as the Javascript frontend library which is Perlish and really as flexible as our Perl code. :-)

    Good luck

    lihao

Re: Perl, Web Apps, HTML::Template, HTML::Mason and the future
by jdrago_999 (Hermit) on Jun 13, 2008 at 17:16 UTC
Re: Perl, Web Apps, HTML::Template, HTML::Mason and the future
by hesco (Deacon) on Jun 15, 2008 at 08:46 UTC
    I've been hacking on perl code for about seven years now and only a week or two ago finally broke down and studied the perldoc for HTML::Template. Played with it for a few hours one day and now feel comfortable with it as a part of my toolkit.

    I tend to handle nearly everything else I do with the workhorses: CGI and DBI. I snatched two subroutines from Rose::DB::Object for a project two years ago (so I could handle postgresql's store an array in a single field feature), but have otherwise been happy with the old standbys. I'm fascinated by what is said above about Template::Toolkit and keep putting off reading its tutorial (which lost a recent competitive bid to the much shorter one for HTML::Template). Five years ago I wrote a 1,000 line script, significant subroutines of which hand rolled LaTeX markup for producing press releases. I keep wanting to refactor that as a module and guess TT will need to be a part of that.

    What I haven't heard mentioned here yet is anything about managing configurations. My first major application used a hand rolled mess (which I'm still occasionally pulled back into maintaining). When I moved from spending less time organizing and more time coding, I found and fell in love with Config::Simple and have used it for everything since, and only a few weeks ago extended it with Config::Simple::Inherit for my current project. My hand rolled mess handles heredocs for feeding configurable copy into a webpage. But I'd love a more elegant solution and will likely refactor the heredoc handling code from that (not that many lines, really) as another extension as Config::Simple::Heredoc one of these days, unless someone else beats me to it, first.

    I had a frustrating experience with CGI::Application, related to discovering conflicts where it did not seem to play well with some other module I was using on that project, but otherwise was very much impressed with its design and organization. I still write my code to return, not print my html and to organize my dispatch as CGI::App taught me, figuring that one day a future refactor might actually try to integrate it into most any project I've written since. But I still have not done more than test it since then.

    Not sure that my experience would qualify me as a Ninja, or a Monk, but over the last three or four years I've felt more comfortable reliably producing working applications with the tools I have beguin to master.

    -- Hugh

    if( $lal && $lol ) { $life++; }