[Petal] Repeat object and Safe compartment

Fergal Daly fergal at esatclear.ie
Sun Jul 27 15:29:51 BST 2003


I also have managed to get it working but in a different way, it turns out the 
problem was that I wasn't calling $hash = $hash->new() at every stage of the 
loop and so Petal wasn't tossing out the cached values. So it just required a 
very small change to my patch to put that back in for the original code 
generator.

What does this call do? Does it copy the hash or just throw away the cache?

Anyway, patch attached,

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,
> -- 
> Building a better web - http://www.mkdoc.com/
> ---------------------------------------------
> Jean-Michel Hiver
> jhiver at mkdoc.com  - +44 (0)114 255 8097
> Homepage: http://www.webmatrix.net/
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: loop3.patch
Type: text/x-diff
Size: 12742 bytes
Desc: not available
Url : http://www.email-lists.org/pipermail/petal/attachments/20030727/47f5a145/loop3.bin


More information about the Petal mailing list