>>On Fri, May 24, 2002 at 03:13:08PM -0500, Shannon, Bryan wrote:
>> I would like to share a Stash (Template::Stash::XS) object between two
>> distinct Template objects, but am having no luck.
>> my $stash = Template::Stash::XS->new();
>> my $template_one = Template->new( {STASH => $stash} );
>> my $template_two = Template->new( {STASH => $stash} );
>That's the right way to do it, but you're being caught out by the
>fact that the stash gets localised when you call $template_xxx->process();
>
>So, each template processor ends up with a cloned copy of the same stash.
>If you set a variable like 'foo' in one, then it won't show up in the
>other.
>However, if you have a hash defined in the original stash, you can use
>that
>to pass data between processors. The stash only performs a shallow clone
>so although you end up with two different stash hashes, they both contain
>references to the same nested hash.
>
>Here's an example:
><SNIP>
>Notice how the changes to 'foo' aren't propagated, but those to 'data.x'
>are.
>
>HTH
>A
Thanks, Andy.
I now see that snooping around in Stash.pm that there is a "global" hash
reference that appears to be set aside for just such an occasion, that would
work the way you suggest.
Reading through the documentation again seems to confirms this. (Yeah, I
read the source code THEN the documentation... Guess that's gives away my
whole backwards-programmer-thought-process!)
Sometimes the documentation is harder to read than the code, because the
code itself offers no preconcieved notions of how the code "appears" to work
to the end user... Then again, it could just be that I can't read any of
the documentation that *I* write! <grin>
I tried this first by making a hashref named "global" and that worked.
After reading the docs, I was able to take it out and it still appears to
work fine.
Thanks again!
-Bryan Shannon