[Petal] Repeat object and Safe compartment

Jean-Michel Hiver jhiver at mkdoc.com
Fri Jul 25 16:48:45 BST 2003


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/


More information about the Petal mailing list