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

The company I work for is using an old, slow, proprietery server-side language, and we'd like to replace it. We're looking at several options:

Now, i'd prefer the perl solution because I can do so much more with a system I already know, but I genuinely want us to make the right decision. What we need is a central and globally accessible collection of reusable pieces of code that we can call from within a document (not from within a script)...I would like to use TT2 because of its breadth of abilities (like having a built-in DBI module).

Is any of this possible? Did it make any sense?

  • Comment on mod_perl and TT2...WITHOUT a calling script?

Replies are listed 'Best First'.
Re: mod_perl and TT2...WITHOUT a calling script?
by perrin (Chancellor) on Jul 08, 2006 at 20:31 UTC
    Apache::Template sounds like what you're asking for. However, it's not very equivalent to the other things you mentioned. Rails is an MVC system which would be like using a mod_perl handler (maybe with the help of CGI::Application or Catalyst) and using TT2 for your view.
Re: mod_perl and TT2...WITHOUT a calling script?
by Anonymous Monk on Jul 08, 2006 at 17:16 UTC
    after reading that post, i should elaborate more. This would be my index.html for instance:
    <html> <body> [% INCLUDE header.html %] [% check_login() %] Welcome to the site! [% INCLUDE footer.html %] </body> </html>
    now, the user would directly request the index.html page, and apache would (theoretically) run it through a mod_perl handler first, which would interpret the TT2 directives, *then* serve it to the user. It would also make a huge library of predefined perl functions available as TT2 directives (such as check_login(), which would check for a login cookie and, if found, authenticate the user).

    Is this a solid idea to use perl and TT2? or should we go with ASP or some other solution?

      To elaborate, you want to, for example, have a .pl file sitting in your /etc somewhere with a bunch of subroutines you have taken the time to write, which can be called from any .html file in your DOCUMENT_ROOT?

      __________
      Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
      - Terry Pratchett

Re: mod_perl and TT2...WITHOUT a calling script?
by water (Deacon) on Jul 10, 2006 at 04:15 UTC
    You should also evaluate catalyst if you want to stay with perl.
Re: mod_perl and TT2...WITHOUT a calling script?
by davorg (Chancellor) on Jul 10, 2006 at 15:29 UTC

    An alternative to Apache::Template is mod_tt - but there doesn't seem to have been much development on it recently.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: mod_perl and TT2...WITHOUT a calling script?
by ftumsh (Scribe) on Jul 10, 2006 at 13:02 UTC
    You also have the option of AxKit.
    I use it and it is _very_ good.

    www.axkit.org

Re: mod_perl and TT2...WITHOUT a calling script?
by saberworks (Curate) on Jul 10, 2006 at 16:00 UTC
Re: mod_perl and TT2...WITHOUT a calling script?
by Anonymous Monk on Jul 10, 2006 at 15:19 UTC
    Apache::Template looks great, but after looking into it, ive heard talk that it is unstable and that I'd be better off rolling my own. is this true?
Re: mod_perl and TT2...WITHOUT a calling script?
by Anonymous Monk on Jul 10, 2006 at 17:29 UTC
    looking into mod_perl, it should be quite easy to do what I need. i'm going to create a simple mod_perl handler associated with all html documents:
    PerlModule My::PerlHandler <Files *.html> SetHandler perl-script PerlHandler My::PerlHandler </Files>
    I just need to figure out how to run the actual file requested through a TT2 object in the handler module...any pointers on that? i'm also skimming the mod_perl docs as I type this.

      You could simply have something like the following in your My::PerlHandler :

      use Template; use Apache::Constants qw( :common ); my $tt; sub handler { my ( $request ) = @_; my $file = $request->filename(); $tt ||= Template->new(); my $params = {}; my $out; $tt->process($file, $params, \$out) or do { $request->log_reason( $tt->error ); return SERVER_ERROR; }; + $request->content_type('text/html'); $request->send_http_header; $request->print( $out ); + return OK; }
      But that isn't tested and you may need to flesh it out a bit more.

      /J\

        thanks gellyfish! thats what i needed to know, the $request->filename() method!