xml-axkit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r414976 - in /xml/axkit/trunk/lib: Apache/AxKit/Language/XSP.pm AxKit.pm
Date Sat, 17 Jun 2006 01:07:28 GMT
Author: matts
Date: Fri Jun 16 18:07:28 2006
New Revision: 414976

URL: http://svn.apache.org/viewvc?rev=414976&view=rev
Log:
Make XSP Cacheable (finally!)

Modified:
    xml/axkit/trunk/lib/Apache/AxKit/Language/XSP.pm
    xml/axkit/trunk/lib/AxKit.pm

Modified: xml/axkit/trunk/lib/Apache/AxKit/Language/XSP.pm
URL: http://svn.apache.org/viewvc/xml/axkit/trunk/lib/Apache/AxKit/Language/XSP.pm?rev=414976&r1=414975&r2=414976&view=diff
==============================================================================
--- xml/axkit/trunk/lib/Apache/AxKit/Language/XSP.pm (original)
+++ xml/axkit/trunk/lib/Apache/AxKit/Language/XSP.pm Fri Jun 16 18:07:28 2006
@@ -61,10 +61,51 @@
     my $class = shift;
     my ($r, $xml, undef, $last_in_chain) = @_;
 
-    _register_me_and_others();
-
 #    warn "XSP Parse: $xmlfile\n";
 
+    my $package = $class->compile($r, $xml);
+    
+    # make sure we use inheritance to get this
+    my $cv = $package->can('handler');
+
+    my $cgi = Apache::Request->instance($r);
+
+    # $r->no_cache();
+
+    my $xsp_cache = Apache::AxKit::Cache->new($r, $package, $package->cache_params($r,
$cgi));
+
+    if (!$package->has_changed($xsp_cache->mtime(), $r) &&
+                !$xml->has_changed($xsp_cache->mtime())) {
+        AxKit::Debug(3, "XSP results cached");
+        $r->print($xsp_cache->read);
+        return;
+    }
+
+    my $dom = XML::LibXML::Document->createDocument("1.0", "UTF-8");
+    my $rc = eval { $package->$cv($r, $cgi, $dom); };
+    if ($@) {
+        die $@ if (ref($@));
+        # if ($to_eval) {
+#             my $line = 1;
+#             $to_eval =~ s/\n/"\n".++$line." "/eg;
+#             warn("Script:\n1 $to_eval\n");
+#         }
+        throw Apache::AxKit::Exception::Error(
+            -text => "Execution failed: $@"
+        );
+    }
+    $r->pnotes('dom_tree', $dom);
+    $r->print($dom->toString) if $last_in_chain;
+
+    $xsp_cache->write( $dom->toString );
+    return $rc;
+}
+
+sub compile {
+    my ($class, $r, $xml) = @_;
+    
+    _register_me_and_others();
+
     my $key = $xml->key();
 
     my $package = get_package_name($key);
@@ -199,42 +240,8 @@
         }
         AxKit::Debug(5, 'XSP Compilation finished');
     }
-
-    no strict 'refs';
-    # make sure we use inheritance to get this
-    my $cv = $package->can('handler');
-
-    my $cgi = Apache::Request->instance($r);
-
-    $r->no_cache(1);
-
-    my $xsp_cache = Apache::AxKit::Cache->new($r, $package, $package->cache_params($r,
$cgi));
-
-    if (!$package->has_changed($xsp_cache->mtime(), $r) &&
-                !$xml->has_changed($xsp_cache->mtime())) {
-        AxKit::Debug(3, "XSP results cached");
-        $r->print($xsp_cache->read);
-        return;
-    }
-
-    my $dom = XML::LibXML::Document->createDocument("1.0", "UTF-8");
-    my $rc = eval { $package->$cv($r, $cgi, $dom); };
-    if ($@) {
-        die $@ if (ref($@));
-        if ($to_eval) {
-            my $line = 1;
-            $to_eval =~ s/\n/"\n".++$line." "/eg;
-            warn("Script:\n1 $to_eval\n");
-        }
-        throw Apache::AxKit::Exception::Error(
-            -text => "Execution failed: $@"
-        );
-    }
-    $r->pnotes('dom_tree', $dom);
-    $r->print($dom->toString) if $last_in_chain;
-
-    $xsp_cache->write( $dom->toString );
-    return $rc;
+    
+    return $package;
 }
 
 sub register {

Modified: xml/axkit/trunk/lib/AxKit.pm
URL: http://svn.apache.org/viewvc/xml/axkit/trunk/lib/AxKit.pm?rev=414976&r1=414975&r2=414976&view=diff
==============================================================================
--- xml/axkit/trunk/lib/AxKit.pm (original)
+++ xml/axkit/trunk/lib/AxKit.pm Fri Jun 16 18:07:28 2006
@@ -447,6 +447,11 @@
         $r->no_cache(1) if $cache->no_cache();
         $recreate++;
     }
+    
+    if (my $package = is_xsp($r, $provider, $styles)) {
+        AxKit::Debug(2, "Checking if XSP has changed");
+        $recreate = $package->has_changed($cache->mtime(), $r);
+    }
 
     if (!$recreate && $AxKit::Cfg->DependencyChecks()) {
         $recreate = check_dependencies($r, $provider, $cache);
@@ -504,7 +509,27 @@
     save_dependencies($r, $cache);
     
     return $return_code;
-        
+}
+
+sub is_xsp {
+    my ($r, $provider, $styles) = @_;
+    
+    foreach my $style (@$styles) {
+        my $mapto = $style->{module};
+
+        # if no module is give AxKit should use the default modules
+        # from the server config.
+        unless ( $mapto ) {
+            my $mapping = $AxKit::Cfg->StyleMap;
+            $mapto = $mapping->{$style->{type}};
+        }
+        if ($mapto =~ /::XSP$/) {
+            AxKit::load_module($mapto);
+            return $mapto->compile($r, $provider);
+        }
+    }
+    
+    return;
 }
 
 sub get_axkit_uri {



Mime
View raw message