On Mon, Nov 30, 2009 at 12:33 PM, Brad Baxter <b...@mail.libs.uga.edu> wrote:
> In my experiments with nested templates, I tried
> some trickery using associate to avoid the extra
> param() calls.  However, I've come across an unexpected
> result (at least, unexpected to me).

Okay, now I'm just confused.  Can someone tell me what I'm
doing wrong in the code below?  In the H::T docs, I read
this:

"associate - this option allows you to inherit the parameter
values from other objects. The only requirement for the other
object is that it have a param() method that works like
HTML::Template's param()."

In the code below, I'm using a My::Param object that has
a param() method that "works like HTML::Template's param()"
as regards a get operation (which is all I'd expect it to
need).  Does it have to be more than that?

Regards,

Brad

     1  #!/usr/local/bin/perl
     2
     3  use strict;
     4  use warnings;
     5  use HTML::Template;
     6
     7  my $text  = qq'This is a <TMPL_VAR NAME="color"> bird.\n';
     8
     9  my $assoc = My::Param->new( { color => 'blue' } );
    10  print "Testing: ".$assoc->param( 'color' )."\n";
    11
    12  my $tmpl = HTML::Template->new(
    13      scalarref         => \$text,
    14      associate         => $assoc,
    15      );
    16
    17  print $tmpl->output();
    18
    19  package My::Param;
    20  sub new   { bless $_[1], $_[0] }
    21  sub param { $_[0]->{ $_[1] }   }
    22
    23  __END__
    24  Use of uninitialized value in hash element at ./qt line 21.
    25  Testing: blue
    26  This is a  bird.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Html-template-users mailing list
Html-template-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/html-template-users

Reply via email to