Bruno Postle | 9 Mar 13:42
X-Face

Re: Adding support for PAR

On Fri 25-Feb-2005 at 16:38 -0500, William McKee wrote:

> I needed to add support to Petal and MKDoc for use within PAR 
> archives.  It was a pretty simple modification to Petal/Hash.pm 
> and MKDoc/XML/Decode.pm. I've attached a diff for Petal to this 
> email.

The patch applies cleanly and passes the tests (without PAR 
installed), though it doesn't contain any changes to 
MKDoc::XML::Decode?

I have a couple of questions about the patch, basically it does 
this:

foreach my $include_dir (@INC)
{

+  if (ref $include_dir eq 'CODE')
+  {
+    next unless keys %PAR::LibCache; # skip if PAR is not loaded

  [do new PAR specific stuff]

+  }
+  else
+  {

  [do the same as before].

+  }
(Continue reading)

Simon McCaughey | 9 Mar 22:07
Favicon

Dynamic metal includes?

Hi
 
I have tried out the include stuff recently talked about on this list, but I don't think it does exactly what I want.
 
What I'm looking for is something like
 
<!-- fancy html -->
  <div tal:replace="insert: $page">__MAIN__</div>
<!-- fancy html -->
 
where page is a macro like #index_body for example
 
At the minute, what I'm doing is
<!-- fancy html -->
 <div tal:if="eq: $page string:help">
  <div metal:use-macro="#help">__MAIN__</div>
 </div>
<!-- fancy html -->
 
Thanks for any pointers
 
Simon
 
 
William McKee | 10 Mar 18:31
Favicon

Re: Dynamic metal includes?

> I have tried out the include stuff recently talked about on this list,
> but I don't think it does exactly what I want.

Hi Simon,

Look in the archives for December '04 for the thread about dynamic
includes. There is some code there which will help you to achieve what
you want.

Eventually, I'd like to make this part of Petal::Utils. If you'd like to
wrap that up into a module for inclusion in Petal::Utils, I'd be glad to
accept it. I just haven't had time to do it myself.

Good luck,
William

--

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

Bruno Postle | 10 Mar 19:00
X-Face

[BUG] translated fragments get cached in last accessed language

This is a Petal bug.  Basically if I enable the Petal cache and do 
something like this:

  my $a = new Petal (file => 'foo', base_dir => 'bar', language => 'en');
     $a = new Petal (file => 'foo', base_dir => 'bar', language => 'fr');

..Petal continues to use 'en' templates.

Either the memory or disk cache will cause the problem, which 
explains why Chris was having to both restart apache and delete the 
petal_cache_* files.

I don't really have the time to track this down just now (new baby 
etc..), so I've added some tests that demonstrate the problem to 
Petal CVS:

  http://lists.webarch.co.uk/pipermail/mkdoc-commit/2005-March/000722.html

On Wed 23-Feb-2005 at 17:35 +0000, Chris Croome wrote:
> On Wed 23-Feb-2005 at 05:19:22PM +0000, Chris Croome wrote:
> > 
> > With MKDoc 1.4 you could havea directory like /bread-crumb-trail/
> > with a en.html and a tr.html file in it and on Turkish pages the
> > tr.html template would be used and on English pages the en.html
> > fragment would be used.
> > 
> > This is broken in MKDoc 1.6.
> > 
> > What happens is that the *first* language version to be accessed
> > appears to be cached and then pages of either language just
> > display the fragment in one language.
> > 
> > If one does rm -rf /tmp/petal* then loads a page in the other
> > lanugage than this version is cached.
>
> Actually I have done some moretesting and it appears that an apache
> restart is required to get the language to change... and not
> deleting the petal tmp files...

--

-- 
Bruno

Simon McCaughey | 11 Mar 14:31
Favicon

Re: Dynamic metal includes?

Re: [Petal] Dynamic metal includes?> > I have tried out the include stuff 
recently talked about on this list,
> > but I don't think it does exactly what I want.
> Hi Simon,
> Look in the archives for December '04 for the thread about dynamic
> i ncludes. There is some code there which will help you to achieve what
> you want.
> Eventually, I'd like to make this part of Petal::Utils. If you'd like to
> wrap that up into a module for inclusion in Petal::Utils, I'd be glad to
> accept it. I just haven't had time to do it myself.

William,

Thanks, I got it to do exactly what I wanted, I didn't realise that you 
could use the Petal::Hash::Include module to include metal macros (I should 
have just tried it)

<div tal:content="structure include: ${extra_content}" />

I would like to help you out by wrapping it up, can you give me some 
pointers on what needs done?

IMHO this is the biggest thing that petal is missing. The only other thing I 
would like to see would be a method for printing debug errors at the bottom 
of the webpage

<pre tal:content="global_errors"/>

Which would turn into
<pre>
<!-- text formatted errors here -->
</pre>

Regards

Simon 

Bruno Postle | 11 Mar 15:42
X-Face

Re: [BUG] translated fragments get cached in last accessed language

On Thu 10-Mar-2005 at 18:00 +0000, Bruno Postle wrote:

> This is a Petal bug.  Basically if I enable the Petal cache and do 
> something like this:
>
>   my $a = new Petal (file => 'foo', base_dir => 'bar', language => 'en');
>      $a = new Petal (file => 'foo', base_dir => 'bar', language => 'fr');
>
> ..Petal continues to use 'en' templates.

The problem was that Petal hard-codes paths and languages for 
included templates in the cached code - Whichever language the 
template was using when it was first-run is the language that gets 
used from then-on.

The attached patch fixes this by stirring the 'language' into the 
hash key used to store and retrieve the cached code.  I would 
appreciate it if somebody could look-over it before I commit and 
release.

-- 
Bruno
Index: lib/Petal.pm
===================================================================
RCS file: /var/spool/cvs/Petal/lib/Petal.pm,v
retrieving revision 1.126
diff -r1.126 Petal.pm
609c609
<     my $code = (defined $DISK_CACHE and $DISK_CACHE) ? Petal::Cache::Disk->get
($self->_file_path_with_macro) : undef;
---
>     my $code = (defined $DISK_CACHE and $DISK_CACHE) ? Petal::Cache::Disk->get
($self->_file_path_with_macro, $self->language) : undef;
620c620
< 	Petal::Cache::Disk->set ($self->_file_path_with_macro, $code) if (defined $DISK_CACHE and $DISK_CACHE);
---
> 	Petal::Cache::Disk->set ($self->_file_path_with_macro, $code, $self->language) if (defined
$DISK_CACHE and $DISK_CACHE);
633c633
<     my $code = (defined $MEMORY_CACHE and $MEMORY_CACHE) ? Petal::Cache::Memory->get
($self->_file_path_with_macro) : undef;
---
>     my $code = (defined $MEMORY_CACHE and $MEMORY_CACHE) ? Petal::Cache::Memory->get
($self->_file_path_with_macro, $self->language) : undef;
659c659
< 	Petal::Cache::Memory->set ($self->_file_path_with_macro, $code) if (defined $MEMORY_CACHE and $MEMORY_CACHE);	
---
> 	Petal::Cache::Memory->set ($self->_file_path_with_macro, $code, $self->language) if (defined
$MEMORY_CACHE and $MEMORY_CACHE);	
Index: lib/Petal/Cache/Disk.pm
===================================================================
RCS file: /var/spool/cvs/Petal/lib/Petal/Cache/Disk.pm,v
retrieving revision 1.16
diff -r1.16 Disk.pm
43c43,44
<     my $key   = $class->compute_key ($file);
---
>     my $lang  = shift || '';
>     my $key   = $class->compute_key ($file, $lang);
57c58,59
<     my $key   = $class->compute_key ($file);
---
>     my $lang  = shift || '';
>     my $key   = $class->compute_key ($file, $lang);
81a84
>     my $lang  = shift || '';
83c86
<     my $key = $class->compute_key ($file);
---
>     my $key = $class->compute_key ($file, $lang);
102a106
>     my $lang = shift || '';
104c108
<     my $key = md5_hex ($file . ";INPUT=" . $Petal::INPUT . ";OUTPUT=" . $Petal::OUTPUT);
---
>     my $key = md5_hex ($file . ";$lang" . ";INPUT=" . $Petal::INPUT . ";OUTPUT=" . $Petal::OUTPUT);
118c122,123
<     my $key = $class->compute_key ($file);
---
>     my $lang = shift || '';
>     my $key = $class->compute_key ($file, $lang);
Index: lib/Petal/Cache/Memory.pm
===================================================================
RCS file: /var/spool/cvs/Petal/lib/Petal/Cache/Memory.pm,v
retrieving revision 1.6
diff -r1.6 Memory.pm
33d32
<     my $key = $class->compute_key ($file);
34a34,35
>     my $lang  = shift || '';
>     my $key = $class->compute_key ($file, $lang);
47d47
<     my $key = $class->compute_key ($file);
48a49,50
>     my $lang  = shift || '';
>     my $key = $class->compute_key ($file, $lang);
61c63,64
<     my $key = $class->compute_key ($file);
---
>     my $lang  = shift || '';
>     my $key = $class->compute_key ($file, $lang);
78c81,82
<     my $key = $class->compute_key ($file);
---
>     my $lang = shift || '';
>     my $key = $class->compute_key ($file, $lang);
104a109
>     my $lang = shift || '';
106c111
<     my $key = $file . ";INPUT=" . $Petal::INPUT . ";OUTPUT=" . $Petal::OUTPUT;
---
>     my $key = $file . ";$lang" . ";INPUT=" . $Petal::INPUT . ";OUTPUT=" . $Petal::OUTPUT;
Bruno Postle | 11 Mar 18:39
X-Face

Re: Petal problem

On Mon 07-Feb-2005 at 09:32 +0100, Christoph Thielecke wrote:
>
> If the "${1}" is in the text the parser fails.

Right, I've confirmed this.

Any Petal template with "${1}" in it fails because 
Petal::Hash::String thinks it looks like a variable but 
Petal::Hash::Var disagrees.

It is valid XML, but anything with '$' in it is going to be 
problematic because Petal uses it for variable substitution.

The following items all survive the Petal Parser untouched:

  <a>$</a>
  <b>$$</b>
  <c>$_</c>
  <f>$@</f>
  <g>$1</g>

..these are interpreted to nothing if they are undefined:

  <d>$foo</d>
  <e>${foo}</e>

..and these fail inelegantly:

  <h>${1}</h>
  <i>${1 bar}</i>
  <j>${1bar}</j>
  <k>${1_bar}</k>
  <l>${foo bar}</l>

The attached patch makes your particular problem go away, but I 
wonder if Petal should have a method of escaping '$' in a template.

Perhaps '$$foo' should be interpreted as the string '$foo' rather that 
a '$' followed by the variable '$foo'?

--

-- 
Bruno
Index: lib/Petal/Hash/String.pm
===================================================================
RCS file: /var/spool/cvs/Petal/lib/Petal/Hash/String.pm,v
retrieving revision 1.10
diff -r1.10 String.pm
15c15
< our $VARIABLE_RE_BRACKETS = qq |\\\$(?<!\\\\)\\{.*?(?<!\\\\)\\}|;
---
> our $VARIABLE_RE_BRACKETS = qq |\\\$(?<!\\\\)\\{[^0-9].*?(?<!\\\\)\\}|;
William McKee | 12 Mar 13:57
Favicon

Re: Adding support for PAR

On Wed, Mar 09, 2005 at 12:42:40PM +0000, Bruno Postle wrote:
> The patch applies cleanly and passes the tests (without PAR 
> installed), though it doesn't contain any changes to 
> MKDoc::XML::Decode?

I was just wanting to get feedback on the code--thanks for the reply.
I've attached the patch to MKDoc to this message which includes your
suggestion.

> Shouldn't it be something like this?:
> 
>  if (ref $include_dir eq 'CODE' and keys %PAR::LibCache)

Yes, that makes more sense. I added the 'next unless' line after
realizing that there is the possibility that the coderef is not a PAR
object. This line really doesn't ensure that it isn't but is the closest
solution I could find.

Basically, it assumes that if PAR is loaded and there are entries in the
%LibCache hash then loop through the entries in the %LibCache and add
them to the @modules list. This will work in most cases. It will
probably add duplicate entries to the @modules list when the programmer
uses coderefs in the @INC in addition to PAR (see `perldoc -f require`
for the details).

I'll admit my ignorance and say that I didn't even know it was possible
to use coderefs until I began using PAR. Is anyone on this list using
coderefs in @INC? Will it matter if @modules contains duplicates when
MKDoc/Petal build up the modules list? It doesn't look like it but I
have not tested this theory.

> You also a moved a '{', this looks like a bugfix?:

Actually I thought it was a '}' that I moved. I did that because the
original code had the foreach loop inside of a different block. I needed
to move it out a level so that PAR modules could be included in the
MODIFIERS hashref. I didn't think it was a bugfix but didn't look too
deeply into the matter before moving it.

Thanks,
William

PS - Is there a publicly accessible CVS repository for MKDoc? Is it the
same as the one for Petal?

-- 
Knowmad Services Inc.
http://www.knowmad.com
--- lib/MKDoc/XML/Decode.pm.orig	2005-03-09 09:35:42.000000000 -0500
+++ lib/MKDoc/XML/Decode.pm	2005-03-09 09:49:15.000000000 -0500
@@ -21,6 +21,24 @@
 # import all plugins once
 foreach my $include_dir (@INC)
 {
+  my @modules;
+  # Support for PAR archives
+  if (ref $include_dir eq 'CODE' && keys %PAR::LibCache)
+  {
+    while (my ($filename, $zip) = each %PAR::LibCache)
+    {
+      my @mods = $zip->membersMatching( "MKDoc/XML/Decode/" );
+      foreach my $mod (@mods)
+      {
+        my $fn = $mod->fileName;
+        my ($pm) = $fn =~ /\/(\w+)\.pm$/;
+        #warn "$fn = $pm";
+        push @modules, $pm;
+      }
+    }
+  }
+  else
+  {
     my $dir = "$include_dir/MKDoc/XML/Decode";
     if (-e $dir and -d $dir)
     {
@@ -29,30 +47,32 @@
             next;
         };
 	
-        my @modules = map { s/\.pm$//; $_ }
+        @modules = map { s/\.pm$//; $_ }
                       grep /\.pm$/,
                       grep !/^\./,
                       readdir (DD);

         closedir DD;
-	
-        foreach my $module (@modules)
-        {
-	    $module =~ /^(\w+)$/;
-	    $module = $1;
-	    eval "use MKDoc::XML::Decode::$module";
-            $@ and warn "Cannot import module $module. Reason: $@";
-	    
-	    my $name = "MKDoc::XML::Decode::$module"->can ('module_name') ?
-	               "MKDoc::XML::Decode::$module"->module_name() :
-		       lc ($module);
-	    
-	    $Modules{$name} = "MKDoc::XML::Decode::$module";
-        }
+      }
     }
+
+  foreach my $module (@modules)
+  {
+    $module =~ /^(\w+)$/;
+    $module = $1;
+    eval "use MKDoc::XML::Decode::$module";
+          $@ and warn "Cannot import module $module. Reason: $@";
+    
+    my $name = "MKDoc::XML::Decode::$module"->can ('module_name') ?
+               "MKDoc::XML::Decode::$module"->module_name() :
+         lc ($module);
+    
+    $Modules{$name} = "MKDoc::XML::Decode::$module";
+  }
 }

 
+
 sub new
 {
     my $class = shift;
Chris Croome | 12 Mar 14:11
Picon
Favicon

Re: Adding support for PAR

Hi

On Sat 12-Mar-2005 at 07:57:04AM -0500, William McKee wrote:
> 
> PS - Is there a publicly accessible CVS repository for MKDoc? Is
> it the same as the one for Petal?

Yes, details here:

  http://www.mkdoc.org/docs/howto/anon-cvs/

Chris

--

-- 
Chris Croome                               <chris@...>
web design                             http://www.webarchitects.co.uk/ 
web content management                               http://mkdoc.com/   

William McKee | 14 Mar 15:01
Favicon

Re: Dynamic metal includes?

On Fri, Mar 11, 2005 at 01:31:12PM -0000, Simon McCaughey wrote:
> Thanks, I got it to do exactly what I wanted, I didn't realise that you 
> could use the Petal::Hash::Include module to include metal macros (I should 
> have just tried it)

Glad to hear it worked for you.

> <div tal:content="structure include: ${extra_content}" />
> 
> I would like to help you out by wrapping it up, can you give me some 
> pointers on what needs done?

Check out the project from the SF cvs[1] and see the README file for the
section called Contributing (near the end of the file). Let me know if
you have any questions.

> IMHO this is the biggest thing that petal is missing. The only other thing 
> I would like to see would be a method for printing debug errors at the 
> bottom of the webpage
> 
> <pre tal:content="global_errors"/>

We could probably hack that into a modifier that accepts no arguments
(if Petal doesn't balk), but I'm not sure where the info would be coming
from to populate the pre tag. I use something similar in my applications
but set the errror key explicitly when my method fails. Please try to
explain in more detail.

Thanks,
William

[1] http://sourceforge.net/cvs/?group_id=97104

--

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


Gmane