[Petal] Repeat object and Safe compartment

William McKee william at knowmad.com
Tue Aug 12 13:00:55 BST 2003


On Tue, Aug 12, 2003 at 03:25:55PM +0100, Fergal Daly wrote:
> I think to use them all you need to do this somewhere before entering safe 
> mode
> 
> *Petal::CPT::Petal::Hash_Repeat::CUR = \$Petal::Hash_Repeat::CUR;

Thanks for the pointer Fergal. I tried this solution and found that I
was getting a SCALAR reference back when trying to access the index and
other functions. However, if I simply set the glob to
$Petal::Hash_Repeat::CUR, then I'd get 'use of unitialized value'
errors when trying to access the index and other functions.

I guess we could check to see if $CUR is a reference and dereference it
but it sounds like you want to move us away from the use of globals
anyhow.


> Now that you know how to solve it, please don't! I was reluctant to give this 
> answer because I still think that using global variables for the repeat 
> object is very wrong. It means that there is only 1 repeat object, even 
> though you can have many nested repeats, so when you do

According to the Petal docs (loops section)--
>> Again these variables are scoped, you can safely nest loops, ifs etc...
>> as much as you like and everything should be fine.

And looking at the template code produced by CodeGenerator.pm, the CUR
and MAX vars are scoped. However, the example you gave does not even
work for me. I can get the index when I'm in the outer repeat loop.
However, I can get neither rep1 nor repeat index when inside the inner
loop.

As for the global repeat counter, you've once again gone above my head
with the code generator issues. I hope that Jean-Michel and you can work
out a reasonable solution. For the time being, I'm going to keep with my
hack to CodeGenerator.pm and Hash.pm which allows me to run with
PerlTaintCheck On for my local testing.

William

-- 
Knowmad Services Inc.
http://www.knowmad.com


More information about the Petal mailing list