From petal-list at 2xlp.com Wed Feb 1 17:17:00 2006 From: petal-list at 2xlp.com (Jonathan Vanasco) Date: Wed Feb 1 17:17:22 2006 Subject: [Petal] Is even/odd working in the current version? Message-ID: That's pretty much self explanatory This is in the docs: =pod
This a odd row, it comes before the even row.
This a even row.
=cut i'm getting false for both even and odd i tried addressing it as even/odd on its own - still no luck i jumped into the cache to get an idea of what was going on: (note, i stripped out the non-even odd stuff) from what I see, it seems to be storing the data in a user defined named hash, and operating instructions/details in other hashes ( repeat, even, odd) but then its calling get_encoded,the normal function i couldn't find anything that either: stores even/odd into the hash itself a line in get_encoded fetch or __FETCH that checks the other hashes for special things (other than the modifiers) so i'm left wondering if its broken or if i'm just completely inept with this can anyone suggest/confirm for me ? my @array = @{$hash->get ('Audiences')}; for (my $i=0; $i < @array; $i++) { my $hash = $hash->new(); my $number = $i + 1; my $odd = $number % 2; my $even = $i % 2; my $start = ($i == 0); my $end = ($i == $#array); my $inner = ($i and $i < @array); $hash->{__count__} = $number; $hash->{__is_first__} = $start; $hash->{__is_last__} = $end; $hash->{__is_inner__} = $inner; $hash->{__even__} = $even; $hash->{__odd__} = $odd; $hash->{repeat} = { index => $i, number => $number, even => $even, odd => $odd, $hash->{__is_last__} = $end; $hash->{__is_inner__} = $inner; $hash->{__even__} = $even; $hash->{__odd__} = $odd; $hash->{repeat} = { index => $i, number => $number, even => $even, odd => $odd, start => $start, end => $end, inner => $inner, }; $hash->{'audience'} = $array[$i]; $res .= ""; if ($hash->get ('false:string:1')) { $res .= "\"; }; $res .= "\ \ \ \\[\"; $res .= do { my $res = $hash->get_encoded ('audience/name'); (defined $res) ? $res : ""; }; $res .= "\<\/span\>\ \=\ \"; $res .= do { my $res = $hash->get_encoded ('audience/even'); (defined $res) ? $res : ""; }; $res .= "\<\/span\>\ \=\ \"; $res .= do { my $res = $hash->get_encoded ('audience/odd'); (defined $res) ? $res : ""; }; $res .= "\<\/span\>\ \]\<\/div\>\ From bruno at mkdoc.com Thu Feb 2 23:22:29 2006 From: bruno at mkdoc.com (Bruno Postle) Date: Thu Feb 2 23:22:42 2006 Subject: [Petal] Is even/odd working in the current version? In-Reply-To: References: Message-ID: <20060202232229.GA2092@mkdoc.com> On Wed 01-Feb-2006 at 12:17 -0500, Jonathan Vanasco wrote: > >This is in the docs: > >
tal:omit-tag="" > tal:repeat="audience self/audiences" > > >
class="odd" > tal:condition="true: audience/odd" > > > > > class="even" > tal:condition="true: audience/even" > > > > > >
> This a odd row, it comes before the even row. >
> This a even row. >
Documentation bug, it should say: tal:condition="true: repeat/odd" tal:condition="true: repeat/even" 'repeat' is a local temporary object that only exists within a petal:repeat loop. It has a bunch of methods useful for selecting different positions in the loop: index # the numeric position number # alias for index even # is the position even odd # is the position odd start # is it the first item end # is it the last item inner # not start or end Thanks for the bug report, pod is fixed in CVS, added a test too. -- Bruno From jon at 2xlp.com Fri Feb 3 20:59:49 2006 From: jon at 2xlp.com (Jonathan Vanasco) Date: Fri Feb 3 21:00:32 2006 Subject: [Petal] Documentation Suggestion Message-ID: <967C1A48-5DE2-4390-9CFD-10BFD17C4098@2xlp.com> RE: Petal/Cookbook Generating even/odd rows (submitted by Warren Smith) First- The decode modifier is GREAT. Unfortunately though, I can't use it as I use Petal to share templates between different languages. For those that need to do the same , there is a way to assign attributes based on repeat characteristics in pure TAL ===
This will use either the rowEven or rowOdd class. All of the 'tag' elements are omitted on render. This uses a nested define tag in a condition tag, because define precedes condition in order of operations.
=== The above is ugly and inefficient. , but if decode: is not an option, it saves time spend making&updating duplicate conditional rows (one for even, one for odd) , which can be a hassle to maintain when designing things. From petal-list at 2xlp.com Sat Feb 4 23:19:15 2006 From: petal-list at 2xlp.com (Jonathan Vanasco) Date: Sat Feb 4 23:19:49 2006 Subject: [Petal] Pre-Caching? Message-ID: <294AAC48-3EBC-4D3F-B594-0C529BA3DDE2@2xlp.com> First off - I'm running my Petal stuff in mod-perl I'd like to pre-cache all of my Petal templates (they're in their own directory structure) during Apache startup in my startup.pl file, so they get pulled into the main memory pool. Does anyone here have a recommended way of doing this? From bruno at mkdoc.com Mon Feb 6 10:49:59 2006 From: bruno at mkdoc.com (Bruno Postle) Date: Mon Feb 6 10:50:08 2006 Subject: [Petal] Documentation Suggestion In-Reply-To: <967C1A48-5DE2-4390-9CFD-10BFD17C4098@2xlp.com> References: <967C1A48-5DE2-4390-9CFD-10BFD17C4098@2xlp.com> Message-ID: <20060206104958.GE3688@mkdoc.com> On Fri 03-Feb-2006 at 15:59 -0500, Jonathan Vanasco wrote: > Petal/Cookbook > Generating even/odd rows (submitted by Warren Smith) > For those that need to do the same , there is a way to assign > attributes based on repeat characteristics in pure TAL Ok done, I also added a simple example of doing it by duplicating the code for each of the odd and even styles. -- Bruno From petal-list at 2xlp.com Fri Feb 17 02:41:41 2006 From: petal-list at 2xlp.com (Jonathan Vanasco) Date: Fri Feb 17 02:42:01 2006 Subject: [Petal] Help ? Trying to pre-cache Message-ID: I'm running petal under mod perl i'm trying to pre-cache the Petal templates before Apache forks, so i can use the Petal memory cache. my issue is this: petal has the fatal error "Cannot find value for ... (FATAL)" based on the petal intenral chart: 1. Read the source XML template 2. $INPUT (XML or HTML) throws XML events from the source file 3. $OUTPUT (XML or HTML) uses these XML events to canonicalize the template 4. Petal::CodeGenerator turns the canonical template into Perl code 5. Petal::Cache::Disk caches the Perl code on disk 6. Petal turns the perl code into a subroutine 7. Petal::Cache::Memory caches the subroutine in memory 8. Petal executes the subroutine 9. (optional) Petal internationalizes the resulting output. I need to stick something between 7&8 to return true. can anyone point me to a line in Petal where that about happens? i figure some sort of option in the constructor, when set, could bypass that. i'd be happy to try and write the patch for that - i just can't figure out where to start. i tried using the function perl -MPetal -e code template.xml but that doesn't work, as it doesn't do the caching or subroutine creating any help would be greatly appreciated == fyi, the recusion i use to get the template files is such: my @template_files ; use File::Find; find(\&wanted, ( $templateDir) ); sub wanted { my %pathname = map { $_ , 1 } split '/' , $File::Find::name; # kill the subversion files return if ( $pathname{'.svn'} ); # kill the subversion files return unless ( substr( $_ , -5 ) eq '.html' ); push @template_files , $File::Find::name; } foreach my $file ( @template_files ) { my $template = Petal->new ( file => $file, 'base_dir' => '/' ); $template->process(); } From petal-list at 2xlp.com Fri Feb 17 07:49:27 2006 From: petal-list at 2xlp.com (Jonathan) Date: Fri Feb 17 07:49:46 2006 Subject: [Petal] Help ? Trying to pre-cache - Patch Submission In-Reply-To: <272CD3E2-4627-4ACC-9566-E9BB51B53C4D@2xlp.com> References: <272CD3E2-4627-4ACC-9566-E9BB51B53C4D@2xlp.com> Message-ID: <20112B1F-56BB-4140-B773-4195B1E60769@2xlp.com> I figured a way to achieve what I wanted with Petal A patch is included below for Petal.pm that updates the Code and inline POD The patch simply does this: 1- add a "cache_only" option to templates (default 0) ( the internal var is $CACHE_ONLY ) 2- if cache_only is set, Petal returns true (1) after the eval block that attempts to interpolate data into the template ( and a line before Petal would otherwise have a fatal error if no data is passed in ) There is probably another way to do this, but this worked and only took me 1hr of blindly stabbing into code. Why would this be beneficial? If you're using Apache pre-fork, you can use a simple directory recursion to Petal objects and process the templates in startup.pl without passing in any data (Petal would otherwise give a fatal error). This lets you consolidate the petal code into the shared memory pool of the parent process. ======================================================================== == --- Petal.pm 2006-01-17 08:02:20.000000000 -0500 +++ newPetal.pm 2006-02-17 02:38:13.000000000 -0500 @@ -95,6 +95,10 @@ our $MEMORY_CACHE = 1; +# cache only mode +our $CACHE_ONLY = 0; + + # prevents infinites includes... our $MAX_INCLUDES = 30; our $CURRENT_INCLUDES = 0; @@ -137,6 +141,7 @@ my $file = shift (@ARGV); local $Petal::DISK_CACHE = 0; local $Petal::MEMORY_CACHE = 0; + local $Petal::CACHE_ONLY = 0; local $Petal::INPUT = $ENV{PETAL_INPUT} || 'XML'; local $Petal::OUTPUT = $ENV{PETAL_OUTPUT} || 'XHTML'; print ${Petal->new ($file)->_canonicalize()}; @@ -151,6 +156,7 @@ my $file = shift (@ARGV); local $Petal::DISK_CACHE = 0; local $Petal::MEMORY_CACHE = 0; + local $Petal::CACHE_ONLY = 0; print Petal->new ($file)->_code_disk_cached; } @@ -163,6 +169,7 @@ my $file = shift (@ARGV); local $Petal::DISK_CACHE = 0; local $Petal::MEMORY_CACHE = 0; + local $Petal::CACHE_ONLY = 0; print Petal->new ($file)->_code_with_line_numbers; } @@ -241,6 +248,7 @@ sub error_on_undef_var { exists $_[0]->{error_on_undef_var} ? $_[0]-> {error_on_undef_var} : $ERROR_ON_UNDEF_VAR } sub disk_cache { exists $_[0]->{disk_cache} ? $_[0]-> {disk_cache} : $DISK_CACHE } sub memory_cache { exists $_[0]->{memory_cache} ? $_[0]-> {memory_cache} : $MEMORY_CACHE } +sub cache_only { exists $_[0]->{cache_only} ? $_[0]-> {cache_only} : $CACHE_ONLY } sub max_includes { exists $_[0]->{max_includes} ? $_[0]-> {max_includes} : $MAX_INCLUDES } @@ -341,6 +349,7 @@ local $ERROR_ON_UNDEF_VAR = defined $self-> {error_on_undef_var} ? $self->{error_on_undef_var} : $ERROR_ON_UNDEF_VAR; local $DISK_CACHE = defined $self-> {disk_cache} ? $self->{disk_cache} : $DISK_CACHE; local $MEMORY_CACHE = defined $self-> {memory_cache} ? $self->{memory_cache} : $MEMORY_CACHE; + local $CACHE_ONLY = defined $self-> {cache_only} ? $self->{cache_only} : $CACHE_ONLY; local $MAX_INCLUDES = defined $self-> {max_includes} ? $self->{max_includes} : $MAX_INCLUDES; local $INPUT = defined $self-> {input} ? $self->{input} : $INPUT; local $OUTPUT = defined $self-> {output} ? $self->{output} : $OUTPUT; @@ -369,6 +378,8 @@ die "\$hash is undefined\n\n" unless $hash; $res = $coderef->($hash); }; + + if ( $CACHE_ONLY == 1 ){ return 1; } if (defined $@ and $@) { $res = $self->_handle_error ($@) } elsif (defined $TranslationService && $CURRENT_INCLUDES == 1) { $res = Petal::I18N->process ($res) } @@ -960,6 +971,13 @@ If set to C, Petal will not use the C module. +=head2 cache_only => I | I (default: I) + +If set to C, Petal will return true after having compiled a template into +perl code and a subroutine , and optionally using disk_cache or memory_cache if +either is set. + + =head2 max_includes => I (default: 30) The maximum number of recursive includes before Petal stops processing. This @@ -1696,6 +1714,11 @@ Otherwise, subsequent calls will resume at step 6, until the source template changes. +If you are using the mod_perl prefork MPM, you can precompile Petal templates +into Apache's shared memory at startup by using the cache_only option. This +will allow you to run through steps 1-7 without passing any data to Petal. + + =head1 DECRYPTING WARNINGS AND ERRORS From bruno at mkdoc.com Fri Feb 24 13:21:48 2006 From: bruno at mkdoc.com (Bruno Postle) Date: Fri Feb 24 13:21:53 2006 Subject: [Petal] Help ? Trying to pre-cache - Patch Submission In-Reply-To: <20112B1F-56BB-4140-B773-4195B1E60769@2xlp.com> References: <272CD3E2-4627-4ACC-9566-E9BB51B53C4D@2xlp.com> <20112B1F-56BB-4140-B773-4195B1E60769@2xlp.com> Message-ID: <20060224132147.GF13850@mkdoc.com> On Fri 17-Feb-2006 at 02:49 -0500, Jonathan wrote: > The patch simply does this: > 1- add a "cache_only" option to templates (default 0) ( the > internal var is $CACHE_ONLY ) > 2- if cache_only is set, Petal returns true (1) after the > eval block that attempts to interpolate data into the > template ( and a line before Petal would otherwise have a > fatal error if no data is passed in ) This looks useful and shouldn't break anything. Can you send the patch again as an attachment? The inline version is mangled by line-wrapping and I can't get it to apply. -- Bruno