From petal-list at 2xlp.com Tue Aug 1 23:49:03 2006 From: petal-list at 2xlp.com (Jonathan Vanasco) Date: Tue Aug 1 23:49:24 2006 Subject: [Petal] PATCH: omit omit-tag from templates Message-ID: This is a trivial patch... I noticed while checking some petal cache documents that if omit- tag="string:1" were set - which is the recommended way of always omitting a tag from a document - it was turned into code that always returned true that seemed a bit wasteful. this patch just does a secondary check on omit-tag items , to see if it is set to string:1 if it is, the start/end tags aren't pushed onto the result stack. if its not , they are. this seems to work fine, and respect nested items -------------- next part -------------- A non-text attachment was scrubbed... Name: PETAL.diff Type: application/octet-stream Size: 1700 bytes Desc: not available Url : https://lists.webarch.co.uk/pipermail/petal/attachments/20060801/24fed1c1/PETAL.obj -------------- next part -------------- From jon at 2xlp.com Wed Aug 2 04:04:03 2006 From: jon at 2xlp.com (Jonathan Vanasco) Date: Wed Aug 2 04:14:03 2006 Subject: [Petal] PATCH: omit omit-tag from templates In-Reply-To: References: Message-ID: <4B6658B7-E7A7-4A30-A16C-63EDAB4DD116@2xlp.com> please ignore the patch. it didn't take into account multi-tal tags i'm going to try and redo it for the case where the only tal instruction is an omit tag. From yair.lenga at citigroup.com Sun Aug 13 22:00:05 2006 From: yair.lenga at citigroup.com (Lenga, Yair [CIB-FI]) Date: Sun Aug 13 23:28:24 2006 Subject: [Petal] Using '|' in TALES Message-ID: Hi, I'm trying to use Petal for a new project that I'm working on. I tried to use the '|' (alternative value), based on the TALES documentation. I realized this is not listed in the Petal doc, but I tought to give it a try. When I tried:

Someting

perl -Mpetal -e 'print new Petal(file=>"file.html", error_on_undef_value => 0)->process();" I was getting an error (undef value). When I allowed the error (error_on_undef_var = 0), I got empty tag - I was hoping to see "nothing"). I decided to try this without the spaces, same command.

Someting

What I got was infinite recursion. The program was producing: Deep recursion on subroutine "Petal::Hash::fetch" at blib/lib/Petal/Hash/Var.pm line 73. Deep recursion on subroutine "Petal::Hash::Var::process" at blib/lib/Petal/Hash.pm line 188. and then the program started hitting the disk - asking for more and more memory (the disk activity was probably from swaping). After few seconds, the whoe server could not function. Few questions: - Is the '|' suppose to work with TAL ? what is the correct syntax. - Any chance of fixing the bug ? My pages are designed by a designer - My goal with Petal is to limit his ability to impact server performance. From petal-list at 2xlp.com Mon Aug 14 01:16:58 2006 From: petal-list at 2xlp.com (Jonathan) Date: Mon Aug 14 01:17:22 2006 Subject: [Petal] Using '|' in TALES In-Reply-To: References: Message-ID: On Aug 13, 2006, at 5:00 PM, Lenga, Yair [CIB-FI] wrote: > Few questions: > - Is the '|' suppose to work with TAL ? what is the correct syntax. > - Any chance of fixing the bug ? My pages are designed by a > designer - My goal with Petal is to limit his ability to impact > server performance. Sadly, Petal isn't strictly TAL. It's almost... the guys who make it have a good portion of TAL in there, and usually fix stuff they overlook when they realize it. But there There are a few things in TAL that aren't in Petal, and vice versa. If you don't hear anything within the next few days from them regarding the bug, there are some options before you give up: a- you can try some of the other TAL implementations in Perl. Last I checked there were 2 others on CPAN. Neither did the code caching or anything like you see in Petal (one was admittedly anti-caching). But they all were much more compliant with the spec. b- alter your code slightly: "my/data | string:nothing" => "my/F_data 'nothing'" instead of data being a string in the hash you pass to petal, its a sub reference, that does the lookup manually, and handles the return value The beauty of TAL is that you can just have your designer handle the templates to the TAL spec, and then use any implementation you want. I have the same TAL templates running on Petal Template::TAL, python and phptal. // Jonathan Vanasco From ben at greenriver.org Mon Aug 14 02:14:14 2006 From: ben at greenriver.org (Benjamin Tucker) Date: Mon Aug 14 02:14:21 2006 Subject: [Petal] Using '|' in TALES In-Reply-To: References: Message-ID: <464DCD77-7CFD-4E1D-8FDE-B4D0AD2C69BA@greenriver.org> On Aug 13, 2006, at 5:00 PM, Lenga, Yair [CIB-FI] wrote: > I tried to use the '|' (alternative value), based on the TALES > documentation. I realized this is not listed in the Petal doc, but > I tought to give it a try. You might have a look at Petal::CodePerl. It adds some functionality to Petal, one of which is making '|' work as specified in TAL. http://search.cpan.org/~fdaly/Petal-CodePerl-0.06/lib/Petal/CodePerl.pm From fergal at esatclear.ie Mon Aug 14 10:57:29 2006 From: fergal at esatclear.ie (Fergal Daly) Date: Mon Aug 14 10:57:43 2006 Subject: [Petal] Using '|' in TALES In-Reply-To: <464DCD77-7CFD-4E1D-8FDE-B4D0AD2C69BA@greenriver.org> References: <464DCD77-7CFD-4E1D-8FDE-B4D0AD2C69BA@greenriver.org> Message-ID: <875029960608140257w6aa71272ldc22e750e02bbc03@mail.gmail.com> On 14/08/06, Benjamin Tucker wrote: > On Aug 13, 2006, at 5:00 PM, Lenga, Yair [CIB-FI] wrote: > > I tried to use the '|' (alternative value), based on the TALES > > documentation. I realized this is not listed in the Petal doc, but > > I tought to give it a try. > > You might have a look at Petal::CodePerl. It adds some functionality > to Petal, one of which is making '|' work as specified in TAL. > > http://search.cpan.org/~fdaly/Petal-CodePerl-0.06/lib/Petal/CodePerl.pm Does this work with Petal anymore? I haven't touched in for about 2 years now, F From fergal at esatclear.ie Mon Aug 14 10:57:29 2006 From: fergal at esatclear.ie (Fergal Daly) Date: Mon Aug 14 10:57:44 2006 Subject: [Petal] Using '|' in TALES In-Reply-To: <464DCD77-7CFD-4E1D-8FDE-B4D0AD2C69BA@greenriver.org> References: <464DCD77-7CFD-4E1D-8FDE-B4D0AD2C69BA@greenriver.org> Message-ID: <875029960608140257w6aa71272ldc22e750e02bbc03@mail.gmail.com> On 14/08/06, Benjamin Tucker wrote: > On Aug 13, 2006, at 5:00 PM, Lenga, Yair [CIB-FI] wrote: > > I tried to use the '|' (alternative value), based on the TALES > > documentation. I realized this is not listed in the Petal doc, but > > I tought to give it a try. > > You might have a look at Petal::CodePerl. It adds some functionality > to Petal, one of which is making '|' work as specified in TAL. > > http://search.cpan.org/~fdaly/Petal-CodePerl-0.06/lib/Petal/CodePerl.pm Does this work with Petal anymore? I haven't touched in for about 2 years now, F From petal-list at 2xlp.com Wed Aug 16 20:08:26 2006 From: petal-list at 2xlp.com (Jonathan Vanasco) Date: Wed Aug 16 20:08:41 2006 Subject: [Petal] Patch Idea Message-ID: This one line is useful to me... but I don't know if its appropriate in Petal. It would be neat if you thought it was. sub process { if (ref $_[0] eq 'Petal::Hash') { $hash = shift } elsif (ref $_[0] eq 'HASH') { $hash = new Petal::Hash (%{shift ()}) } + elsif (ref $_[0] eq 'ARRAY') { $hash = new Petal::Hash (@{shift ()}) } else { $hash = new Petal::Hash (@_) } basically, if you're wrapping Petal as a templating option for a framwork, you don't have to deref the input into something that Petal expects its of trivial use. the difference is in a function below. just wanted to suggest it. sub process_petal { my $self= shift; my $template_vars; if ( ref $_[0] eq 'HASH' ) { $template_vars= $_[0]; } elsif ( ref $_[0] eq 'REF' ) { $template_vars= $$template_vars; while ( ref $template_vars eq 'REF' ) { $template_vars= $$template_vars; } } else { if ( scalar @_ ) { $template_vars= \@_; } } return $self->PetalObject->process( $template_vars ); return $self->PetalObject->process( @{$template_vars} ); } From corey_s at qwest.net Wed Aug 16 21:06:00 2006 From: corey_s at qwest.net (Corey) Date: Wed Aug 16 21:06:56 2006 Subject: [Petal] Patch Idea In-Reply-To: References: Message-ID: <200608161306.01123.corey_s@qwest.net> A while back I asked whether it would be possible to get Petal to iterate ('petal:repeat') through hashes because I hated having to convert all my data structures in my classes, which are usually hashes, into arrays just so I could feed them to petal.... is this essentially what your provided code does? If so -- killer! I think it would be especially useful. On Wednesday 16 August 2006 12:08, Jonathan Vanasco wrote: > This one line is useful to me... but I don't know if its appropriate > in Petal. It would be neat if you thought it was. > > sub process { > > if (ref $_[0] eq 'Petal::Hash') { $hash = shift } > elsif (ref $_[0] eq 'HASH') { $hash = new Petal::Hash (%{shift > ()}) } > + elsif (ref $_[0] eq 'ARRAY') { $hash = new Petal::Hash (@{shift > ()}) } > else { $hash = new Petal::Hash > (@_) } > > > basically, if you're wrapping Petal as a templating option for a > framwork, you don't have to deref the input into something that Petal > expects > its of trivial use. the difference is in a function below. just > wanted to suggest it. > > > sub process_petal { > my $self= shift; > my $template_vars; > > if ( ref $_[0] eq 'HASH' ) { > $template_vars= $_[0]; > } > elsif ( ref $_[0] eq 'REF' ) { > $template_vars= $$template_vars; > while ( ref $template_vars eq 'REF' ) { > $template_vars= $$template_vars; > } > } > else { > if ( scalar @_ ) { > $template_vars= \@_; > } > } > return $self->PetalObject->process( $template_vars ); > return $self->PetalObject->process( @{$template_vars} ); > } > > From jon at 2xlp.com Wed Aug 16 21:34:17 2006 From: jon at 2xlp.com (Jonathan Vanasco) Date: Wed Aug 16 21:34:28 2006 Subject: [Petal] Patch Idea In-Reply-To: <200608161306.01123.corey_s@qwest.net> References: <200608161306.01123.corey_s@qwest.net> Message-ID: <23C913A2-B6DF-4743-862D-18873AB639CA@2xlp.com> On Aug 16, 2006, at 4:06 PM, Corey wrote: > > A while back I asked whether it would be possible to get Petal to > iterate ('petal:repeat') through hashes because I hated having > to convert all my data structures in my classes, which are usually > hashes, into arrays just so I could feed them to petal.... is this > essentially what your provided code does? > > If so -- killer! I think it would be especially useful. sorry, but no. it just has to do with the way perl treats hashes and named arguments, and how a) $template->process( a=> 'z' ); my %Personalized= ( 'a' => 'z' ); b) $template->process( %Personalized ); c) $template->process( \%Personalized ); d) $template->process( {'a' => 'z'} ); on c, process gets ( $self , $ref__Personalized ); on d, process gets ( $self , $ref__toThatAnonHash ); on a & b , process gets ( $self , 'a' , 'z' ); if you're doing some sort of template class / plugin / or wrapper where Petal is an option, adding that just lets you do my $self= shift; my $args= shift; and you can pass in args as an array ref, without coercing it into a hash or exploding the array there's no immediate performance difference, as petal processes the array ref and array the same way, with no memory or opcode gain but, it means that you save doing process( @$args ) in your class, instead of just process( $args ), which is kind of confusing you still don't need to convert hashes into arrays for petal-- just make an iterator class or something. have petal print out a function to the iterator that loops through an array and pulls out the index you want. From corey_s at qwest.net Wed Aug 16 22:10:55 2006 From: corey_s at qwest.net (Corey) Date: Wed Aug 16 22:11:46 2006 Subject: [Petal] Patch Idea In-Reply-To: <23C913A2-B6DF-4743-862D-18873AB639CA@2xlp.com> References: <200608161306.01123.corey_s@qwest.net> <23C913A2-B6DF-4743-862D-18873AB639CA@2xlp.com> Message-ID: <200608161410.55839.corey_s@qwest.net> On Wednesday 16 August 2006 13:34, Jonathan Vanasco wrote: > sorry, but no. it just has to do with the way perl treats hashes and > named arguments > but, it means that you save doing > process( @$args ) in your class, instead of just process( $args ), > which is kind of confusing > Ok - I understand, that's definitely usefull in its own right. > you still don't need to convert hashes into arrays for petal-- just > make an iterator class or something. have petal print out a function > to the iterator that loops through an array and pulls out the index > you want. > Thanks, when I get a moment to experiment, I'll try this out. Beers! Corey From jon at 2xlp.com Mon Aug 21 20:19:40 2006 From: jon at 2xlp.com (Jonathan Vanasco) Date: Tue Aug 22 00:57:33 2006 Subject: [Petal] possible memory leak issue Message-ID: while profiling growth in my modperl app, i read there's a memory leak in the way perl handles string evals. i think its fixed in 5.9x or so, but it kind of sucks in 5.8.x i've been stripping them out of my code and restructuring to get acceptable performance. Petal seems to only use it in this section of ::Hash # import all plugins once foreach my $include_dir (@INC) { my $dir = "$include_dir/Petal/Hash"; if (-e $dir and -d $dir) { opendir DD, $dir or do { warn "Cannot open directory $dir. Reason: $!"; next; }; my @modules = map { s/\.pm$//; $_ } grep /\.pm$/, grep !/^\./, readdir (DD); closedir DD; foreach my $module (@modules) { $module =~ /^(\w+)$/; $module = $1; eval "use Petal::Hash::$module"; $@ and warn "Cannot import module $module. Reason: $@"; $MODIFIERS->{lc ($module) . ':'} = "Petal::Hash::$module"; } } } is there any way we can use a non-eval way to do that? ### use Petal::Hash::String; $MODIFIERS->{'string:'}= 'string' use Petal::Hash::Test; $MODIFIERS->{'test:'}= 'test' use Petal::Hash::Var; $MODIFIERS->{'var:'}= 'var' ### i know that this is done to handle custom plugins- but if someone is doing a custom plugin, they're likely to be able to just 'use' the module, and the $MODIFIERS line looks like it could just be registered in the plugin iteself.