# $Id$ package Apache::AxKit::LibXMLCallbacks; use strict; use XML::LibXML 1.50; use Apache::AxKit::Provider; use vars qw($provider_cb); sub input_callbacks { my $class = shift; my $icb = XML::LibXML::InputCallback->new(); $icb->cleanup_callbacks(); $icb->register_callbacks( [ \&match_uri, \&open_uri, \&read_uri, \&close_uri ] ); return $icb; } sub match_uri { my $uri = shift; AxKit::Debug(8, "LibXSLT match_uri: $uri"); return 0 if $uri =~ /^(https?|ftp|file):/; # don't handle URI's supported by libxml return 1 if !($uri =~ /^([a-zA-Z0-9]+):/); return Apache::AxKit::Provider::has_protocol($1); } sub open_uri { my $uri = shift || './'; return Apache::AxKit::Provider::get_uri($uri,AxKit::Apache->request(),$provider_cb); } sub close_uri { # do nothing } sub read_uri { return substr(${$_[0]}, 0, $_[1], ""); } 1; __END__ =head1 NAME Apache::AxKit::LibXMLCallbacks - XML::LibXML callback routines =head1 SYNOPSIS use Apache::AxKit::LibXMLCallbacks; my $icb = Apache::AxKit::LibXMLCallbacks->input_callbacks(); =head1 DESCRIPTION This module sets up some things for using XML::LibXML in AxKit. Specifically this is to do with callbacks. All callbacks look pretty much the same in AxKit, so this module makes them editable in one place. =head1 API There is just one method: C<< Apache::AxKit::LibXMLCallbacks->setup_libxml() >>. You can pass a parameter, in which case it is a callback to create a provider given a C<$r> (an Apache request object). This is so that you can create the provider in different ways and register the fact that it was created. If you don't provide a callback though a default one will be provided. =cut