Re: Associate (bug?)

Brad Baxter <[email protected]> Mon, 30 Nov 2009 13:14:27 -0500
Newsgroups gmane.comp.lang.perl.modules.html-template
Message-ID <[email protected]>
On Mon, Nov 30, 2009 at 12:33 PM, Brad Baxter <[email protected]> wrote:
> In my experiments with nested templates, I tried
> some trickery using associate to avoid the extra
> param() calls. =A0However, 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  =3D qq'This is a <TMPL_VAR NAME=3D"color"> bird.\n';
     8
     9  my $assoc =3D My::Param->new( { color =3D> 'blue' } );
    10  print "Testing: ".$assoc->param( 'color' )."\n";
    11
    12  my $tmpl =3D HTML::Template->new(
    13      scalarref         =3D> \$text,
    14      associate         =3D> $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