xml-axkit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jw...@apache.org
Subject cvs commit: xml-axkit/lib/Apache/AxKit/Language/XSP Preload.pm
Date Fri, 03 Oct 2003 18:38:38 GMT
jwalt       2003/10/03 11:38:38

  Modified:    lib/Apache/AxKit Cache.pm Provider.pm
               lib/Apache/AxKit/Language XSP.pm
  Added:       lib/Apache/AxKit/Language/XSP Preload.pm
  Log:
  - another bugfix for 5.8.0 charset issues
  - added preloading
  - bugfix for missing XInclude processing
  
  Revision  Changes    Path
  1.12      +5 -3      xml-axkit/lib/Apache/AxKit/Cache.pm
  
  Index: Cache.pm
  ===================================================================
  RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/Cache.pm,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Cache.pm	18 Jun 2003 14:11:56 -0000	1.11
  +++ Cache.pm	3 Oct 2003 18:38:38 -0000	1.12
  @@ -109,10 +109,11 @@
   sub write {
       my $self = shift;
       return if $self->{no_cache};
  +    my $encoding = $_[1] || 'raw';
       AxKit::Debug(7, "[Cache] writing cache file $self->{file}");
       my $fh = Apache->gensym();
       my $tmp_filename = $self->{file}."new$$";
  -    if (AxKit::sysopen($fh, $tmp_filename, O_WRONLY|O_CREAT, 'raw')) {
  +    if (AxKit::sysopen($fh, $tmp_filename, O_WRONLY|O_CREAT, $encoding)) {
           # flock($fh, LOCK_EX);
           # seek($fh, 0, 0);
           # truncate($fh, 0);
  @@ -142,8 +143,9 @@
   sub read {
       my $self = shift;
       return if $self->{no_cache};
  +    my $encoding = $_[0] || 'raw';
       my $fh = Apache->gensym();
  -    if (AxKit::sysopen($fh, $self->{file}, O_RDONLY, 'raw')) {
  +    if (AxKit::sysopen($fh, $self->{file}, O_RDONLY, $encoding)) {
           flock($fh, LOCK_SH);
           local $/;
           return <$fh>;
  
  
  
  1.18      +2 -1      xml-axkit/lib/Apache/AxKit/Provider.pm
  
  Index: Provider.pm
  ===================================================================
  RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/Provider.pm,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Provider.pm	17 Sep 2003 21:58:38 -0000	1.17
  +++ Provider.pm	3 Oct 2003 18:38:38 -0000	1.18
  @@ -137,6 +137,7 @@
       AxKit::Debug(8, "Provider::get_dom");
       my $parser = XML::LibXML->new();
       $parser->expand_entities(1);
  +    $parser->expand_xinclude(1);
       local($XML::LibXML::match_cb, $XML::LibXML::open_cb,
             $XML::LibXML::read_cb, $XML::LibXML::close_cb);
       Apache::AxKit::LibXMLSupport->reset($parser);
  
  
  
  1.51      +25 -8     xml-axkit/lib/Apache/AxKit/Language/XSP.pm
  
  Index: XSP.pm
  ===================================================================
  RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/Language/XSP.pm,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- XSP.pm	17 Sep 2003 19:49:52 -0000	1.50
  +++ XSP.pm	3 Oct 2003 18:38:38 -0000	1.51
  @@ -24,6 +24,11 @@
   
   my $cache;
   
  +sub cache_key {
  +       $cache->{$_[0]}{mtime} = $_[1] if $_[1];
  +       return 1;
  +}
  +
   # useful for debugging - not actually used by AxKit:
   # sub get_code {
   #     my $filename = shift;
  @@ -63,17 +68,28 @@
   
       my $to_eval;
   
  +    my $mtime = $xml->mtime();
       eval {
           if (my $dom_tree = $r->pnotes('dom_tree')) {
  -            AxKit::Debug(5, 'XSP: parsing dom_tree');
  -            $to_eval = $parser->parse($dom_tree);
  +            if ($r->no_cache() || !exists($cache->{$key})
  +                    || !defined &{"${package}::xml_generator"}
  +                    || $xml->has_changed($cache->{$key}{mtime})) {
  +                AxKit::Debug(5, "XSP: parsing dom_tree $mtime > ".$cache->{$key}{mtime});
  +                $to_eval = $parser->parse($dom_tree);
  +                $cache->{$key}{mtime} = $mtime;
  +            }
  +            else {
  +                AxKit::Debug(5, 'XSP: not reparsing dom_tree (cached)');
  +            }
               delete $r->pnotes()->{'dom_tree'};
           }
           elsif (my $xmlstr = $r->pnotes('xml_string')) {
  -            if ($r->no_cache()
  -                    || !defined &{"${package}::xml_generator"}) {
  +            if ($r->no_cache() || !exists($cache->{$key})
  +                    || !defined &{"${package}::xml_generator"}
  +                    || $xml->has_changed($cache->{$key}{mtime})) {
                   AxKit::Debug(5, 'XSP: parsing xml_string');
                   $to_eval = $parser->parse($xmlstr);
  +                $cache->{$key}{mtime} = $mtime;
               }
               else {
                   AxKit::Debug(5, 'XSP: not reparsing xml_string (cached)');
  @@ -82,7 +98,6 @@
           else {
               my $xcache = Apache::AxKit::Cache->new($r, $package, 'compiled XSP');
               # check mtime.
  -            my $mtime = $xml->mtime();
               no strict 'refs';
               if (exists($cache->{$key})
                       && !$xml->has_changed($cache->{$key}{mtime})
  @@ -93,7 +108,8 @@
                   AxKit::Debug(5, 'XSP: xsp script cached in memory');
               } elsif (!$xml->has_changed($xcache->mtime())) {
                   AxKit::Debug(5, 'XSP: xsp script cached on disk');
  -                $to_eval = $xcache->read();
  +                $to_eval = $xcache->read('utf8');
  +                $cache->{$key}{mtime} = $mtime;
               } else {
                   AxKit::Debug(5, 'XSP: parsing fh');
                   $to_eval = eval {
  @@ -101,7 +117,7 @@
                   } || $parser->parse(${ $xml->get_strref() });
   
                   $cache->{$key}{mtime} = $mtime;
  -                $xcache->write($to_eval);
  +                $xcache->write($to_eval,'utf8');
               }
           }
       };
  @@ -112,6 +128,7 @@
       }
   
       if ($to_eval) {
  +       $to_eval .= 'Apache::AxKit::Language::XSP::cache_key('.makeSingleQuoted($key).','.$cache->{$key}{mtime}.");\n";
           eval {
               require Perl::Tidy;
               AxKit::Debug(5,'Running PerlTidy...');
  
  
  
  1.1                  xml-axkit/lib/Apache/AxKit/Language/XSP/Preload.pm
  
  Index: Preload.pm
  ===================================================================
  # $Id: Preload.pm,v 1.1 2003/10/03 18:38:38 jwalt Exp $
  
  use strict;
  no warnings;
  
  BEGIN {
  
  use AxKit;
  use Apache::AxKit::Language::XSP;
  
  my $r = Apache->server();
  my $dir = $r->dir_config('AxXSPPreloadDir');
  my $dirh;
  opendir $dirh, $dir;
  while (my $file = readdir $dirh) {
          if (-f "$dir/$file") {
                  my $rc = eval { do "$dir/$file" };
                  warn("Could not load $file: $@") if $@;
                  warn("Loading of $file failed") if !$rc;
          }
  }
  
  }
  1;
  __END__
  
  =head1 NAME
  
  Apache::AxKit::Language::XSP::Preload - preload compiled XSP scripts
  
  =head1 SYNOPSIS
  
  Use something similar to this in your httpd.conf:
  
    PerlModule AxKit
    PerlSetVar AxXSPPreloadDir /etc/apache/xsp-preload
    PerlModule Apache::AxKit::Language::XSP::Preload
  
  =head1 DESCRIPTION
  
  This module will preload all compiled XSP files that reside in a
  configurable directory. This is good for live sites, as the memory
  for this XSP code will be shared among child processes and XSP.pm
  doesn't need to reparse or re-eval your code at request time.
  
  You must put compiled XSP files into the given directory. Use
  AxTraceIntermediate to have them saved to disk, and copy any *.XSP
  file you want into the preload dir.
  
  B<Warning:> Do not, never, ever set AxTraceIntermediate to the same value as
  AxXSPPreloadDir. First of all, this module tries to load all files in the
  preload dir, and most files generated by AxTraceIntermediate are not
  preloadable, only those ending in .XSP. More importantly, regenerating
  preloaded files automatically opens a whole lot of security risks.
  
  B<The preloaded code is loaded while apache is still running as root.> So make
  absolutely sure you trust these files. You should only load files you generated
  yourself. On a sidenote, similar systems like HTML::Mason have this problem, too,
  so don't be afraid - but be careful.
  
  =head1 AUTHOR
  
  Jörg Walter E<lt>jwalt@cpan.orgE<gt>
  
  =head1 LICENSE
  
  This module is available under the same terms as AxKit itself.
  
  =cut
  
  
  

Mime
View raw message