Apache-AxKit-Language-LibXSLTEnhanced
view release on metacpan or search on metacpan
lib/Apache/AxKit/Language/LibXSLTEnhanced.pm view on Meta::CPAN
# This allows declaration use Apache::AxKit::Language::LibXSLTEnhanced ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = ( 'all' => [ qw(
) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw(
);
our $VERSION = '0.02';
use strict;
use vars qw/@ISA $VERSION %DEPENDS/;
use XML::LibXSLT 1.30;
use XML::LibXML;
use Apache;
use Apache::Request;
use Apache::AxKit::Language;
use Apache::AxKit::Provider;
use Apache::AxKit::LibXMLSupport;
@ISA = 'Apache::AxKit::Language';
$VERSION = 1.0; # this fixes a CPAN.pm bug. Bah!
my %style_cache;
sub reset_depends {
%DEPENDS = ();
}
sub add_depends {
$DEPENDS{shift()}++;
}
sub get_depends {
return keys %DEPENDS;
}
sub handler {
my $class = shift;
my ($r, $xml, $style, $last_in_chain) = @_;
my ($xmlstring, $xml_doc);
AxKit::Debug(7, "[LibXSLT] getting the XML");
if (my $dom = $r->pnotes('dom_tree')) {
$xml_doc = $dom;
delete $r->pnotes()->{'dom_tree'};
}
else {
$xmlstring = $r->pnotes('xml_string');
}
my $parser = XML::LibXML->new();
$parser->expand_entities(1);
local($XML::LibXML::match_cb, $XML::LibXML::open_cb,
$XML::LibXML::read_cb, $XML::LibXML::close_cb);
Apache::AxKit::LibXMLSupport->reset();
local $Apache::AxKit::LibXMLSupport::provider_cb =
sub {
my $r = shift;
my $provider = Apache::AxKit::Provider->new_content_provider($r);
add_depends($provider->key());
return $provider;
};
if (!$xml_doc && !$xmlstring) {
$xml_doc = $xml->get_dom();
}
elsif ($xmlstring) {
$xml_doc = $parser->parse_string($xmlstring, $r->uri());
}
$xml_doc->process_xinclude();
AxKit::Debug(7, "[LibXSLT] parsing stylesheet");
my $stylesheet;
my $cache = $style_cache{$style->key()};
if (ref($cache) eq 'HASH' && !$style->has_changed($cache->{mtime}) && ref($cache->{depends}) eq 'ARRAY') {
AxKit::Debug(8, "[LibXSLT] checking if stylesheet is cached");
my $changed = 0;
DEPENDS:
foreach my $depends (@{ $cache->{depends} }) {
my $p = Apache::AxKit::Provider->new_style_provider($r, key => $depends);
if ( $p->has_changed( $cache->{mtime} ) ) {
$changed = 1;
last DEPENDS;
}
}
if (!$changed) {
AxKit::Debug(7, "[LibXSLT] stylesheet cached");
$stylesheet = $style_cache{$style->key()}{style};
}
}
if (!$stylesheet || ref($stylesheet) ne 'XML::LibXSLT::Stylesheet') {
reset_depends();
my $style_uri = $style->apache_request->uri();
AxKit::Debug(7, "[LibXSLT] parsing stylesheet $style_uri");
my $style_doc = $style->get_dom();
local($XML::LibXML::match_cb, $XML::LibXML::open_cb,
$XML::LibXML::read_cb, $XML::LibXML::close_cb);
Apache::AxKit::LibXMLSupport->reset();
local $Apache::AxKit::LibXMLSupport::provider_cb =
sub {
my $r = shift;
my $provider = Apache::AxKit::Provider->new_style_provider($r);
add_depends($provider->key());
return $provider;
};
$stylesheet = XML::LibXSLT->parse_stylesheet($style_doc);
( run in 0.859 second using v1.01-cache-2.11-cpan-5b529ec07f3 )