Template Toolkit ... is there a bug in the ANYCASE setting??

Discussion in 'Perl Misc' started by valued customer, Jan 23, 2004.

  1. The code snippet below produces an error "unexpected token (LAST)".
    Changing the ANYCASE property to false (zero) removes the error and
    the code behaves as expected.

    The question is, is this a bug? According to the TT2 documentation,
    the ANYCASE property has a side effect of precluding reserved words as
    variable names, does this also preclude using the 'loop.last'
    directive? Any TT2 experts out there? Tips? Suggestions? Thanks in
    advance.

    ### INIT library
    use strict;
    use warnings;
    use Template;

    ### INIT variables
    my $tt =
    Template->new( { ANYCASE => 1,}) || die "$Template::ERROR\n";

    ### INIT Source Data
    my $data = { list => [ qw(one two three four five) ]};

    ### PROCESS TEMPLATE
    my $strOut;
    $tt->process(\*DATA, $data, \$strOut) || die $tt->error(), "\n";
    print $strOut;

    __DATA__
    [%-FOREACH item = list;
    "<BEGIN>\n" IF loop.first;%]
    [%- item %]
    [%"<END>" IF loop.last;
    END;%]
     
    valued customer, Jan 23, 2004
    #1
    1. Advertising

  2. valued customer

    Dave Cross Guest

    On Fri, 23 Jan 2004 01:46:38 -0800, valued customer wrote:

    > The code snippet below produces an error "unexpected token (LAST)".
    > Changing the ANYCASE property to false (zero) removes the error and
    > the code behaves as expected.
    >
    > The question is, is this a bug? According to the TT2 documentation,
    > the ANYCASE property has a side effect of precluding reserved words as
    > variable names, does this also preclude using the 'loop.last'
    > directive? Any TT2 experts out there? Tips? Suggestions? Thanks in
    > advance.
    >
    > ### INIT library
    > use strict;
    > use warnings;
    > use Template;
    >
    > ### INIT variables
    > my $tt =
    > Template->new( { ANYCASE => 1,}) || die "$Template::ERROR\n";
    >
    > ### INIT Source Data
    > my $data = { list => [ qw(one two three four five) ]};
    >
    > ### PROCESS TEMPLATE
    > my $strOut;
    > $tt->process(\*DATA, $data, \$strOut) || die $tt->error(), "\n";
    > print $strOut;
    >
    > __DATA__
    > [%-FOREACH item = list;
    > "<BEGIN>\n" IF loop.first;%]
    > [%- item %]
    > [%"<END>" IF loop.last;
    > END;%]


    LAST is also a template directive (for exiting loops) so it seems that the
    parser is getting slightly confused in this situation. Probably worth
    letting the TT mailing list know (as that's where the real TT experts hang
    out).

    Dave...
     
    Dave Cross, Jan 31, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    7
    Views:
    598
  2. Smith
    Replies:
    1
    Views:
    1,565
    dotNetDave
    Nov 11, 2009
  3. Tony
    Replies:
    2
    Views:
    135
  4. Kevin

    Template Toolkit Problem

    Kevin, Apr 11, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    168
  5. Mark D Smith

    Template-Toolkit-2.14 fails make on FC3

    Mark D Smith, Aug 27, 2005, in forum: Perl Misc
    Replies:
    1
    Views:
    128
    Mark D Smith
    Aug 30, 2005
Loading...

Share This Page