in reply to Re: Overriding Subroutines in Package
in thread Overriding Subroutines in Package

I know Mason and like it very much. Among the mini template tools I like the plain s/\$(\w+)/$values->{$1}/eg; most. So I combine both and it lets me write

<html> <body><h1>Hello $world</h1></body> </html> <% BEGIN{ $world = "World"; } %>

Actually no new template language, only a recombination. I wonder if I can override subroutines of Mason, too. Hopefully not.

Replies are listed 'Best First'.
Re: Re: Re: Overriding Subroutines in Package
by merlyn (Sage) on Oct 07, 2001 at 19:52 UTC
    In Template, that's
    [% world = "World" -%] <html> <body><h1>Hello $world</h1></body> </html>
    And you don't have to expose Perl. Template is good. use Template!

    -- Randal L. Schwartz, Perl hacker

      For my script I am now using local to protect the system from being overridden under mod_perl. I don't really know if it's the right way, it's only the result of trial and failure.

      #!/usr/bin/perl use strict; use HSP; if ($ENV{MOD_PERL}) { my @keys = keys %HSP::; my $do = ''; foreach(@keys){ $do .= "local *HSP::$_ = *HSP::$_;"; } $do .= 'HSP::handle();'; eval $do; } else { HSP::handle(); }

      In fact, Toolkit, which you mentioned, has an option for variable interpolation, I just found that line that says it in the documentation. It's quite helpful when coding a template with an ASP capable editor. The code blocks appear in clickable boxes and the variables can be entered in the visible HTML. Only TT2 does use square brackets [% %] by default which should be changed to <% %> then.
      However just for my personal pleasure I would like to put perl within the brackets so I can have everything in one place. I have long enough put everything in the cgi-bin and started with #!/usr/bin/perl, I need a change!! Playing with this saves me from switching to php.