[Petal] Repeat object and Safe compartment

Fergal Daly fergal at esatclear.ie
Fri Aug 1 14:43:26 BST 2003


Something was bothering me about the way repeat work in the scheme below, I 
finally figured out what it was. When you have just 1 object and you localise 
$CUR and $MAX, this won't work properly

<ur petal:repeat="user users">
  <d petal:define="userrepeat repeat">
    <cr petal:repeat="comment user/comments">
      usernum = <u petal:replace="userrepeat/number" />
      comment = <c petal:replace="repeat/number" />
    </cr>
  </d>
</ur>

It's a silly example but the idea is that you cannot save the repeat object 
out to another variable and use it later because it's not an independent 
object. Each loop needs to create it's own repeat object, otherwise 
interference can occur,

F


On Friday 25 July 2003 15:48, Jean-Michel Hiver wrote:
> Hi List,
>
> I have managed to get the repeat object thingie working with Petal. The
> way I achieved this was by:
>
>
> 1/ Getting Petal::Hash::Var to replace any value that's a coderef by its
> return value.
>
>
> 2/ Adding the following object to the Petal hash root object:
>
>   package Petal::Hash_Repeat;
>   use strict;
>   use warnings;
>
>   our $CUR = undef;
>   our $MAX = undef;
>
>   sub number { $CUR + 1 }
>   sub index  { $CUR }
>   sub even   { not $CUR % 2 }
>   sub odd    { $CUR % 2 }
>   sub start  { not $CUR }
>   sub end    { $CUR == $MAX }
>   sub inner  { $CUR and $CUR < $MAX }
>
>
> 3/ Getting the code generator to locally set the
> $Petal::Hash_Repeat::CUR and $Petal::Hash_Repeat::MAX variables.
>
>
> Then the codegenerator sets the following coderefs for backwards
> compatibility:
>
>   $class->add_code ("\$hash->{__count__}    = sub {
> \$hash->{repeat}->number() };"); $class->add_code ("\$hash->{__is_first__}
> = sub { \$hash->{repeat}->start()  };"); $class->add_code
> ("\$hash->{__is_last__}  = sub { \$hash->{repeat}->end()    };");
> $class->add_code ("\$hash->{__is_inner__} = sub { \$hash->{repeat}->inner()
>  };"); $class->add_code ("\$hash->{__even__}     = sub {
> \$hash->{repeat}->even()   };"); $class->add_code ("\$hash->{__odd__}     
> = sub { \$hash->{repeat}->odd()    };");
>
>
> And it works! However Safe wouldn't let me access those variables...
>
> So at the moment I have this in Petal.pm's _code_memory_cached
> subroutine:
>
>   if (0) # if ($TAINT) - doesn't work with repeat object
>
>
> I have tried to play with Safe's share() and share_from() method with no
> success... So I would like to release Petal 1.01 with those changes and
> hopefully somebody will figure out a wonder-patch that will fix this
> issue.
>
> Is taint mode a big showstopper?
> Cheers,



More information about the Petal mailing list