Apache2-ModXml2
view release on metacpan or search on metacpan
FREETMPS;
LEAVE;
return ret;
}
/**
* Static callback to be used as an XPath callback. The
* perl subroutine is passed as the void * argument.
* @param node The root node of the tree to transform.
* This is assumed to have a document fragment
* as its parent.
* @param transform The coderef to call.
* @return APR_SUCCESS (== 0) on success.
*/
static int call_transform(xmlNode *node, void *transform) {
SV *svTransform = transform;
assert(SvROK(svTransform));
assert(SvTYPE(SvRV(svTransform)) == SVt_PVCV);
/* We assume that the parent is the
owner document fragment */
SV *svNode = sv_2mortal(newSViv(PTR2IV(node)));
int ret;
dSP;
ENTER;
SAVETMPS;
/* arguments */
PUSHMARK(SP);
examples/TestXML2.pm view on Meta::CPAN
{
my ($r) = @_;
return sub {
my($tree) = @_;
$r->log->debug("Tree: ".$tree->toString());
#return APR::Const::SUCCESS();
my $doc = $tree->ownerDocument;
my $frag = $tree->parentNode;
my $xpc = XML::LibXML::XPathContext->new($frag);
$r->log->debug("XPathContext created.");
my @tags = $xpc->findnodes(q|.//*[@tag='param']|);
$r->log->debug(scalar(@tags)." parameter tags found.");
$tree->addChild($doc->createComment("mod_xml2"));
my @params = ();
foreach my $tag (@tags) {
push(@params, $tag->getAttribute( 'name' ));
examples/TestXML2.pm view on Meta::CPAN
$filter->ctx(1);
}
return AMX2::xpath_filter($filter, $bb);
}
sub get_osm_transform
{
my ($r) = @_;
return sub {
my($frag) = @_;
$r->log->debug("Tree: ".$frag->toString());
my $tree = $frag->firstChild;
return unless ($tree);
#return APR::Const::SUCCESS();
my $doc = $frag->ownerDocument;
$r->log->debug("XPathContext will be created.");
my $xpc = XML::LibXML::XPathContext->new($frag);
$r->log->debug("XPathContext created.");
# check if the node is a gas station.
my @tags = $xpc->findnodes(q|.//tag[@k='amenity'][@v='fuel']|);
$r->log->debug(scalar(@tags)." fuel tags found.");
if (!@tags) {
# We remove the whole tree.
$frag->removeChild($tree);
}
return APR::Const::SUCCESS();
};
}
1;
lib/Apache2/ModXml2.pm view on Meta::CPAN
require XSLoader;
XSLoader::load('Apache2::ModXml2', $VERSION);
sub unwrap_node
{
my ($b) = @_;
my $vn = xml2_unwrap_node($b);
# The nodes are owned by the document.
# We do not introduce an owner fragment
# as LibXML does it.
my $d = raw_owner_document($vn);
my $rtn = node_to_perl($vn, $d);
refcnt_inc($vn);
return $rtn;
}
sub wrap_node
{
my ($a, $n, $r) = @_;
t/lib/TestSXPath.pm view on Meta::CPAN
my $rtn = AMX2::xpath_filter($filter, $bb);
$filter->r->log->debug("SXPATH handler finished.");
return $rtn;
}
sub get_transform
{
my ($r) = @_;
return sub {
my($frag) = @_;
my $tree = $frag->firstChild;
$r->log->debug("Tree: ".$tree->toString());
#return APR::Const::SUCCESS();
my $doc = $tree->ownerDocument;
my $xpc = XML::LibXML::XPathContext->new($frag);
$r->log->debug("XPathContext created.");
my @tags = $xpc->findnodes(q|.//*[@tag='param']|);
$r->log->debug(scalar(@tags)." parameter tags found.");
$tree->addChild($doc->createComment("mod_xml2"));
my @params = ();
foreach my $tag (@tags) {
push(@params, $tag->getAttribute( 'name' ));
t/lib/TestSXPath.pm view on Meta::CPAN
$filter->ctx(1);
}
return AMX2::xpath_filter($filter, $bb);
}
sub get_osm_transform
{
my ($r) = @_;
return sub {
my($frag) = @_;
$r->log->debug("Ref: ".ref($frag));
$r->log->debug("Name: ".$frag->nodeName);
$r->log->debug("Tree: ".$frag->toString());
my $tree = $frag->firstChild;
return unless ($tree);
#return APR::Const::SUCCESS();
my $doc = $frag->ownerDocument;
$r->log->debug("XPathContext will be created.");
my $xpc = XML::LibXML::XPathContext->new($frag);
$r->log->debug("XPathContext created.");
# check if the node is a gas station.
my @tags = $xpc->findnodes(q|.//tag[@k='amenity'][@v='fuel']|);
$r->log->debug(scalar(@tags)." fuel tags found.");
if (!@tags) {
# We remove the whole tree.
$frag->removeChild($tree);
}
return APR::Const::SUCCESS();
};
}
#
# Helper for debugging
#
( run in 1.733 second using v1.01-cache-2.11-cpan-364913b4093 )