Hi,

(I strongly suspect this has been answered before, but I've looked and 
not found it.)

I'm curious, given that TT can use objects within templates without any 
problems, you'd think you could pass an object as the second parameter 
to process():

  my $tt = Template->new;
  my $obj = MyClass->new; # implements the method ->message()
  $tt->process(\"the message is: $message", $obj);

Ok, I know this doesn't work.  I've had a brief look at the source of 
Template::Stash and I can see why.

I know I could just pass the object as a value within a hashref.  But 
this is frustrating, since it forces me to add a redundant prefix to all 
the variable names used in the template. Or I could unbless the object, 
but that's assuming it is a hash-based object, and the values I want are 
stored in the hash.  And there are other hacks I could try, but they get 
increasingly clumsy and long winded.

But it seems such an obvious thing to want, I wonder is there a clever 
way around this?  And before I spend any time trying, is there some 
reason why Template::Stash couldn't just delegate appropriate uses of 
->get and ->set to an object, or die on inappropriate ones?


Thanks,

N

_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to