Apache-AxKit-Provider-XMLDOMProvider
view release on metacpan or search on metacpan
lib/Apache/AxKit/Provider/XMLDOMProvider.pm view on Meta::CPAN
package Apache::AxKit::Provider::XMLDOMProvider;
use base qw(Apache::AxKit::Provider);
use 5.008004;
use strict;
use warnings;
use Apache;
use Apache::Log;
use Apache::AxKit::Exception;
use Apache::AxKit::Provider::File;
use XML::LibXML;
use LWP::UserAgent;
use Time::Piece;
# only used for debugging
#use Data::Dumper;
require Exporter;
our @ISA = qw(Exporter Apache::AxKit::Provider);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
# This allows declaration use Apache::AxKit::Provider::XMLDOMProvider ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = ( 'all' => [ qw(
new init process exists mtime get_fh get_strref key get_styles get_ext_ent_handler
) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw(
new init process exists mtime get_fh get_strref key get_styles get_ext_ent_handler
);
our $VERSION = '0.03';
# sub: init
# here we do some initialization stuff.
sub init {
my $self = shift;
my $r = $self->{apache};
my $mtime_element = $r->dir_config('RemoteXMLmTimeElement');
# prepare remote XML
my $url = $r->dir_config('RemoteXML');
# append query if defined
my $query = $r->args();
if ( defined $query ) {
$url .= "?" . $query;
}
# get xml with substitute request
my $ua = LWP::UserAgent->new();
$ua->timeout(10);
my $response = $ua->get($url);
# store some stuff for later use
$self->{response} = $response;
$self->{xmlfile} = $url;
$self->{id} = $url;
$self->{mtime_element} = $mtime_element;
}
# sub: get_fh
# we don't want to handle files, so we just throw an exception here.
sub get_fh {
throw Apache::AxKit::Exception::IO( -text => "Can't get filehandle for XMLDOMProvider (not yet implemented)!" );
}
# sub: get_strref
# since we refused to work with file handles, we HAVE to define this.
# returns a string containing the remote XML-DOM
( run in 1.678 second using v1.01-cache-2.11-cpan-df04353d9ac )