On Aug 17, 2006, at 5:50 PM, Frank Wiles wrote:
TT handles all of that for you. It can even cache them on disk for you
  so you don't have to bother recompiling them on startup if they
  haven't changed.

Petal does that as well.

On Aug 17, 2006, at 5:54 PM, Joel Bernstein wrote:
AFAIK TT doesn't precompile templates, it caches them on first use.
Which means you'll take the hit in each forked child unless you
explicitly precompile them. But perhaps I'm wrong about that?

That is probably right. Petal behaves the same way. You usually have to call them, either as a request or some other way.

I opted for 'some other way'-- i just find and loop through all my templates on startup as dummy documents.

Here's what i do in startup.pl:

a- i patched petal to not die and still compile the template if not given the right hash info (its was put in the last version ) b- i do a recursive loop on my template dir to find template files, then make blank dummy templates

originally i did this with File::Find. Then i found out that File::Find is gigantic-- 2+ MB. ModPerl::Utils's unload couldn't get rid of enough of it for me. so i just did a dumb recursive loop. not as fancy, but its a fraction of the resources.

i included the code below, as i think its of marginal use to others.

FindMeOn::Templater is just my webapp specific template base class, that wraps Petal or whatever else engine, hold some defaults, and gives a standard interface.

===============================

my      $restart_count= Apache2::ServerUtil::restart_count();
if ( $restart_count == 2 ) {
        my      @template_files;
        sub _list_templates {
                my      ( $dir )= @_;
                my      @sub_dirs;
                opendir DIR , $dir ;
                foreach my $file ( readdir ( DIR ) ) {
                        next if substr ( $file , 0 , 1) eq '.';
                        my      $fullpath= $dir . $file;
                        if ( -f $fullpath ) {
                                push @template_files , $fullpath;
                                next;
                        }
                        if ( -d $fullpath ) {
                                &_list_templates( $fullpath . '/' );
                                next;
                        }
                }
                closedir DIR ;
        }

        print STDERR "\nPreCompiling Templates";
                # recurse all of the petal templates and pre-cache
                &_list_templates( $FindMeOn::Config::ServerLayout::TemplateDir 
);
                foreach my $file ( @template_files ) {
                        my      $template= FindMeOn::Templater->new(
                                engine=> 'Petal',
                                file=> $file,
                                base_dir=> '/',
                                cache_only=> 1,
                        );
                        $template->process();
                }
        print STDERR "\n\tPreCompiling Templates: DONE";
}

Reply via email to