[Petal] Various things

Fergal Daly fergal at esatclear.ie
Wed Jul 9 15:45:24 BST 2003


On Wednesday 09 July 2003 13:17, Jean-Michel Hiver wrote:
> 1/ It doesn't do METAL macros.
> 
> I must confess that I do not fully understand METAL macros. They seem to
> be some kind of includes inside-out. Apparently the advantage is that it
> is more WYSIWYG-compatible that an include statement.
> 
> Anybody has a full understanding of METAL? What steps would a METAL
> implementation involve?

No clue, I also found them very strange, I think I worked through an example 
once and it made sense but it soon leaked out of my brain again.

> 2/ It has poor error reporting.
> 
> Again this is a big problem. We want to support a variety of parsers
> which process a file format which is not line-oriented, yet it would be
> very nice to get more syntax checking and better error reporting.
> 
> Any idea on how to implement this?

I was planning on doing someting like adding line and col attrributes to the 
tags in PIS, like

<?var name="bla" line="57" col="7"?>

These would be populated by the XML/HTML parsers. So 

<t petal:repeat="item list">
  <t petal:replace="var1" /><t petal:replace="var2" />
</t>

would produce

<?for name="item list" line="1" col="0"?><t>
        <?var name="var1" line="1" col="2"?><?var name="var2" line="1" 
col="29"?>
</t><?end?>

which would compile to

$VAR1 = sub {
  my %Position = (file => "/blah//templates/temp.xml");
  push(@Petal::Stack, \%Position);
  my $hash = shift;  
  my $res = "";  
  local $^W = 0;  
  $res .= "";  
  @Position{"line", "col"} = (1, 0);
  my @array = @{Petal::XML_Encode_Decode::encode(($hash)->{"list"})};  
  for (my $i=0; $i < @array; $i++) {  
    my $hash = $hash->new();
    my $count= $i + 1;
    $hash->{'item'} = $array[$i];
    $res .= "<t>\n  ";
    @Position{"line", "col"} = (1, 2);
    $res .= Petal::XML_Encode_Decode::encode(($hash)->{"var"});
    @Position{"line", "col"} = (1, 29);
    $res .= Petal::XML_Encode_Decode::encode(($hash)->{"var2"});

    $res .= "\n</t>";
  }  
  pop(@Petal::Stack);
  return $res;  
}

Every time you enter a new template file, you create an object to track where 
you are and push it onto the stack. Every time you're about to perform an 
action that might fail you update the object with information about where the 
action came from. When you leave the file, you pop the stack.

I've used a hash and an array above but real objects would probably be better.

I haven't done it due to lack of time and lack of knowledge about how the PIS 
stuff is produced.

> 5/ Caching involves writing temp files with can be a security problem.
> 
> I know you can turn the cache off, but... Wouldn't it be better to
> always do in-memory conversion and avoid potential security risks? Maybe
> turn caching on only if the programmer provides a temp directory to
> write to? How about we use a more formal cache module, such as
> Cache::Cache?

In principle, using Cache::Cache would be a good idea. I don't know how well 
that module works but seems to have lots of good stuff.

Thanks for all the hard work,

F



More information about the Petal mailing list